]> bbs.cooldavid.org Git - net-next-2.6.git/blame - kernel/audit.c
[PATCH] fix ppid bug in 2.6.18 kernel
[net-next-2.6.git] / kernel / audit.c
CommitLineData
85c8721f 1/* audit.c -- Auditing support
1da177e4
LT
2 * Gateway between the kernel (e.g., selinux) and the user-space audit daemon.
3 * System-call specific features have moved to auditsc.c
4 *
5 * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
6 * All Rights Reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 * Written by Rickard E. (Rik) Faith <faith@redhat.com>
23 *
24 * Goals: 1) Integrate fully with SELinux.
25 * 2) Minimal run-time overhead:
26 * a) Minimal when syscall auditing is disabled (audit_enable=0).
27 * b) Small when syscall auditing is enabled and no audit record
28 * is generated (defer as much work as possible to record
29 * generation time):
30 * i) context is allocated,
31 * ii) names from getname are stored without a copy, and
32 * iii) inode information stored from path_lookup.
33 * 3) Ability to disable syscall auditing at boot time (audit=0).
34 * 4) Usable by other parts of the kernel (if audit_log* is called,
35 * then a syscall record will be generated automatically for the
36 * current syscall).
37 * 5) Netlink interface to user-space.
38 * 6) Support low-overhead kernel-based filtering to minimize the
39 * information that must be passed to user-space.
40 *
85c8721f 41 * Example user-space utilities: http://people.redhat.com/sgrubb/audit/
1da177e4
LT
42 */
43
44#include <linux/init.h>
1da177e4 45#include <asm/types.h>
715b49ef 46#include <asm/atomic.h>
1da177e4
LT
47#include <linux/mm.h>
48#include <linux/module.h>
b7d11258
DW
49#include <linux/err.h>
50#include <linux/kthread.h>
1da177e4
LT
51
52#include <linux/audit.h>
53
54#include <net/sock.h>
93315ed6 55#include <net/netlink.h>
1da177e4
LT
56#include <linux/skbuff.h>
57#include <linux/netlink.h>
3dc7e315 58#include <linux/selinux.h>
f368c07d 59#include <linux/inotify.h>
3dc7e315
DG
60
61#include "audit.h"
1da177e4
LT
62
63/* No auditing will take place until audit_initialized != 0.
64 * (Initialization happens after skb_init is called.) */
65static int audit_initialized;
66
67/* No syscall auditing will take place unless audit_enabled != 0. */
68int audit_enabled;
69
70/* Default state when kernel boots without any parameters. */
71static int audit_default;
72
73/* If auditing cannot proceed, audit_failure selects what happens. */
74static int audit_failure = AUDIT_FAIL_PRINTK;
75
76/* If audit records are to be written to the netlink socket, audit_pid
77 * contains the (non-zero) pid. */
c2f0c7c3 78int audit_pid;
1da177e4 79
b0dd25a8 80/* If audit_rate_limit is non-zero, limit the rate of sending audit records
1da177e4
LT
81 * to that number per second. This prevents DoS attacks, but results in
82 * audit records being dropped. */
83static int audit_rate_limit;
84
85/* Number of outstanding audit_buffers allowed. */
86static int audit_backlog_limit = 64;
ac4cec44
DW
87static int audit_backlog_wait_time = 60 * HZ;
88static int audit_backlog_wait_overflow = 0;
1da177e4 89
c2f0c7c3
SG
90/* The identity of the user shutting down the audit system. */
91uid_t audit_sig_uid = -1;
92pid_t audit_sig_pid = -1;
e1396065 93u32 audit_sig_sid = 0;
c2f0c7c3 94
1da177e4
LT
95/* Records can be lost in several ways:
96 0) [suppressed in audit_alloc]
97 1) out of memory in audit_log_start [kmalloc of struct audit_buffer]
98 2) out of memory in audit_log_move [alloc_skb]
99 3) suppressed due to audit_rate_limit
100 4) suppressed due to audit_backlog_limit
101*/
102static atomic_t audit_lost = ATOMIC_INIT(0);
103
104/* The netlink socket. */
105static struct sock *audit_sock;
106
f368c07d
AG
107/* Inotify handle. */
108struct inotify_handle *audit_ih;
109
110/* Hash for inode-based rules */
111struct list_head audit_inode_hash[AUDIT_INODE_BUCKETS];
112
b7d11258 113/* The audit_freelist is a list of pre-allocated audit buffers (if more
1da177e4
LT
114 * than AUDIT_MAXFREE are in use, the audit buffer is freed instead of
115 * being placed on the freelist). */
1da177e4 116static DEFINE_SPINLOCK(audit_freelist_lock);
b0dd25a8 117static int audit_freelist_count;
1da177e4
LT
118static LIST_HEAD(audit_freelist);
119
b7d11258
DW
120static struct sk_buff_head audit_skb_queue;
121static struct task_struct *kauditd_task;
122static DECLARE_WAIT_QUEUE_HEAD(kauditd_wait);
9ad9ad38 123static DECLARE_WAIT_QUEUE_HEAD(audit_backlog_wait);
1da177e4 124
f368c07d
AG
125/* Serialize requests from userspace. */
126static DEFINE_MUTEX(audit_cmd_mutex);
1da177e4
LT
127
128/* AUDIT_BUFSIZ is the size of the temporary buffer used for formatting
129 * audit records. Since printk uses a 1024 byte buffer, this buffer
130 * should be at least that large. */
131#define AUDIT_BUFSIZ 1024
132
133/* AUDIT_MAXFREE is the number of empty audit_buffers we keep on the
134 * audit_freelist. Doing so eliminates many kmalloc/kfree calls. */
135#define AUDIT_MAXFREE (2*NR_CPUS)
136
137/* The audit_buffer is used when formatting an audit record. The caller
138 * locks briefly to get the record off the freelist or to allocate the
139 * buffer, and locks briefly to send the buffer to the netlink layer or
140 * to place it on a transmit queue. Multiple audit_buffers can be in
141 * use simultaneously. */
142struct audit_buffer {
143 struct list_head list;
8fc6115c 144 struct sk_buff *skb; /* formatted skb ready to send */
1da177e4 145 struct audit_context *ctx; /* NULL or associated context */
9796fdd8 146 gfp_t gfp_mask;
1da177e4
LT
147};
148
c0404993
SG
149static void audit_set_pid(struct audit_buffer *ab, pid_t pid)
150{
151 struct nlmsghdr *nlh = (struct nlmsghdr *)ab->skb->data;
152 nlh->nlmsg_pid = pid;
153}
154
8c8570fb 155void audit_panic(const char *message)
1da177e4
LT
156{
157 switch (audit_failure)
158 {
159 case AUDIT_FAIL_SILENT:
160 break;
161 case AUDIT_FAIL_PRINTK:
162 printk(KERN_ERR "audit: %s\n", message);
163 break;
164 case AUDIT_FAIL_PANIC:
165 panic("audit: %s\n", message);
166 break;
167 }
168}
169
170static inline int audit_rate_check(void)
171{
172 static unsigned long last_check = 0;
173 static int messages = 0;
174 static DEFINE_SPINLOCK(lock);
175 unsigned long flags;
176 unsigned long now;
177 unsigned long elapsed;
178 int retval = 0;
179
180 if (!audit_rate_limit) return 1;
181
182 spin_lock_irqsave(&lock, flags);
183 if (++messages < audit_rate_limit) {
184 retval = 1;
185 } else {
186 now = jiffies;
187 elapsed = now - last_check;
188 if (elapsed > HZ) {
189 last_check = now;
190 messages = 0;
191 retval = 1;
192 }
193 }
194 spin_unlock_irqrestore(&lock, flags);
195
196 return retval;
197}
198
b0dd25a8
RD
199/**
200 * audit_log_lost - conditionally log lost audit message event
201 * @message: the message stating reason for lost audit message
202 *
203 * Emit at least 1 message per second, even if audit_rate_check is
204 * throttling.
205 * Always increment the lost messages counter.
206*/
1da177e4
LT
207void audit_log_lost(const char *message)
208{
209 static unsigned long last_msg = 0;
210 static DEFINE_SPINLOCK(lock);
211 unsigned long flags;
212 unsigned long now;
213 int print;
214
215 atomic_inc(&audit_lost);
216
217 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
218
219 if (!print) {
220 spin_lock_irqsave(&lock, flags);
221 now = jiffies;
222 if (now - last_msg > HZ) {
223 print = 1;
224 last_msg = now;
225 }
226 spin_unlock_irqrestore(&lock, flags);
227 }
228
229 if (print) {
230 printk(KERN_WARNING
b7d11258 231 "audit: audit_lost=%d audit_rate_limit=%d audit_backlog_limit=%d\n",
1da177e4 232 atomic_read(&audit_lost),
1da177e4
LT
233 audit_rate_limit,
234 audit_backlog_limit);
235 audit_panic(message);
236 }
1da177e4
LT
237}
238
ce29b682 239static int audit_set_rate_limit(int limit, uid_t loginuid, u32 sid)
1da177e4 240{
ce29b682
SG
241 int old = audit_rate_limit;
242
243 if (sid) {
244 char *ctx = NULL;
245 u32 len;
246 int rc;
247 if ((rc = selinux_ctxid_to_string(sid, &ctx, &len)))
248 return rc;
249 else
250 audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
251 "audit_rate_limit=%d old=%d by auid=%u subj=%s",
252 limit, old, loginuid, ctx);
253 kfree(ctx);
254 } else
255 audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
bccf6ae0 256 "audit_rate_limit=%d old=%d by auid=%u",
ce29b682
SG
257 limit, old, loginuid);
258 audit_rate_limit = limit;
5d136a01 259 return 0;
1da177e4
LT
260}
261
ce29b682 262static int audit_set_backlog_limit(int limit, uid_t loginuid, u32 sid)
1da177e4 263{
ce29b682
SG
264 int old = audit_backlog_limit;
265
266 if (sid) {
267 char *ctx = NULL;
268 u32 len;
269 int rc;
270 if ((rc = selinux_ctxid_to_string(sid, &ctx, &len)))
271 return rc;
272 else
273 audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
274 "audit_backlog_limit=%d old=%d by auid=%u subj=%s",
275 limit, old, loginuid, ctx);
276 kfree(ctx);
277 } else
278 audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
bccf6ae0 279 "audit_backlog_limit=%d old=%d by auid=%u",
ce29b682
SG
280 limit, old, loginuid);
281 audit_backlog_limit = limit;
5d136a01 282 return 0;
1da177e4
LT
283}
284
ce29b682 285static int audit_set_enabled(int state, uid_t loginuid, u32 sid)
1da177e4 286{
ce29b682
SG
287 int old = audit_enabled;
288
1da177e4
LT
289 if (state != 0 && state != 1)
290 return -EINVAL;
ce29b682
SG
291
292 if (sid) {
293 char *ctx = NULL;
294 u32 len;
295 int rc;
296 if ((rc = selinux_ctxid_to_string(sid, &ctx, &len)))
297 return rc;
298 else
299 audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
300 "audit_enabled=%d old=%d by auid=%u subj=%s",
301 state, old, loginuid, ctx);
302 kfree(ctx);
303 } else
304 audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
bccf6ae0 305 "audit_enabled=%d old=%d by auid=%u",
ce29b682
SG
306 state, old, loginuid);
307 audit_enabled = state;
5d136a01 308 return 0;
1da177e4
LT
309}
310
ce29b682 311static int audit_set_failure(int state, uid_t loginuid, u32 sid)
1da177e4 312{
ce29b682
SG
313 int old = audit_failure;
314
1da177e4
LT
315 if (state != AUDIT_FAIL_SILENT
316 && state != AUDIT_FAIL_PRINTK
317 && state != AUDIT_FAIL_PANIC)
318 return -EINVAL;
ce29b682
SG
319
320 if (sid) {
321 char *ctx = NULL;
322 u32 len;
323 int rc;
324 if ((rc = selinux_ctxid_to_string(sid, &ctx, &len)))
325 return rc;
326 else
327 audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
328 "audit_failure=%d old=%d by auid=%u subj=%s",
329 state, old, loginuid, ctx);
330 kfree(ctx);
331 } else
332 audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
bccf6ae0 333 "audit_failure=%d old=%d by auid=%u",
ce29b682
SG
334 state, old, loginuid);
335 audit_failure = state;
5d136a01 336 return 0;
1da177e4
LT
337}
338
97a41e26 339static int kauditd_thread(void *dummy)
b7d11258
DW
340{
341 struct sk_buff *skb;
342
343 while (1) {
344 skb = skb_dequeue(&audit_skb_queue);
9ad9ad38 345 wake_up(&audit_backlog_wait);
b7d11258
DW
346 if (skb) {
347 if (audit_pid) {
348 int err = netlink_unicast(audit_sock, skb, audit_pid, 0);
349 if (err < 0) {
350 BUG_ON(err != -ECONNREFUSED); /* Shoudn't happen */
351 printk(KERN_ERR "audit: *NO* daemon at audit_pid=%d\n", audit_pid);
352 audit_pid = 0;
353 }
354 } else {
e1b09eba 355 printk(KERN_NOTICE "%s\n", skb->data + NLMSG_SPACE(0));
b7d11258
DW
356 kfree_skb(skb);
357 }
358 } else {
359 DECLARE_WAITQUEUE(wait, current);
360 set_current_state(TASK_INTERRUPTIBLE);
361 add_wait_queue(&kauditd_wait, &wait);
362
7a4ae749
PO
363 if (!skb_queue_len(&audit_skb_queue)) {
364 try_to_freeze();
b7d11258 365 schedule();
7a4ae749 366 }
b7d11258
DW
367
368 __set_current_state(TASK_RUNNING);
369 remove_wait_queue(&kauditd_wait, &wait);
370 }
371 }
372}
373
9044e6bc
AV
374int audit_send_list(void *_dest)
375{
376 struct audit_netlink_list *dest = _dest;
377 int pid = dest->pid;
378 struct sk_buff *skb;
379
380 /* wait for parent to finish and send an ACK */
f368c07d
AG
381 mutex_lock(&audit_cmd_mutex);
382 mutex_unlock(&audit_cmd_mutex);
9044e6bc
AV
383
384 while ((skb = __skb_dequeue(&dest->q)) != NULL)
385 netlink_unicast(audit_sock, skb, pid, 0);
386
387 kfree(dest);
388
389 return 0;
390}
391
392struct sk_buff *audit_make_reply(int pid, int seq, int type, int done,
393 int multi, void *payload, int size)
394{
395 struct sk_buff *skb;
396 struct nlmsghdr *nlh;
397 int len = NLMSG_SPACE(size);
398 void *data;
399 int flags = multi ? NLM_F_MULTI : 0;
400 int t = done ? NLMSG_DONE : type;
401
402 skb = alloc_skb(len, GFP_KERNEL);
403 if (!skb)
404 return NULL;
405
406 nlh = NLMSG_PUT(skb, pid, seq, t, size);
407 nlh->nlmsg_flags = flags;
408 data = NLMSG_DATA(nlh);
409 memcpy(data, payload, size);
410 return skb;
411
412nlmsg_failure: /* Used by NLMSG_PUT */
413 if (skb)
414 kfree_skb(skb);
415 return NULL;
416}
417
b0dd25a8
RD
418/**
419 * audit_send_reply - send an audit reply message via netlink
420 * @pid: process id to send reply to
421 * @seq: sequence number
422 * @type: audit message type
423 * @done: done (last) flag
424 * @multi: multi-part message flag
425 * @payload: payload data
426 * @size: payload size
427 *
428 * Allocates an skb, builds the netlink message, and sends it to the pid.
429 * No failure notifications.
430 */
1da177e4
LT
431void audit_send_reply(int pid, int seq, int type, int done, int multi,
432 void *payload, int size)
433{
434 struct sk_buff *skb;
9044e6bc 435 skb = audit_make_reply(pid, seq, type, done, multi, payload, size);
1da177e4 436 if (!skb)
b7d11258 437 return;
b7d11258
DW
438 /* Ignore failure. It'll only happen if the sender goes away,
439 because our timeout is set to infinite. */
440 netlink_unicast(audit_sock, skb, pid, 0);
1da177e4 441 return;
1da177e4
LT
442}
443
444/*
445 * Check for appropriate CAP_AUDIT_ capabilities on incoming audit
446 * control messages.
447 */
c7bdb545 448static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type)
1da177e4
LT
449{
450 int err = 0;
451
452 switch (msg_type) {
453 case AUDIT_GET:
454 case AUDIT_LIST:
93315ed6 455 case AUDIT_LIST_RULES:
1da177e4
LT
456 case AUDIT_SET:
457 case AUDIT_ADD:
93315ed6 458 case AUDIT_ADD_RULE:
1da177e4 459 case AUDIT_DEL:
93315ed6 460 case AUDIT_DEL_RULE:
c2f0c7c3 461 case AUDIT_SIGNAL_INFO:
c7bdb545 462 if (security_netlink_recv(skb, CAP_AUDIT_CONTROL))
1da177e4
LT
463 err = -EPERM;
464 break;
05474106 465 case AUDIT_USER:
209aba03 466 case AUDIT_FIRST_USER_MSG...AUDIT_LAST_USER_MSG:
90d526c0 467 case AUDIT_FIRST_USER_MSG2...AUDIT_LAST_USER_MSG2:
c7bdb545 468 if (security_netlink_recv(skb, CAP_AUDIT_WRITE))
1da177e4
LT
469 err = -EPERM;
470 break;
471 default: /* bad msg */
472 err = -EINVAL;
473 }
474
475 return err;
476}
477
478static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
479{
e7c34970 480 u32 uid, pid, seq, sid;
1da177e4
LT
481 void *data;
482 struct audit_status *status_get, status_set;
483 int err;
c0404993 484 struct audit_buffer *ab;
1da177e4 485 u16 msg_type = nlh->nlmsg_type;
c94c257c 486 uid_t loginuid; /* loginuid of sender */
e1396065
AV
487 struct audit_sig_info *sig_data;
488 char *ctx;
489 u32 len;
1da177e4 490
c7bdb545 491 err = audit_netlink_ok(skb, msg_type);
1da177e4
LT
492 if (err)
493 return err;
494
b0dd25a8
RD
495 /* As soon as there's any sign of userspace auditd,
496 * start kauditd to talk to it */
b7d11258
DW
497 if (!kauditd_task)
498 kauditd_task = kthread_run(kauditd_thread, NULL, "kauditd");
499 if (IS_ERR(kauditd_task)) {
500 err = PTR_ERR(kauditd_task);
501 kauditd_task = NULL;
502 return err;
503 }
504
1da177e4
LT
505 pid = NETLINK_CREDS(skb)->pid;
506 uid = NETLINK_CREDS(skb)->uid;
c94c257c 507 loginuid = NETLINK_CB(skb).loginuid;
e7c34970 508 sid = NETLINK_CB(skb).sid;
1da177e4
LT
509 seq = nlh->nlmsg_seq;
510 data = NLMSG_DATA(nlh);
511
512 switch (msg_type) {
513 case AUDIT_GET:
514 status_set.enabled = audit_enabled;
515 status_set.failure = audit_failure;
516 status_set.pid = audit_pid;
517 status_set.rate_limit = audit_rate_limit;
518 status_set.backlog_limit = audit_backlog_limit;
519 status_set.lost = atomic_read(&audit_lost);
b7d11258 520 status_set.backlog = skb_queue_len(&audit_skb_queue);
1da177e4
LT
521 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
522 &status_set, sizeof(status_set));
523 break;
524 case AUDIT_SET:
525 if (nlh->nlmsg_len < sizeof(struct audit_status))
526 return -EINVAL;
527 status_get = (struct audit_status *)data;
528 if (status_get->mask & AUDIT_STATUS_ENABLED) {
ce29b682
SG
529 err = audit_set_enabled(status_get->enabled,
530 loginuid, sid);
1da177e4
LT
531 if (err < 0) return err;
532 }
533 if (status_get->mask & AUDIT_STATUS_FAILURE) {
ce29b682
SG
534 err = audit_set_failure(status_get->failure,
535 loginuid, sid);
1da177e4
LT
536 if (err < 0) return err;
537 }
538 if (status_get->mask & AUDIT_STATUS_PID) {
539 int old = audit_pid;
ce29b682 540 if (sid) {
e1396065 541 if ((err = selinux_ctxid_to_string(
ce29b682 542 sid, &ctx, &len)))
e1396065 543 return err;
ce29b682
SG
544 else
545 audit_log(NULL, GFP_KERNEL,
546 AUDIT_CONFIG_CHANGE,
547 "audit_pid=%d old=%d by auid=%u subj=%s",
548 status_get->pid, old,
549 loginuid, ctx);
550 kfree(ctx);
551 } else
552 audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
553 "audit_pid=%d old=%d by auid=%u",
554 status_get->pid, old, loginuid);
1da177e4 555 audit_pid = status_get->pid;
1da177e4
LT
556 }
557 if (status_get->mask & AUDIT_STATUS_RATE_LIMIT)
5d136a01 558 err = audit_set_rate_limit(status_get->rate_limit,
ce29b682 559 loginuid, sid);
1da177e4 560 if (status_get->mask & AUDIT_STATUS_BACKLOG_LIMIT)
5d136a01 561 err = audit_set_backlog_limit(status_get->backlog_limit,
ce29b682 562 loginuid, sid);
1da177e4 563 break;
05474106 564 case AUDIT_USER:
209aba03 565 case AUDIT_FIRST_USER_MSG...AUDIT_LAST_USER_MSG:
90d526c0 566 case AUDIT_FIRST_USER_MSG2...AUDIT_LAST_USER_MSG2:
4a4cd633
DW
567 if (!audit_enabled && msg_type != AUDIT_USER_AVC)
568 return 0;
569
5bb289b5 570 err = audit_filter_user(&NETLINK_CB(skb), msg_type);
4a4cd633
DW
571 if (err == 1) {
572 err = 0;
9ad9ad38 573 ab = audit_log_start(NULL, GFP_KERNEL, msg_type);
4a4cd633
DW
574 if (ab) {
575 audit_log_format(ab,
e7c34970
SG
576 "user pid=%d uid=%u auid=%u",
577 pid, uid, loginuid);
578 if (sid) {
e7c34970
SG
579 if (selinux_ctxid_to_string(
580 sid, &ctx, &len)) {
581 audit_log_format(ab,
ce29b682 582 " ssid=%u", sid);
e7c34970
SG
583 /* Maybe call audit_panic? */
584 } else
585 audit_log_format(ab,
586 " subj=%s", ctx);
587 kfree(ctx);
588 }
589 audit_log_format(ab, " msg='%.1024s'",
590 (char *)data);
4a4cd633
DW
591 audit_set_pid(ab, pid);
592 audit_log_end(ab);
593 }
0f45aa18 594 }
1da177e4
LT
595 break;
596 case AUDIT_ADD:
597 case AUDIT_DEL:
93315ed6 598 if (nlmsg_len(nlh) < sizeof(struct audit_rule))
1da177e4
LT
599 return -EINVAL;
600 /* fallthrough */
601 case AUDIT_LIST:
1da177e4 602 err = audit_receive_filter(nlh->nlmsg_type, NETLINK_CB(skb).pid,
93315ed6 603 uid, seq, data, nlmsg_len(nlh),
ce29b682 604 loginuid, sid);
93315ed6
AG
605 break;
606 case AUDIT_ADD_RULE:
607 case AUDIT_DEL_RULE:
608 if (nlmsg_len(nlh) < sizeof(struct audit_rule_data))
609 return -EINVAL;
610 /* fallthrough */
611 case AUDIT_LIST_RULES:
612 err = audit_receive_filter(nlh->nlmsg_type, NETLINK_CB(skb).pid,
613 uid, seq, data, nlmsg_len(nlh),
ce29b682 614 loginuid, sid);
1da177e4 615 break;
c2f0c7c3 616 case AUDIT_SIGNAL_INFO:
e1396065
AV
617 err = selinux_ctxid_to_string(audit_sig_sid, &ctx, &len);
618 if (err)
619 return err;
620 sig_data = kmalloc(sizeof(*sig_data) + len, GFP_KERNEL);
621 if (!sig_data) {
622 kfree(ctx);
623 return -ENOMEM;
624 }
625 sig_data->uid = audit_sig_uid;
626 sig_data->pid = audit_sig_pid;
627 memcpy(sig_data->ctx, ctx, len);
628 kfree(ctx);
c2f0c7c3 629 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_SIGNAL_INFO,
e1396065
AV
630 0, 0, sig_data, sizeof(*sig_data) + len);
631 kfree(sig_data);
c2f0c7c3 632 break;
1da177e4
LT
633 default:
634 err = -EINVAL;
635 break;
636 }
637
638 return err < 0 ? err : 0;
639}
640
b0dd25a8
RD
641/*
642 * Get message from skb (based on rtnetlink_rcv_skb). Each message is
1da177e4 643 * processed by audit_receive_msg. Malformed skbs with wrong length are
b0dd25a8
RD
644 * discarded silently.
645 */
2a0a6ebe 646static void audit_receive_skb(struct sk_buff *skb)
1da177e4
LT
647{
648 int err;
649 struct nlmsghdr *nlh;
650 u32 rlen;
651
652 while (skb->len >= NLMSG_SPACE(0)) {
653 nlh = (struct nlmsghdr *)skb->data;
654 if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len)
2a0a6ebe 655 return;
1da177e4
LT
656 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
657 if (rlen > skb->len)
658 rlen = skb->len;
659 if ((err = audit_receive_msg(skb, nlh))) {
660 netlink_ack(skb, nlh, err);
661 } else if (nlh->nlmsg_flags & NLM_F_ACK)
662 netlink_ack(skb, nlh, 0);
663 skb_pull(skb, rlen);
664 }
1da177e4
LT
665}
666
667/* Receive messages from netlink socket. */
668static void audit_receive(struct sock *sk, int length)
669{
670 struct sk_buff *skb;
2a0a6ebe 671 unsigned int qlen;
1da177e4 672
f368c07d 673 mutex_lock(&audit_cmd_mutex);
1da177e4 674
2a0a6ebe
HX
675 for (qlen = skb_queue_len(&sk->sk_receive_queue); qlen; qlen--) {
676 skb = skb_dequeue(&sk->sk_receive_queue);
677 audit_receive_skb(skb);
678 kfree_skb(skb);
1da177e4 679 }
f368c07d 680 mutex_unlock(&audit_cmd_mutex);
1da177e4
LT
681}
682
f368c07d
AG
683#ifdef CONFIG_AUDITSYSCALL
684static const struct inotify_operations audit_inotify_ops = {
685 .handle_event = audit_handle_ievent,
686 .destroy_watch = audit_free_parent,
687};
688#endif
1da177e4
LT
689
690/* Initialize audit support at boot time. */
691static int __init audit_init(void)
692{
f368c07d 693 int i;
f368c07d 694
1da177e4
LT
695 printk(KERN_INFO "audit: initializing netlink socket (%s)\n",
696 audit_default ? "enabled" : "disabled");
06628607 697 audit_sock = netlink_kernel_create(NETLINK_AUDIT, 0, audit_receive,
4fdb3bb7 698 THIS_MODULE);
1da177e4
LT
699 if (!audit_sock)
700 audit_panic("cannot initialize netlink socket");
71e1c784
AG
701 else
702 audit_sock->sk_sndtimeo = MAX_SCHEDULE_TIMEOUT;
1da177e4 703
b7d11258 704 skb_queue_head_init(&audit_skb_queue);
1da177e4
LT
705 audit_initialized = 1;
706 audit_enabled = audit_default;
3dc7e315
DG
707
708 /* Register the callback with selinux. This callback will be invoked
709 * when a new policy is loaded. */
710 selinux_audit_set_callback(&selinux_audit_rule_update);
711
9ad9ad38 712 audit_log(NULL, GFP_KERNEL, AUDIT_KERNEL, "initialized");
f368c07d
AG
713
714#ifdef CONFIG_AUDITSYSCALL
715 audit_ih = inotify_init(&audit_inotify_ops);
716 if (IS_ERR(audit_ih))
717 audit_panic("cannot initialize inotify handle");
6988434e 718#endif
f368c07d
AG
719
720 for (i = 0; i < AUDIT_INODE_BUCKETS; i++)
721 INIT_LIST_HEAD(&audit_inode_hash[i]);
f368c07d 722
1da177e4
LT
723 return 0;
724}
1da177e4
LT
725__initcall(audit_init);
726
727/* Process kernel command-line parameter at boot time. audit=0 or audit=1. */
728static int __init audit_enable(char *str)
729{
730 audit_default = !!simple_strtol(str, NULL, 0);
731 printk(KERN_INFO "audit: %s%s\n",
732 audit_default ? "enabled" : "disabled",
733 audit_initialized ? "" : " (after initialization)");
734 if (audit_initialized)
735 audit_enabled = audit_default;
9b41046c 736 return 1;
1da177e4
LT
737}
738
739__setup("audit=", audit_enable);
740
16e1904e
CW
741static void audit_buffer_free(struct audit_buffer *ab)
742{
743 unsigned long flags;
744
8fc6115c
CW
745 if (!ab)
746 return;
747
5ac52f33
CW
748 if (ab->skb)
749 kfree_skb(ab->skb);
b7d11258 750
16e1904e 751 spin_lock_irqsave(&audit_freelist_lock, flags);
5d136a01 752 if (audit_freelist_count > AUDIT_MAXFREE)
16e1904e 753 kfree(ab);
5d136a01
SH
754 else {
755 audit_freelist_count++;
16e1904e 756 list_add(&ab->list, &audit_freelist);
5d136a01 757 }
16e1904e
CW
758 spin_unlock_irqrestore(&audit_freelist_lock, flags);
759}
760
c0404993 761static struct audit_buffer * audit_buffer_alloc(struct audit_context *ctx,
dd0fc66f 762 gfp_t gfp_mask, int type)
16e1904e
CW
763{
764 unsigned long flags;
765 struct audit_buffer *ab = NULL;
c0404993 766 struct nlmsghdr *nlh;
16e1904e
CW
767
768 spin_lock_irqsave(&audit_freelist_lock, flags);
769 if (!list_empty(&audit_freelist)) {
770 ab = list_entry(audit_freelist.next,
771 struct audit_buffer, list);
772 list_del(&ab->list);
773 --audit_freelist_count;
774 }
775 spin_unlock_irqrestore(&audit_freelist_lock, flags);
776
777 if (!ab) {
4332bdd3 778 ab = kmalloc(sizeof(*ab), gfp_mask);
16e1904e 779 if (!ab)
8fc6115c 780 goto err;
16e1904e 781 }
8fc6115c 782
4332bdd3 783 ab->skb = alloc_skb(AUDIT_BUFSIZ, gfp_mask);
5ac52f33 784 if (!ab->skb)
8fc6115c
CW
785 goto err;
786
b7d11258 787 ab->ctx = ctx;
9ad9ad38 788 ab->gfp_mask = gfp_mask;
c0404993
SG
789 nlh = (struct nlmsghdr *)skb_put(ab->skb, NLMSG_SPACE(0));
790 nlh->nlmsg_type = type;
791 nlh->nlmsg_flags = 0;
792 nlh->nlmsg_pid = 0;
793 nlh->nlmsg_seq = 0;
16e1904e 794 return ab;
8fc6115c
CW
795err:
796 audit_buffer_free(ab);
797 return NULL;
16e1904e 798}
1da177e4 799
b0dd25a8
RD
800/**
801 * audit_serial - compute a serial number for the audit record
802 *
803 * Compute a serial number for the audit record. Audit records are
bfb4496e
DW
804 * written to user-space as soon as they are generated, so a complete
805 * audit record may be written in several pieces. The timestamp of the
806 * record and this serial number are used by the user-space tools to
807 * determine which pieces belong to the same audit record. The
808 * (timestamp,serial) tuple is unique for each syscall and is live from
809 * syscall entry to syscall exit.
810 *
bfb4496e
DW
811 * NOTE: Another possibility is to store the formatted records off the
812 * audit context (for those records that have a context), and emit them
813 * all at syscall exit. However, this could delay the reporting of
814 * significant errors until syscall exit (or never, if the system
b0dd25a8
RD
815 * halts).
816 */
bfb4496e
DW
817unsigned int audit_serial(void)
818{
34af946a 819 static DEFINE_SPINLOCK(serial_lock);
d5b454f2
DW
820 static unsigned int serial = 0;
821
822 unsigned long flags;
823 unsigned int ret;
bfb4496e 824
d5b454f2 825 spin_lock_irqsave(&serial_lock, flags);
bfb4496e 826 do {
ce625a80
DW
827 ret = ++serial;
828 } while (unlikely(!ret));
d5b454f2 829 spin_unlock_irqrestore(&serial_lock, flags);
bfb4496e 830
d5b454f2 831 return ret;
bfb4496e
DW
832}
833
834static inline void audit_get_stamp(struct audit_context *ctx,
835 struct timespec *t, unsigned int *serial)
836{
837 if (ctx)
838 auditsc_get_stamp(ctx, t, serial);
839 else {
840 *t = CURRENT_TIME;
841 *serial = audit_serial();
842 }
843}
844
1da177e4
LT
845/* Obtain an audit buffer. This routine does locking to obtain the
846 * audit buffer, but then no locking is required for calls to
847 * audit_log_*format. If the tsk is a task that is currently in a
848 * syscall, then the syscall is marked as auditable and an audit record
849 * will be written at syscall exit. If there is no associated task, tsk
850 * should be NULL. */
9ad9ad38 851
b0dd25a8
RD
852/**
853 * audit_log_start - obtain an audit buffer
854 * @ctx: audit_context (may be NULL)
855 * @gfp_mask: type of allocation
856 * @type: audit message type
857 *
858 * Returns audit_buffer pointer on success or NULL on error.
859 *
860 * Obtain an audit buffer. This routine does locking to obtain the
861 * audit buffer, but then no locking is required for calls to
862 * audit_log_*format. If the task (ctx) is a task that is currently in a
863 * syscall, then the syscall is marked as auditable and an audit record
864 * will be written at syscall exit. If there is no associated task, then
865 * task context (ctx) should be NULL.
866 */
9796fdd8 867struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask,
9ad9ad38 868 int type)
1da177e4
LT
869{
870 struct audit_buffer *ab = NULL;
1da177e4 871 struct timespec t;
d812ddbb 872 unsigned int serial;
9ad9ad38 873 int reserve;
ac4cec44 874 unsigned long timeout_start = jiffies;
1da177e4
LT
875
876 if (!audit_initialized)
877 return NULL;
878
c8edc80c
DK
879 if (unlikely(audit_filter_type(type)))
880 return NULL;
881
9ad9ad38
DW
882 if (gfp_mask & __GFP_WAIT)
883 reserve = 0;
884 else
885 reserve = 5; /* Allow atomic callers to go up to five
886 entries over the normal backlog limit */
887
888 while (audit_backlog_limit
889 && skb_queue_len(&audit_skb_queue) > audit_backlog_limit + reserve) {
ac4cec44
DW
890 if (gfp_mask & __GFP_WAIT && audit_backlog_wait_time
891 && time_before(jiffies, timeout_start + audit_backlog_wait_time)) {
892
9ad9ad38
DW
893 /* Wait for auditd to drain the queue a little */
894 DECLARE_WAITQUEUE(wait, current);
895 set_current_state(TASK_INTERRUPTIBLE);
896 add_wait_queue(&audit_backlog_wait, &wait);
897
898 if (audit_backlog_limit &&
899 skb_queue_len(&audit_skb_queue) > audit_backlog_limit)
ac4cec44 900 schedule_timeout(timeout_start + audit_backlog_wait_time - jiffies);
9ad9ad38
DW
901
902 __set_current_state(TASK_RUNNING);
903 remove_wait_queue(&audit_backlog_wait, &wait);
ac4cec44 904 continue;
9ad9ad38 905 }
fb19b4c6
DW
906 if (audit_rate_check())
907 printk(KERN_WARNING
908 "audit: audit_backlog=%d > "
909 "audit_backlog_limit=%d\n",
910 skb_queue_len(&audit_skb_queue),
911 audit_backlog_limit);
912 audit_log_lost("backlog limit exceeded");
ac4cec44
DW
913 audit_backlog_wait_time = audit_backlog_wait_overflow;
914 wake_up(&audit_backlog_wait);
fb19b4c6
DW
915 return NULL;
916 }
917
9ad9ad38 918 ab = audit_buffer_alloc(ctx, gfp_mask, type);
1da177e4
LT
919 if (!ab) {
920 audit_log_lost("out of memory in audit_log_start");
921 return NULL;
922 }
923
bfb4496e 924 audit_get_stamp(ab->ctx, &t, &serial);
197c69c6 925
1da177e4
LT
926 audit_log_format(ab, "audit(%lu.%03lu:%u): ",
927 t.tv_sec, t.tv_nsec/1000000, serial);
928 return ab;
929}
930
8fc6115c 931/**
5ac52f33 932 * audit_expand - expand skb in the audit buffer
8fc6115c 933 * @ab: audit_buffer
b0dd25a8 934 * @extra: space to add at tail of the skb
8fc6115c
CW
935 *
936 * Returns 0 (no space) on failed expansion, or available space if
937 * successful.
938 */
e3b926b4 939static inline int audit_expand(struct audit_buffer *ab, int extra)
8fc6115c 940{
5ac52f33 941 struct sk_buff *skb = ab->skb;
e3b926b4 942 int ret = pskb_expand_head(skb, skb_headroom(skb), extra,
9ad9ad38 943 ab->gfp_mask);
5ac52f33
CW
944 if (ret < 0) {
945 audit_log_lost("out of memory in audit_expand");
8fc6115c 946 return 0;
5ac52f33
CW
947 }
948 return skb_tailroom(skb);
8fc6115c 949}
1da177e4 950
b0dd25a8
RD
951/*
952 * Format an audit message into the audit buffer. If there isn't enough
1da177e4
LT
953 * room in the audit buffer, more room will be allocated and vsnprint
954 * will be called a second time. Currently, we assume that a printk
b0dd25a8
RD
955 * can't format message larger than 1024 bytes, so we don't either.
956 */
1da177e4
LT
957static void audit_log_vformat(struct audit_buffer *ab, const char *fmt,
958 va_list args)
959{
960 int len, avail;
5ac52f33 961 struct sk_buff *skb;
eecb0a73 962 va_list args2;
1da177e4
LT
963
964 if (!ab)
965 return;
966
5ac52f33
CW
967 BUG_ON(!ab->skb);
968 skb = ab->skb;
969 avail = skb_tailroom(skb);
970 if (avail == 0) {
e3b926b4 971 avail = audit_expand(ab, AUDIT_BUFSIZ);
8fc6115c
CW
972 if (!avail)
973 goto out;
1da177e4 974 }
eecb0a73 975 va_copy(args2, args);
5ac52f33 976 len = vsnprintf(skb->tail, avail, fmt, args);
1da177e4
LT
977 if (len >= avail) {
978 /* The printk buffer is 1024 bytes long, so if we get
979 * here and AUDIT_BUFSIZ is at least 1024, then we can
980 * log everything that printk could have logged. */
b0dd25a8
RD
981 avail = audit_expand(ab,
982 max_t(unsigned, AUDIT_BUFSIZ, 1+len-avail));
8fc6115c
CW
983 if (!avail)
984 goto out;
eecb0a73 985 len = vsnprintf(skb->tail, avail, fmt, args2);
1da177e4 986 }
168b7173
SG
987 if (len > 0)
988 skb_put(skb, len);
8fc6115c
CW
989out:
990 return;
1da177e4
LT
991}
992
b0dd25a8
RD
993/**
994 * audit_log_format - format a message into the audit buffer.
995 * @ab: audit_buffer
996 * @fmt: format string
997 * @...: optional parameters matching @fmt string
998 *
999 * All the work is done in audit_log_vformat.
1000 */
1da177e4
LT
1001void audit_log_format(struct audit_buffer *ab, const char *fmt, ...)
1002{
1003 va_list args;
1004
1005 if (!ab)
1006 return;
1007 va_start(args, fmt);
1008 audit_log_vformat(ab, fmt, args);
1009 va_end(args);
1010}
1011
b0dd25a8
RD
1012/**
1013 * audit_log_hex - convert a buffer to hex and append it to the audit skb
1014 * @ab: the audit_buffer
1015 * @buf: buffer to convert to hex
1016 * @len: length of @buf to be converted
1017 *
1018 * No return value; failure to expand is silently ignored.
1019 *
1020 * This function will take the passed buf and convert it into a string of
1021 * ascii hex digits. The new string is placed onto the skb.
1022 */
1023void audit_log_hex(struct audit_buffer *ab, const unsigned char *buf,
168b7173 1024 size_t len)
83c7d091 1025{
168b7173
SG
1026 int i, avail, new_len;
1027 unsigned char *ptr;
1028 struct sk_buff *skb;
1029 static const unsigned char *hex = "0123456789ABCDEF";
1030
1031 BUG_ON(!ab->skb);
1032 skb = ab->skb;
1033 avail = skb_tailroom(skb);
1034 new_len = len<<1;
1035 if (new_len >= avail) {
1036 /* Round the buffer request up to the next multiple */
1037 new_len = AUDIT_BUFSIZ*(((new_len-avail)/AUDIT_BUFSIZ) + 1);
1038 avail = audit_expand(ab, new_len);
1039 if (!avail)
1040 return;
1041 }
83c7d091 1042
168b7173
SG
1043 ptr = skb->tail;
1044 for (i=0; i<len; i++) {
1045 *ptr++ = hex[(buf[i] & 0xF0)>>4]; /* Upper nibble */
1046 *ptr++ = hex[buf[i] & 0x0F]; /* Lower nibble */
1047 }
1048 *ptr = 0;
1049 skb_put(skb, len << 1); /* new string is twice the old string */
83c7d091
DW
1050}
1051
9c937dcc
AG
1052/*
1053 * Format a string of no more than slen characters into the audit buffer,
1054 * enclosed in quote marks.
1055 */
1056static void audit_log_n_string(struct audit_buffer *ab, size_t slen,
1057 const char *string)
1058{
1059 int avail, new_len;
1060 unsigned char *ptr;
1061 struct sk_buff *skb;
1062
1063 BUG_ON(!ab->skb);
1064 skb = ab->skb;
1065 avail = skb_tailroom(skb);
1066 new_len = slen + 3; /* enclosing quotes + null terminator */
1067 if (new_len > avail) {
1068 avail = audit_expand(ab, new_len);
1069 if (!avail)
1070 return;
1071 }
1072 ptr = skb->tail;
1073 *ptr++ = '"';
1074 memcpy(ptr, string, slen);
1075 ptr += slen;
1076 *ptr++ = '"';
1077 *ptr = 0;
1078 skb_put(skb, slen + 2); /* don't include null terminator */
1079}
1080
b0dd25a8 1081/**
9c937dcc 1082 * audit_log_n_unstrustedstring - log a string that may contain random characters
b0dd25a8 1083 * @ab: audit_buffer
9c937dcc 1084 * @len: lenth of string (not including trailing null)
b0dd25a8
RD
1085 * @string: string to be logged
1086 *
1087 * This code will escape a string that is passed to it if the string
1088 * contains a control character, unprintable character, double quote mark,
168b7173 1089 * or a space. Unescaped strings will start and end with a double quote mark.
b0dd25a8 1090 * Strings that are escaped are printed in hex (2 digits per char).
9c937dcc
AG
1091 *
1092 * The caller specifies the number of characters in the string to log, which may
1093 * or may not be the entire string.
b0dd25a8 1094 */
9c937dcc
AG
1095const char *audit_log_n_untrustedstring(struct audit_buffer *ab, size_t len,
1096 const char *string)
83c7d091 1097{
81b7854d 1098 const unsigned char *p = string;
83c7d091
DW
1099
1100 while (*p) {
168b7173 1101 if (*p == '"' || *p < 0x21 || *p > 0x7f) {
473ae30b
AV
1102 audit_log_hex(ab, string, len);
1103 return string + len + 1;
83c7d091
DW
1104 }
1105 p++;
1106 }
9c937dcc 1107 audit_log_n_string(ab, len, string);
473ae30b 1108 return p + 1;
83c7d091
DW
1109}
1110
9c937dcc
AG
1111/**
1112 * audit_log_unstrustedstring - log a string that may contain random characters
1113 * @ab: audit_buffer
1114 * @string: string to be logged
1115 *
1116 * Same as audit_log_n_unstrustedstring(), except that strlen is used to
1117 * determine string length.
1118 */
1119const char *audit_log_untrustedstring(struct audit_buffer *ab, const char *string)
1120{
1121 return audit_log_n_untrustedstring(ab, strlen(string), string);
1122}
1123
168b7173 1124/* This is a helper-function to print the escaped d_path */
1da177e4
LT
1125void audit_log_d_path(struct audit_buffer *ab, const char *prefix,
1126 struct dentry *dentry, struct vfsmount *vfsmnt)
1127{
168b7173 1128 char *p, *path;
1da177e4 1129
8fc6115c
CW
1130 if (prefix)
1131 audit_log_format(ab, " %s", prefix);
1da177e4 1132
168b7173 1133 /* We will allow 11 spaces for ' (deleted)' to be appended */
9ad9ad38 1134 path = kmalloc(PATH_MAX+11, ab->gfp_mask);
168b7173
SG
1135 if (!path) {
1136 audit_log_format(ab, "<no memory>");
1137 return;
1da177e4 1138 }
168b7173
SG
1139 p = d_path(dentry, vfsmnt, path, PATH_MAX+11);
1140 if (IS_ERR(p)) { /* Should never happen since we send PATH_MAX */
1141 /* FIXME: can we save some information here? */
1142 audit_log_format(ab, "<too long>");
1143 } else
1144 audit_log_untrustedstring(ab, p);
1145 kfree(path);
1da177e4
LT
1146}
1147
b0dd25a8
RD
1148/**
1149 * audit_log_end - end one audit record
1150 * @ab: the audit_buffer
1151 *
1152 * The netlink_* functions cannot be called inside an irq context, so
1153 * the audit buffer is placed on a queue and a tasklet is scheduled to
1da177e4 1154 * remove them from the queue outside the irq context. May be called in
b0dd25a8
RD
1155 * any context.
1156 */
b7d11258 1157void audit_log_end(struct audit_buffer *ab)
1da177e4 1158{
1da177e4
LT
1159 if (!ab)
1160 return;
1161 if (!audit_rate_check()) {
1162 audit_log_lost("rate limit exceeded");
1163 } else {
b7d11258
DW
1164 if (audit_pid) {
1165 struct nlmsghdr *nlh = (struct nlmsghdr *)ab->skb->data;
1166 nlh->nlmsg_len = ab->skb->len - NLMSG_SPACE(0);
1167 skb_queue_tail(&audit_skb_queue, ab->skb);
1168 ab->skb = NULL;
1169 wake_up_interruptible(&kauditd_wait);
1170 } else {
e1b09eba 1171 printk(KERN_NOTICE "%s\n", ab->skb->data + NLMSG_SPACE(0));
b7d11258 1172 }
1da177e4 1173 }
16e1904e 1174 audit_buffer_free(ab);
1da177e4
LT
1175}
1176
b0dd25a8
RD
1177/**
1178 * audit_log - Log an audit record
1179 * @ctx: audit context
1180 * @gfp_mask: type of allocation
1181 * @type: audit message type
1182 * @fmt: format string to use
1183 * @...: variable parameters matching the format string
1184 *
1185 * This is a convenience function that calls audit_log_start,
1186 * audit_log_vformat, and audit_log_end. It may be called
1187 * in any context.
1188 */
9796fdd8 1189void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
9ad9ad38 1190 const char *fmt, ...)
1da177e4
LT
1191{
1192 struct audit_buffer *ab;
1193 va_list args;
1194
9ad9ad38 1195 ab = audit_log_start(ctx, gfp_mask, type);
1da177e4
LT
1196 if (ab) {
1197 va_start(args, fmt);
1198 audit_log_vformat(ab, fmt, args);
1199 va_end(args);
1200 audit_log_end(ab);
1201 }
1202}
bf45da97 1203
1204EXPORT_SYMBOL(audit_log_start);
1205EXPORT_SYMBOL(audit_log_end);
1206EXPORT_SYMBOL(audit_log_format);
1207EXPORT_SYMBOL(audit_log);