bbaceab83a654e804e7b2bd1dcc4f4f232c605ea
[linux-3.10.git] / include / linux / lsm_audit.h
1 /*
2  * Common LSM logging functions
3  * Heavily borrowed from selinux/avc.h
4  *
5  * Author : Etienne BASSET  <etienne.basset@ensta.org>
6  *
7  * All credits to : Stephen Smalley, <sds@epoch.ncsc.mil>
8  * All BUGS to : Etienne BASSET  <etienne.basset@ensta.org>
9  */
10 #ifndef _LSM_COMMON_LOGGING_
11 #define _LSM_COMMON_LOGGING_
12
13 #include <linux/stddef.h>
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/kdev_t.h>
17 #include <linux/spinlock.h>
18 #include <linux/init.h>
19 #include <linux/audit.h>
20 #include <linux/in6.h>
21 #include <linux/path.h>
22 #include <linux/key.h>
23 #include <linux/skbuff.h>
24 #include <asm/system.h>
25
26
27 /* Auxiliary data to use in generating the audit record. */
28 struct common_audit_data {
29         char type;
30 #define LSM_AUDIT_DATA_PATH     1
31 #define LSM_AUDIT_DATA_NET      2
32 #define LSM_AUDIT_DATA_CAP      3
33 #define LSM_AUDIT_DATA_IPC      4
34 #define LSM_AUDIT_DATA_TASK     5
35 #define LSM_AUDIT_DATA_KEY      6
36 #define LSM_AUDIT_DATA_NONE     7
37 #define LSM_AUDIT_DATA_KMOD     8
38 #define LSM_AUDIT_DATA_INODE    9
39         struct task_struct *tsk;
40         union   {
41                 struct path path;
42                 struct inode *inode;
43                 struct {
44                         int netif;
45                         struct sock *sk;
46                         u16 family;
47                         __be16 dport;
48                         __be16 sport;
49                         union {
50                                 struct {
51                                         __be32 daddr;
52                                         __be32 saddr;
53                                 } v4;
54                                 struct {
55                                         struct in6_addr daddr;
56                                         struct in6_addr saddr;
57                                 } v6;
58                         } fam;
59                 } net;
60                 int cap;
61                 int ipc_id;
62                 struct task_struct *tsk;
63 #ifdef CONFIG_KEYS
64                 struct {
65                         key_serial_t key;
66                         char *key_desc;
67                 } key_struct;
68 #endif
69                 char *kmod_name;
70         } u;
71         /* this union contains LSM specific data */
72         union {
73 #ifdef CONFIG_SECURITY_SMACK
74                 /* SMACK data */
75                 struct smack_audit_data {
76                         const char *function;
77                         char *subject;
78                         char *object;
79                         char *request;
80                         int result;
81                 } smack_audit_data;
82 #endif
83 #ifdef CONFIG_SECURITY_SELINUX
84                 /* SELinux data */
85                 struct {
86                         u32 ssid;
87                         u32 tsid;
88                         u16 tclass;
89                         u32 requested;
90                         u32 audited;
91                         u32 denied;
92                         /*
93                          * auditdeny is a bit tricky and unintuitive.  See the
94                          * comments in avc.c for it's meaning and usage.
95                          */
96                         u32 auditdeny;
97                         struct av_decision *avd;
98                         int result;
99                 } selinux_audit_data;
100 #endif
101 #ifdef CONFIG_SECURITY_APPARMOR
102                 struct {
103                         int error;
104                         int op;
105                         int type;
106                         void *profile;
107                         const char *name;
108                         const char *info;
109                         union {
110                                 void *target;
111                                 struct {
112                                         long pos;
113                                         void *target;
114                                 } iface;
115                                 struct {
116                                         int rlim;
117                                         unsigned long max;
118                                 } rlim;
119                                 struct {
120                                         const char *target;
121                                         u32 request;
122                                         u32 denied;
123                                         uid_t ouid;
124                                 } fs;
125                         };
126                 } apparmor_audit_data;
127 #endif
128         };
129         /* these callback will be implemented by a specific LSM */
130         void (*lsm_pre_audit)(struct audit_buffer *, void *);
131         void (*lsm_post_audit)(struct audit_buffer *, void *);
132 };
133
134 #define v4info fam.v4
135 #define v6info fam.v6
136
137 int ipv4_skb_to_auditdata(struct sk_buff *skb,
138                 struct common_audit_data *ad, u8 *proto);
139
140 int ipv6_skb_to_auditdata(struct sk_buff *skb,
141                 struct common_audit_data *ad, u8 *proto);
142
143 /* Initialize an LSM audit data structure. */
144 #define COMMON_AUDIT_DATA_INIT(_d, _t) \
145         { memset((_d), 0, sizeof(struct common_audit_data)); \
146          (_d)->type = LSM_AUDIT_DATA_##_t; }
147
148 void common_lsm_audit(struct common_audit_data *a);
149
150 #endif