Blame view

security/lsm_audit.c 10.8 KB
d2912cb15   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-only
6e837fb15   Etienne Basset   smack: implement ...
2
3
4
5
  /*
   * common LSM auditing functions
   *
   * Based on code written for SELinux by :
5d7280153   Stephen Smalley   lsm_audit: update...
6
   *			Stephen Smalley, <sds@tycho.nsa.gov>
6e837fb15   Etienne Basset   smack: implement ...
7
8
   * 			James Morris <jmorris@redhat.com>
   * Author : Etienne Basset, <etienne.basset@ensta.org>
6e837fb15   Etienne Basset   smack: implement ...
9
10
11
12
13
   */
  
  #include <linux/types.h>
  #include <linux/stddef.h>
  #include <linux/kernel.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
14
  #include <linux/gfp.h>
6e837fb15   Etienne Basset   smack: implement ...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  #include <linux/fs.h>
  #include <linux/init.h>
  #include <net/sock.h>
  #include <linux/un.h>
  #include <net/af_unix.h>
  #include <linux/audit.h>
  #include <linux/ipv6.h>
  #include <linux/ip.h>
  #include <net/ip.h>
  #include <net/ipv6.h>
  #include <linux/tcp.h>
  #include <linux/udp.h>
  #include <linux/dccp.h>
  #include <linux/sctp.h>
  #include <linux/lsm_audit.h>
  
  /**
   * ipv4_skb_to_auditdata : fill auditdata from skb
   * @skb : the skb
   * @ad : the audit data to fill
   * @proto : the layer 4 protocol
   *
   * return  0 on success
   */
  int ipv4_skb_to_auditdata(struct sk_buff *skb,
  		struct common_audit_data *ad, u8 *proto)
  {
  	int ret = 0;
  	struct iphdr *ih;
  
  	ih = ip_hdr(skb);
  	if (ih == NULL)
  		return -EINVAL;
48c62af68   Eric Paris   LSM: shrink the c...
48
49
  	ad->u.net->v4info.saddr = ih->saddr;
  	ad->u.net->v4info.daddr = ih->daddr;
6e837fb15   Etienne Basset   smack: implement ...
50
51
52
53
54
55
56
57
58
59
60
61
  
  	if (proto)
  		*proto = ih->protocol;
  	/* non initial fragment */
  	if (ntohs(ih->frag_off) & IP_OFFSET)
  		return 0;
  
  	switch (ih->protocol) {
  	case IPPROTO_TCP: {
  		struct tcphdr *th = tcp_hdr(skb);
  		if (th == NULL)
  			break;
48c62af68   Eric Paris   LSM: shrink the c...
62
63
  		ad->u.net->sport = th->source;
  		ad->u.net->dport = th->dest;
6e837fb15   Etienne Basset   smack: implement ...
64
65
66
67
68
69
  		break;
  	}
  	case IPPROTO_UDP: {
  		struct udphdr *uh = udp_hdr(skb);
  		if (uh == NULL)
  			break;
48c62af68   Eric Paris   LSM: shrink the c...
70
71
  		ad->u.net->sport = uh->source;
  		ad->u.net->dport = uh->dest;
6e837fb15   Etienne Basset   smack: implement ...
72
73
74
75
76
77
  		break;
  	}
  	case IPPROTO_DCCP: {
  		struct dccp_hdr *dh = dccp_hdr(skb);
  		if (dh == NULL)
  			break;
48c62af68   Eric Paris   LSM: shrink the c...
78
79
  		ad->u.net->sport = dh->dccph_sport;
  		ad->u.net->dport = dh->dccph_dport;
6e837fb15   Etienne Basset   smack: implement ...
80
81
82
83
84
85
  		break;
  	}
  	case IPPROTO_SCTP: {
  		struct sctphdr *sh = sctp_hdr(skb);
  		if (sh == NULL)
  			break;
48c62af68   Eric Paris   LSM: shrink the c...
86
87
  		ad->u.net->sport = sh->source;
  		ad->u.net->dport = sh->dest;
6e837fb15   Etienne Basset   smack: implement ...
88
89
90
91
92
93
94
  		break;
  	}
  	default:
  		ret = -EINVAL;
  	}
  	return ret;
  }
1a93a6eac   Javier Martinez Canillas   security: Use IS_...
95
  #if IS_ENABLED(CONFIG_IPV6)
6e837fb15   Etienne Basset   smack: implement ...
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  /**
   * ipv6_skb_to_auditdata : fill auditdata from skb
   * @skb : the skb
   * @ad : the audit data to fill
   * @proto : the layer 4 protocol
   *
   * return  0 on success
   */
  int ipv6_skb_to_auditdata(struct sk_buff *skb,
  		struct common_audit_data *ad, u8 *proto)
  {
  	int offset, ret = 0;
  	struct ipv6hdr *ip6;
  	u8 nexthdr;
75f2811c6   Jesse Gross   ipv6: Add fragmen...
110
  	__be16 frag_off;
6e837fb15   Etienne Basset   smack: implement ...
111
112
113
114
  
  	ip6 = ipv6_hdr(skb);
  	if (ip6 == NULL)
  		return -EINVAL;
48c62af68   Eric Paris   LSM: shrink the c...
115
116
  	ad->u.net->v6info.saddr = ip6->saddr;
  	ad->u.net->v6info.daddr = ip6->daddr;
6e837fb15   Etienne Basset   smack: implement ...
117
118
119
120
121
122
  	ret = 0;
  	/* IPv6 can have several extension header before the Transport header
  	 * skip them */
  	offset = skb_network_offset(skb);
  	offset += sizeof(*ip6);
  	nexthdr = ip6->nexthdr;
75f2811c6   Jesse Gross   ipv6: Add fragmen...
123
  	offset = ipv6_skip_exthdr(skb, offset, &nexthdr, &frag_off);
6e837fb15   Etienne Basset   smack: implement ...
124
125
126
127
128
129
130
131
132
133
134
  	if (offset < 0)
  		return 0;
  	if (proto)
  		*proto = nexthdr;
  	switch (nexthdr) {
  	case IPPROTO_TCP: {
  		struct tcphdr _tcph, *th;
  
  		th = skb_header_pointer(skb, offset, sizeof(_tcph), &_tcph);
  		if (th == NULL)
  			break;
48c62af68   Eric Paris   LSM: shrink the c...
135
136
  		ad->u.net->sport = th->source;
  		ad->u.net->dport = th->dest;
6e837fb15   Etienne Basset   smack: implement ...
137
138
139
140
141
142
143
144
  		break;
  	}
  	case IPPROTO_UDP: {
  		struct udphdr _udph, *uh;
  
  		uh = skb_header_pointer(skb, offset, sizeof(_udph), &_udph);
  		if (uh == NULL)
  			break;
48c62af68   Eric Paris   LSM: shrink the c...
145
146
  		ad->u.net->sport = uh->source;
  		ad->u.net->dport = uh->dest;
6e837fb15   Etienne Basset   smack: implement ...
147
148
149
150
151
152
153
154
  		break;
  	}
  	case IPPROTO_DCCP: {
  		struct dccp_hdr _dccph, *dh;
  
  		dh = skb_header_pointer(skb, offset, sizeof(_dccph), &_dccph);
  		if (dh == NULL)
  			break;
48c62af68   Eric Paris   LSM: shrink the c...
155
156
  		ad->u.net->sport = dh->dccph_sport;
  		ad->u.net->dport = dh->dccph_dport;
6e837fb15   Etienne Basset   smack: implement ...
157
158
159
160
161
162
163
164
  		break;
  	}
  	case IPPROTO_SCTP: {
  		struct sctphdr _sctph, *sh;
  
  		sh = skb_header_pointer(skb, offset, sizeof(_sctph), &_sctph);
  		if (sh == NULL)
  			break;
48c62af68   Eric Paris   LSM: shrink the c...
165
166
  		ad->u.net->sport = sh->source;
  		ad->u.net->dport = sh->dest;
6e837fb15   Etienne Basset   smack: implement ...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
  		break;
  	}
  	default:
  		ret = -EINVAL;
  	}
  	return ret;
  }
  #endif
  
  
  static inline void print_ipv6_addr(struct audit_buffer *ab,
  				   struct in6_addr *addr, __be16 port,
  				   char *name1, char *name2)
  {
  	if (!ipv6_addr_any(addr))
d81165919   Paul Moore   lsm: Use a compre...
182
  		audit_log_format(ab, " %s=%pI6c", name1, addr);
6e837fb15   Etienne Basset   smack: implement ...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
  	if (port)
  		audit_log_format(ab, " %s=%d", name2, ntohs(port));
  }
  
  static inline void print_ipv4_addr(struct audit_buffer *ab, __be32 addr,
  				   __be16 port, char *name1, char *name2)
  {
  	if (addr)
  		audit_log_format(ab, " %s=%pI4", name1, &addr);
  	if (port)
  		audit_log_format(ab, " %s=%d", name2, ntohs(port));
  }
  
  /**
   * dump_common_audit_data - helper to dump common audit data
   * @a : common audit data
   *
   */
  static void dump_common_audit_data(struct audit_buffer *ab,
  				   struct common_audit_data *a)
  {
5deeb5cec   Richard Guy Briggs   lsm: copy comm be...
204
  	char comm[sizeof(current->comm)];
6e837fb15   Etienne Basset   smack: implement ...
205

07f62eb66   Eric Paris   LSM: BUILD_BUG_ON...
206
207
208
209
210
211
  	/*
  	 * To keep stack sizes in check force programers to notice if they
  	 * start making this union too large!  See struct lsm_network_audit
  	 * as an example of how to deal with large data.
  	 */
  	BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2);
fa2bea2f5   Paul Moore   audit: consistent...
212
  	audit_log_format(ab, " pid=%d comm=", task_tgid_nr(current));
5deeb5cec   Richard Guy Briggs   lsm: copy comm be...
213
  	audit_log_untrustedstring(ab, memcpy(comm, current->comm, sizeof(comm)));
6e837fb15   Etienne Basset   smack: implement ...
214
215
  
  	switch (a->type) {
cb84aa9b4   Eric Paris   LSM Audit: rename...
216
  	case LSM_AUDIT_DATA_NONE:
2bf496903   Thomas Liu   SELinux: Convert ...
217
  		return;
6e837fb15   Etienne Basset   smack: implement ...
218
219
220
221
222
223
  	case LSM_AUDIT_DATA_IPC:
  		audit_log_format(ab, " key=%d ", a->u.ipc_id);
  		break;
  	case LSM_AUDIT_DATA_CAP:
  		audit_log_format(ab, " capability=%d ", a->u.cap);
  		break;
f48b73998   Eric Paris   LSM: split LSM_AU...
224
  	case LSM_AUDIT_DATA_PATH: {
f48b73998   Eric Paris   LSM: split LSM_AU...
225
  		struct inode *inode;
c158a35c8   Kees Cook   audit: no leading...
226
  		audit_log_d_path(ab, " path=", &a->u.path);
a269434d2   Eric Paris   LSM: separate LSM...
227

c6f493d63   David Howells   VFS: security/: d...
228
  		inode = d_backing_inode(a->u.path.dentry);
41fdc3054   Kees Cook   audit: treat s_id...
229
230
231
232
233
  		if (inode) {
  			audit_log_format(ab, " dev=");
  			audit_log_untrustedstring(ab, inode->i_sb->s_id);
  			audit_log_format(ab, " ino=%lu", inode->i_ino);
  		}
d7481b24b   Richard Guy Briggs   audit: issue CWD ...
234
  		audit_getcwd();
a269434d2   Eric Paris   LSM: separate LSM...
235
236
  		break;
  	}
43af5de74   Vivek Goyal   lsm,audit,selinux...
237
238
239
240
241
242
243
244
245
246
247
  	case LSM_AUDIT_DATA_FILE: {
  		struct inode *inode;
  
  		audit_log_d_path(ab, " path=", &a->u.file->f_path);
  
  		inode = file_inode(a->u.file);
  		if (inode) {
  			audit_log_format(ab, " dev=");
  			audit_log_untrustedstring(ab, inode->i_sb->s_id);
  			audit_log_format(ab, " ino=%lu", inode->i_ino);
  		}
d7481b24b   Richard Guy Briggs   audit: issue CWD ...
248
  		audit_getcwd();
43af5de74   Vivek Goyal   lsm,audit,selinux...
249
250
  		break;
  	}
671a2781f   Jeff Vander Stoep   security: add ioc...
251
252
253
254
255
256
257
258
259
260
261
  	case LSM_AUDIT_DATA_IOCTL_OP: {
  		struct inode *inode;
  
  		audit_log_d_path(ab, " path=", &a->u.op->path);
  
  		inode = a->u.op->path.dentry->d_inode;
  		if (inode) {
  			audit_log_format(ab, " dev=");
  			audit_log_untrustedstring(ab, inode->i_sb->s_id);
  			audit_log_format(ab, " ino=%lu", inode->i_ino);
  		}
8b31f456c   William Roberts   selinux: print le...
262
  		audit_log_format(ab, " ioctlcmd=0x%hx", a->u.op->cmd);
d7481b24b   Richard Guy Briggs   audit: issue CWD ...
263
  		audit_getcwd();
671a2781f   Jeff Vander Stoep   security: add ioc...
264
265
  		break;
  	}
a269434d2   Eric Paris   LSM: separate LSM...
266
267
268
269
  	case LSM_AUDIT_DATA_DENTRY: {
  		struct inode *inode;
  
  		audit_log_format(ab, " name=");
a3fddad7a   Al Viro   dump_common_audit...
270
  		spin_lock(&a->u.dentry->d_lock);
a269434d2   Eric Paris   LSM: separate LSM...
271
  		audit_log_untrustedstring(ab, a->u.dentry->d_name.name);
a3fddad7a   Al Viro   dump_common_audit...
272
  		spin_unlock(&a->u.dentry->d_lock);
a269434d2   Eric Paris   LSM: separate LSM...
273

c6f493d63   David Howells   VFS: security/: d...
274
  		inode = d_backing_inode(a->u.dentry);
41fdc3054   Kees Cook   audit: treat s_id...
275
276
277
278
279
  		if (inode) {
  			audit_log_format(ab, " dev=");
  			audit_log_untrustedstring(ab, inode->i_sb->s_id);
  			audit_log_format(ab, " ino=%lu", inode->i_ino);
  		}
d7481b24b   Richard Guy Briggs   audit: issue CWD ...
280
  		audit_getcwd();
6e837fb15   Etienne Basset   smack: implement ...
281
  		break;
f48b73998   Eric Paris   LSM: split LSM_AU...
282
283
284
285
286
287
288
289
290
  	}
  	case LSM_AUDIT_DATA_INODE: {
  		struct dentry *dentry;
  		struct inode *inode;
  
  		inode = a->u.inode;
  		dentry = d_find_alias(inode);
  		if (dentry) {
  			audit_log_format(ab, " name=");
a3fddad7a   Al Viro   dump_common_audit...
291
292
293
  			spin_lock(&dentry->d_lock);
  			audit_log_untrustedstring(ab, dentry->d_name.name);
  			spin_unlock(&dentry->d_lock);
f48b73998   Eric Paris   LSM: split LSM_AU...
294
295
  			dput(dentry);
  		}
41fdc3054   Kees Cook   audit: treat s_id...
296
297
298
  		audit_log_format(ab, " dev=");
  		audit_log_untrustedstring(ab, inode->i_sb->s_id);
  		audit_log_format(ab, " ino=%lu", inode->i_ino);
d7481b24b   Richard Guy Briggs   audit: issue CWD ...
299
  		audit_getcwd();
f48b73998   Eric Paris   LSM: split LSM_AU...
300
301
  		break;
  	}
5deeb5cec   Richard Guy Briggs   lsm: copy comm be...
302
303
  	case LSM_AUDIT_DATA_TASK: {
  		struct task_struct *tsk = a->u.tsk;
f1dc4867f   Richard Guy Briggs   audit: anchor all...
304
  		if (tsk) {
fa2bea2f5   Paul Moore   audit: consistent...
305
  			pid_t pid = task_tgid_nr(tsk);
f1dc4867f   Richard Guy Briggs   audit: anchor all...
306
  			if (pid) {
5deeb5cec   Richard Guy Briggs   lsm: copy comm be...
307
  				char comm[sizeof(tsk->comm)];
5c5bc97e2   Richard Guy Briggs   lsm: rename dupli...
308
  				audit_log_format(ab, " opid=%d ocomm=", pid);
5deeb5cec   Richard Guy Briggs   lsm: copy comm be...
309
310
  				audit_log_untrustedstring(ab,
  				    memcpy(comm, tsk->comm, sizeof(comm)));
f1dc4867f   Richard Guy Briggs   audit: anchor all...
311
  			}
6e837fb15   Etienne Basset   smack: implement ...
312
313
  		}
  		break;
5deeb5cec   Richard Guy Briggs   lsm: copy comm be...
314
  	}
6e837fb15   Etienne Basset   smack: implement ...
315
  	case LSM_AUDIT_DATA_NET:
48c62af68   Eric Paris   LSM: shrink the c...
316
317
  		if (a->u.net->sk) {
  			struct sock *sk = a->u.net->sk;
6e837fb15   Etienne Basset   smack: implement ...
318
  			struct unix_sock *u;
ae3b56417   Al Viro   missing barriers ...
319
  			struct unix_address *addr;
6e837fb15   Etienne Basset   smack: implement ...
320
321
322
323
324
325
  			int len = 0;
  			char *p = NULL;
  
  			switch (sk->sk_family) {
  			case AF_INET: {
  				struct inet_sock *inet = inet_sk(sk);
c720c7e83   Eric Dumazet   inet: rename some...
326
327
  				print_ipv4_addr(ab, inet->inet_rcv_saddr,
  						inet->inet_sport,
6e837fb15   Etienne Basset   smack: implement ...
328
  						"laddr", "lport");
c720c7e83   Eric Dumazet   inet: rename some...
329
330
  				print_ipv4_addr(ab, inet->inet_daddr,
  						inet->inet_dport,
6e837fb15   Etienne Basset   smack: implement ...
331
332
333
  						"faddr", "fport");
  				break;
  			}
c2bb06db5   Eric Dumazet   net: fix build er...
334
  #if IS_ENABLED(CONFIG_IPV6)
6e837fb15   Etienne Basset   smack: implement ...
335
336
  			case AF_INET6: {
  				struct inet_sock *inet = inet_sk(sk);
6e837fb15   Etienne Basset   smack: implement ...
337

efe4208f4   Eric Dumazet   ipv6: make lookup...
338
  				print_ipv6_addr(ab, &sk->sk_v6_rcv_saddr,
c720c7e83   Eric Dumazet   inet: rename some...
339
  						inet->inet_sport,
6e837fb15   Etienne Basset   smack: implement ...
340
  						"laddr", "lport");
efe4208f4   Eric Dumazet   ipv6: make lookup...
341
  				print_ipv6_addr(ab, &sk->sk_v6_daddr,
c720c7e83   Eric Dumazet   inet: rename some...
342
  						inet->inet_dport,
6e837fb15   Etienne Basset   smack: implement ...
343
344
345
  						"faddr", "fport");
  				break;
  			}
c2bb06db5   Eric Dumazet   net: fix build er...
346
  #endif
6e837fb15   Etienne Basset   smack: implement ...
347
348
  			case AF_UNIX:
  				u = unix_sk(sk);
ae3b56417   Al Viro   missing barriers ...
349
350
351
  				addr = smp_load_acquire(&u->addr);
  				if (!addr)
  					break;
40ffe67d2   Al Viro   switch unix_sock ...
352
353
  				if (u->path.dentry) {
  					audit_log_d_path(ab, " path=", &u->path);
6e837fb15   Etienne Basset   smack: implement ...
354
355
  					break;
  				}
ae3b56417   Al Viro   missing barriers ...
356
357
  				len = addr->len-sizeof(short);
  				p = &addr->name->sun_path[0];
6e837fb15   Etienne Basset   smack: implement ...
358
359
360
361
362
363
364
365
  				audit_log_format(ab, " path=");
  				if (*p)
  					audit_log_untrustedstring(ab, p);
  				else
  					audit_log_n_hex(ab, p, len);
  				break;
  			}
  		}
48c62af68   Eric Paris   LSM: shrink the c...
366
  		switch (a->u.net->family) {
6e837fb15   Etienne Basset   smack: implement ...
367
  		case AF_INET:
48c62af68   Eric Paris   LSM: shrink the c...
368
369
  			print_ipv4_addr(ab, a->u.net->v4info.saddr,
  					a->u.net->sport,
6e837fb15   Etienne Basset   smack: implement ...
370
  					"saddr", "src");
48c62af68   Eric Paris   LSM: shrink the c...
371
372
  			print_ipv4_addr(ab, a->u.net->v4info.daddr,
  					a->u.net->dport,
6e837fb15   Etienne Basset   smack: implement ...
373
374
375
  					"daddr", "dest");
  			break;
  		case AF_INET6:
48c62af68   Eric Paris   LSM: shrink the c...
376
377
  			print_ipv6_addr(ab, &a->u.net->v6info.saddr,
  					a->u.net->sport,
6e837fb15   Etienne Basset   smack: implement ...
378
  					"saddr", "src");
48c62af68   Eric Paris   LSM: shrink the c...
379
380
  			print_ipv6_addr(ab, &a->u.net->v6info.daddr,
  					a->u.net->dport,
6e837fb15   Etienne Basset   smack: implement ...
381
382
383
  					"daddr", "dest");
  			break;
  		}
48c62af68   Eric Paris   LSM: shrink the c...
384
  		if (a->u.net->netif > 0) {
6e837fb15   Etienne Basset   smack: implement ...
385
386
387
  			struct net_device *dev;
  
  			/* NOTE: we always use init's namespace */
48c62af68   Eric Paris   LSM: shrink the c...
388
  			dev = dev_get_by_index(&init_net, a->u.net->netif);
6e837fb15   Etienne Basset   smack: implement ...
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
  			if (dev) {
  				audit_log_format(ab, " netif=%s", dev->name);
  				dev_put(dev);
  			}
  		}
  		break;
  #ifdef CONFIG_KEYS
  	case LSM_AUDIT_DATA_KEY:
  		audit_log_format(ab, " key_serial=%u", a->u.key_struct.key);
  		if (a->u.key_struct.key_desc) {
  			audit_log_format(ab, " key_desc=");
  			audit_log_untrustedstring(ab, a->u.key_struct.key_desc);
  		}
  		break;
  #endif
dd8dbf2e6   Eric Paris   security: report ...
404
405
406
407
  	case LSM_AUDIT_DATA_KMOD:
  		audit_log_format(ab, " kmod=");
  		audit_log_untrustedstring(ab, a->u.kmod_name);
  		break;
cfc4d882d   Daniel Jurgens   selinux: Implemen...
408
409
410
411
412
413
414
415
416
417
418
  	case LSM_AUDIT_DATA_IBPKEY: {
  		struct in6_addr sbn_pfx;
  
  		memset(&sbn_pfx.s6_addr, 0,
  		       sizeof(sbn_pfx.s6_addr));
  		memcpy(&sbn_pfx.s6_addr, &a->u.ibpkey->subnet_prefix,
  		       sizeof(a->u.ibpkey->subnet_prefix));
  		audit_log_format(ab, " pkey=0x%x subnet_prefix=%pI6c",
  				 a->u.ibpkey->pkey, &sbn_pfx);
  		break;
  	}
ab861dfca   Daniel Jurgens   selinux: Add IB P...
419
420
421
422
423
  	case LSM_AUDIT_DATA_IBENDPORT:
  		audit_log_format(ab, " device=%s port_num=%u",
  				 a->u.ibendport->dev_name,
  				 a->u.ibendport->port);
  		break;
6e837fb15   Etienne Basset   smack: implement ...
424
425
426
427
428
429
  	} /* switch (a->type) */
  }
  
  /**
   * common_lsm_audit - generic LSM auditing function
   * @a:  auxiliary audit data
b61c37f57   Linus Torvalds   lsm_audit: don't ...
430
431
   * @pre_audit: lsm-specific pre-audit callback
   * @post_audit: lsm-specific post-audit callback
6e837fb15   Etienne Basset   smack: implement ...
432
433
434
435
   *
   * setup the audit buffer for common security information
   * uses callback to print LSM specific information
   */
b61c37f57   Linus Torvalds   lsm_audit: don't ...
436
437
438
  void common_lsm_audit(struct common_audit_data *a,
  	void (*pre_audit)(struct audit_buffer *, void *),
  	void (*post_audit)(struct audit_buffer *, void *))
6e837fb15   Etienne Basset   smack: implement ...
439
440
441
442
443
444
  {
  	struct audit_buffer *ab;
  
  	if (a == NULL)
  		return;
  	/* we use GFP_ATOMIC so we won't sleep */
cdfb6b341   Richard Guy Briggs   audit: use inline...
445
  	ab = audit_log_start(audit_context(), GFP_ATOMIC | __GFP_NOWARN,
a20b62bdf   Richard Guy Briggs   audit: suppress s...
446
  			     AUDIT_AVC);
6e837fb15   Etienne Basset   smack: implement ...
447
448
449
  
  	if (ab == NULL)
  		return;
b61c37f57   Linus Torvalds   lsm_audit: don't ...
450
451
  	if (pre_audit)
  		pre_audit(ab, a);
6e837fb15   Etienne Basset   smack: implement ...
452
453
  
  	dump_common_audit_data(ab, a);
b61c37f57   Linus Torvalds   lsm_audit: don't ...
454
455
  	if (post_audit)
  		post_audit(ab, a);
6e837fb15   Etienne Basset   smack: implement ...
456
457
458
  
  	audit_log_end(ab);
  }