blob: 99d629fd994457589410ee08344f83b2c69cfdda [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Etienne Basset6e837fb2009-04-08 20:39:40 +02002/*
3 * Common LSM logging functions
4 * Heavily borrowed from selinux/avc.h
5 *
6 * Author : Etienne BASSET <etienne.basset@ensta.org>
7 *
Stephen Smalley5d728012017-08-17 13:32:37 -04008 * All credits to : Stephen Smalley, <sds@tycho.nsa.gov>
Etienne Basset6e837fb2009-04-08 20:39:40 +02009 * All BUGS to : Etienne BASSET <etienne.basset@ensta.org>
10 */
11#ifndef _LSM_COMMON_LOGGING_
12#define _LSM_COMMON_LOGGING_
13
14#include <linux/stddef.h>
15#include <linux/errno.h>
16#include <linux/kernel.h>
17#include <linux/kdev_t.h>
18#include <linux/spinlock.h>
19#include <linux/init.h>
20#include <linux/audit.h>
21#include <linux/in6.h>
22#include <linux/path.h>
23#include <linux/key.h>
24#include <linux/skbuff.h>
Daniel Jurgensab861df2017-05-19 15:48:58 +030025#include <rdma/ib_verbs.h>
Etienne Basset6e837fb2009-04-08 20:39:40 +020026
Eric Paris48c62af2012-04-02 13:15:44 -040027struct lsm_network_audit {
28 int netif;
29 struct sock *sk;
30 u16 family;
31 __be16 dport;
32 __be16 sport;
33 union {
34 struct {
35 __be32 daddr;
36 __be32 saddr;
37 } v4;
38 struct {
39 struct in6_addr daddr;
40 struct in6_addr saddr;
41 } v6;
42 } fam;
43};
Etienne Basset6e837fb2009-04-08 20:39:40 +020044
Jeff Vander Stoep671a2782015-07-10 17:19:55 -040045struct lsm_ioctlop_audit {
46 struct path path;
47 u16 cmd;
48};
49
Daniel Jurgenscfc4d882017-05-19 15:48:57 +030050struct lsm_ibpkey_audit {
51 u64 subnet_prefix;
52 u16 pkey;
53};
54
Daniel Jurgensab861df2017-05-19 15:48:58 +030055struct lsm_ibendport_audit {
56 char dev_name[IB_DEVICE_NAME_MAX];
57 u8 port;
58};
59
Etienne Basset6e837fb2009-04-08 20:39:40 +020060/* Auxiliary data to use in generating the audit record. */
61struct common_audit_data {
Eric Parisdd8dbf22009-11-03 16:35:32 +110062 char type;
Eric Parisf48b7392011-04-25 12:54:27 -040063#define LSM_AUDIT_DATA_PATH 1
Eric Parisdd8dbf22009-11-03 16:35:32 +110064#define LSM_AUDIT_DATA_NET 2
65#define LSM_AUDIT_DATA_CAP 3
66#define LSM_AUDIT_DATA_IPC 4
67#define LSM_AUDIT_DATA_TASK 5
68#define LSM_AUDIT_DATA_KEY 6
Eric Pariscb84aa92010-04-27 17:20:38 -040069#define LSM_AUDIT_DATA_NONE 7
Eric Parisdd8dbf22009-11-03 16:35:32 +110070#define LSM_AUDIT_DATA_KMOD 8
Eric Parisf48b7392011-04-25 12:54:27 -040071#define LSM_AUDIT_DATA_INODE 9
Eric Parisa2694342011-04-25 13:10:27 -040072#define LSM_AUDIT_DATA_DENTRY 10
Jeff Vander Stoep671a2782015-07-10 17:19:55 -040073#define LSM_AUDIT_DATA_IOCTL_OP 11
Vivek Goyal43af5de2016-09-09 11:37:49 -040074#define LSM_AUDIT_DATA_FILE 12
Daniel Jurgenscfc4d882017-05-19 15:48:57 +030075#define LSM_AUDIT_DATA_IBPKEY 13
Daniel Jurgensab861df2017-05-19 15:48:58 +030076#define LSM_AUDIT_DATA_IBENDPORT 14
Stephen Smalley59438b462019-11-27 12:04:36 -050077#define LSM_AUDIT_DATA_LOCKDOWN 15
Etienne Basset6e837fb2009-04-08 20:39:40 +020078 union {
Eric Parisf48b7392011-04-25 12:54:27 -040079 struct path path;
Eric Parisa2694342011-04-25 13:10:27 -040080 struct dentry *dentry;
Eric Parisf48b7392011-04-25 12:54:27 -040081 struct inode *inode;
Eric Paris48c62af2012-04-02 13:15:44 -040082 struct lsm_network_audit *net;
Etienne Basset6e837fb2009-04-08 20:39:40 +020083 int cap;
84 int ipc_id;
85 struct task_struct *tsk;
86#ifdef CONFIG_KEYS
87 struct {
88 key_serial_t key;
89 char *key_desc;
90 } key_struct;
91#endif
Eric Parisdd8dbf22009-11-03 16:35:32 +110092 char *kmod_name;
Jeff Vander Stoep671a2782015-07-10 17:19:55 -040093 struct lsm_ioctlop_audit *op;
Vivek Goyal43af5de2016-09-09 11:37:49 -040094 struct file *file;
Daniel Jurgenscfc4d882017-05-19 15:48:57 +030095 struct lsm_ibpkey_audit *ibpkey;
Daniel Jurgensab861df2017-05-19 15:48:58 +030096 struct lsm_ibendport_audit *ibendport;
Stephen Smalley59438b462019-11-27 12:04:36 -050097 int reason;
Etienne Basset6e837fb2009-04-08 20:39:40 +020098 } u;
Etienne Basset6e837fb2009-04-08 20:39:40 +020099 /* this union contains LSM specific data */
100 union {
Thomas Liu65c3f0a2009-07-09 10:00:31 -0400101#ifdef CONFIG_SECURITY_SMACK
Eric Paris3b3b0e42012-04-03 09:37:02 -0700102 struct smack_audit_data *smack_audit_data;
Thomas Liu65c3f0a2009-07-09 10:00:31 -0400103#endif
104#ifdef CONFIG_SECURITY_SELINUX
Eric Paris3b3b0e42012-04-03 09:37:02 -0700105 struct selinux_audit_data *selinux_audit_data;
Thomas Liu65c3f0a2009-07-09 10:00:31 -0400106#endif
John Johansen67012e82010-07-29 14:47:58 -0700107#ifdef CONFIG_SECURITY_APPARMOR
Eric Paris3b3b0e42012-04-03 09:37:02 -0700108 struct apparmor_audit_data *apparmor_audit_data;
John Johansen67012e82010-07-29 14:47:58 -0700109#endif
Eric Paris3b3b0e42012-04-03 09:37:02 -0700110 }; /* per LSM data pointer union */
Etienne Basset6e837fb2009-04-08 20:39:40 +0200111};
112
113#define v4info fam.v4
114#define v6info fam.v6
115
116int ipv4_skb_to_auditdata(struct sk_buff *skb,
117 struct common_audit_data *ad, u8 *proto);
118
119int ipv6_skb_to_auditdata(struct sk_buff *skb,
120 struct common_audit_data *ad, u8 *proto);
121
Linus Torvaldsb61c37f2012-04-02 15:48:12 -0700122void common_lsm_audit(struct common_audit_data *a,
123 void (*pre_audit)(struct audit_buffer *, void *),
124 void (*post_audit)(struct audit_buffer *, void *));
Etienne Basset6e837fb2009-04-08 20:39:40 +0200125
126#endif