blob: cb8a44945157889951ad1df68198bbcdf80d8d32 [file] [log] [blame]
85c87212005-04-29 16:23:29 +01001/* auditsc.c -- System-call auditing support
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Handles all system-call specific auditing features.
3 *
4 * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
5 * All Rights Reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Written by Rickard E. (Rik) Faith <faith@redhat.com>
22 *
23 * Many of the ideas implemented here are from Stephen C. Tweedie,
24 * especially the idea of avoiding a copy by using getname.
25 *
26 * The method for actual interception of syscall entry and exit (not in
27 * this file -- see entry.S) is based on a GPL'd patch written by
28 * okir@suse.de and Copyright 2003 SuSE Linux AG.
29 *
30 */
31
32#include <linux/init.h>
33#include <asm/atomic.h>
34#include <asm/types.h>
35#include <linux/mm.h>
36#include <linux/module.h>
Stephen Smalley01116102005-05-21 00:15:52 +010037#include <linux/mount.h>
David Woodhouse3ec3b2f2005-05-17 12:08:48 +010038#include <linux/socket.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/audit.h>
40#include <linux/personality.h>
41#include <linux/time.h>
David Woodhousef6a789d2005-06-21 16:22:01 +010042#include <linux/kthread.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <asm/unistd.h>
44
45/* 0 = no checking
46 1 = put_count checking
47 2 = verbose put_count checking
48*/
49#define AUDIT_DEBUG 0
50
51/* No syscall auditing will take place unless audit_enabled != 0. */
52extern int audit_enabled;
53
54/* AUDIT_NAMES is the number of slots we reserve in the audit_context
55 * for saving names from getname(). */
56#define AUDIT_NAMES 20
57
58/* AUDIT_NAMES_RESERVED is the number of slots we reserve in the
59 * audit_context from being used for nameless inodes from
60 * path_lookup. */
61#define AUDIT_NAMES_RESERVED 7
62
63/* At task start time, the audit_state is set in the audit_context using
64 a per-task filter. At syscall entry, the audit_state is augmented by
65 the syscall filter. */
66enum audit_state {
67 AUDIT_DISABLED, /* Do not create per-task audit_context.
68 * No syscall-specific audit records can
69 * be generated. */
70 AUDIT_SETUP_CONTEXT, /* Create the per-task audit_context,
71 * but don't necessarily fill it in at
72 * syscall entry time (i.e., filter
73 * instead). */
74 AUDIT_BUILD_CONTEXT, /* Create the per-task audit_context,
75 * and always fill it in at syscall
76 * entry time. This makes a full
77 * syscall record available if some
78 * other part of the kernel decides it
79 * should be recorded. */
80 AUDIT_RECORD_CONTEXT /* Create the per-task audit_context,
81 * always fill it in at syscall entry
82 * time, and always write out the audit
83 * record at syscall exit time. */
84};
85
86/* When fs/namei.c:getname() is called, we store the pointer in name and
87 * we don't let putname() free it (instead we free all of the saved
88 * pointers at syscall exit time).
89 *
90 * Further, in fs/namei.c:path_lookup() we store the inode and device. */
91struct audit_names {
92 const char *name;
93 unsigned long ino;
94 dev_t dev;
95 umode_t mode;
96 uid_t uid;
97 gid_t gid;
98 dev_t rdev;
David Woodhouseae7b9612005-06-20 16:11:05 +010099 unsigned flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100};
101
102struct audit_aux_data {
103 struct audit_aux_data *next;
104 int type;
105};
106
107#define AUDIT_AUX_IPCPERM 0
108
109struct audit_aux_data_ipcctl {
110 struct audit_aux_data d;
111 struct ipc_perm p;
112 unsigned long qbytes;
113 uid_t uid;
114 gid_t gid;
115 mode_t mode;
116};
117
David Woodhouse3ec3b2f2005-05-17 12:08:48 +0100118struct audit_aux_data_socketcall {
119 struct audit_aux_data d;
120 int nargs;
121 unsigned long args[0];
122};
123
124struct audit_aux_data_sockaddr {
125 struct audit_aux_data d;
126 int len;
127 char a[0];
128};
129
Stephen Smalley01116102005-05-21 00:15:52 +0100130struct audit_aux_data_path {
131 struct audit_aux_data d;
132 struct dentry *dentry;
133 struct vfsmount *mnt;
134};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136/* The per-task audit context. */
137struct audit_context {
138 int in_syscall; /* 1 if task is in a syscall */
139 enum audit_state state;
140 unsigned int serial; /* serial number for record */
141 struct timespec ctime; /* time of syscall entry */
142 uid_t loginuid; /* login uid (identity) */
143 int major; /* syscall number */
144 unsigned long argv[4]; /* syscall arguments */
145 int return_valid; /* return code is valid */
2fd6f582005-04-29 16:08:28 +0100146 long return_code;/* syscall return code */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 int auditable; /* 1 if record should be written */
148 int name_count;
149 struct audit_names names[AUDIT_NAMES];
David Woodhouse8f37d472005-05-27 12:17:28 +0100150 struct dentry * pwd;
151 struct vfsmount * pwdmnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 struct audit_context *previous; /* For nested syscalls */
153 struct audit_aux_data *aux;
154
155 /* Save things to print about task_struct */
156 pid_t pid;
157 uid_t uid, euid, suid, fsuid;
158 gid_t gid, egid, sgid, fsgid;
159 unsigned long personality;
2fd6f582005-04-29 16:08:28 +0100160 int arch;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162#if AUDIT_DEBUG
163 int put_count;
164 int ino_count;
165#endif
166};
167
168 /* Public API */
169/* There are three lists of rules -- one to search at task creation
170 * time, one to search at syscall entry time, and another to search at
171 * syscall exit time. */
David Woodhouse0f45aa12005-06-19 19:35:50 +0100172static struct list_head audit_filter_list[AUDIT_NR_FILTERS] = {
173 LIST_HEAD_INIT(audit_filter_list[0]),
174 LIST_HEAD_INIT(audit_filter_list[1]),
175 LIST_HEAD_INIT(audit_filter_list[2]),
176 LIST_HEAD_INIT(audit_filter_list[3]),
177 LIST_HEAD_INIT(audit_filter_list[4]),
178#if AUDIT_NR_FILTERS != 5
179#error Fix audit_filter_list initialiser
180#endif
181};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183struct audit_entry {
184 struct list_head list;
185 struct rcu_head rcu;
186 struct audit_rule rule;
187};
188
David Woodhouse7ca00262005-05-19 11:23:13 +0100189extern int audit_pid;
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191/* Check to see if two rules are identical. It is called from
192 * audit_del_rule during AUDIT_DEL. */
193static int audit_compare_rule(struct audit_rule *a, struct audit_rule *b)
194{
195 int i;
196
197 if (a->flags != b->flags)
198 return 1;
199
200 if (a->action != b->action)
201 return 1;
202
203 if (a->field_count != b->field_count)
204 return 1;
205
206 for (i = 0; i < a->field_count; i++) {
207 if (a->fields[i] != b->fields[i]
208 || a->values[i] != b->values[i])
209 return 1;
210 }
211
212 for (i = 0; i < AUDIT_BITMASK_SIZE; i++)
213 if (a->mask[i] != b->mask[i])
214 return 1;
215
216 return 0;
217}
218
219/* Note that audit_add_rule and audit_del_rule are called via
220 * audit_receive() in audit.c, and are protected by
221 * audit_netlink_sem. */
David Woodhouse0f45aa12005-06-19 19:35:50 +0100222static inline void audit_add_rule(struct audit_entry *entry,
223 struct list_head *list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
David Woodhouse0f45aa12005-06-19 19:35:50 +0100225 if (entry->rule.flags & AUDIT_FILTER_PREPEND) {
226 entry->rule.flags &= ~AUDIT_FILTER_PREPEND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 list_add_rcu(&entry->list, list);
228 } else {
229 list_add_tail_rcu(&entry->list, list);
230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
233static void audit_free_rule(struct rcu_head *head)
234{
235 struct audit_entry *e = container_of(head, struct audit_entry, rcu);
236 kfree(e);
237}
238
239/* Note that audit_add_rule and audit_del_rule are called via
240 * audit_receive() in audit.c, and are protected by
241 * audit_netlink_sem. */
242static inline int audit_del_rule(struct audit_rule *rule,
243 struct list_head *list)
244{
245 struct audit_entry *e;
246
247 /* Do not use the _rcu iterator here, since this is the only
248 * deletion routine. */
249 list_for_each_entry(e, list, list) {
250 if (!audit_compare_rule(rule, &e->rule)) {
251 list_del_rcu(&e->list);
252 call_rcu(&e->rcu, audit_free_rule);
253 return 0;
254 }
255 }
David Woodhouse0f45aa12005-06-19 19:35:50 +0100256 return -ENOENT; /* No matching rule */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257}
258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259/* Copy rule from user-space to kernel-space. Called during
260 * AUDIT_ADD. */
261static int audit_copy_rule(struct audit_rule *d, struct audit_rule *s)
262{
263 int i;
264
265 if (s->action != AUDIT_NEVER
266 && s->action != AUDIT_POSSIBLE
267 && s->action != AUDIT_ALWAYS)
268 return -1;
269 if (s->field_count < 0 || s->field_count > AUDIT_MAX_FIELDS)
270 return -1;
David Woodhouse0f45aa12005-06-19 19:35:50 +0100271 if ((s->flags & ~AUDIT_FILTER_PREPEND) >= AUDIT_NR_FILTERS)
272 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274 d->flags = s->flags;
275 d->action = s->action;
276 d->field_count = s->field_count;
277 for (i = 0; i < d->field_count; i++) {
278 d->fields[i] = s->fields[i];
279 d->values[i] = s->values[i];
280 }
281 for (i = 0; i < AUDIT_BITMASK_SIZE; i++) d->mask[i] = s->mask[i];
282 return 0;
283}
284
David Woodhousef6a789d2005-06-21 16:22:01 +0100285static int audit_list_rules(void *_dest)
286{
287 int pid, seq;
288 int *dest = _dest;
289 struct audit_entry *entry;
290 int i;
291
292 pid = dest[0];
293 seq = dest[1];
294 kfree(dest);
295
296 down(&audit_netlink_sem);
297
298 /* The *_rcu iterators not needed here because we are
299 always called with audit_netlink_sem held. */
300 for (i=0; i<AUDIT_NR_FILTERS; i++) {
301 list_for_each_entry(entry, &audit_filter_list[i], list)
302 audit_send_reply(pid, seq, AUDIT_LIST, 0, 1,
303 &entry->rule, sizeof(entry->rule));
304 }
305 audit_send_reply(pid, seq, AUDIT_LIST, 1, 1, NULL, 0);
306
307 up(&audit_netlink_sem);
308 return 0;
309}
310
Serge Hallync94c2572005-04-29 16:27:17 +0100311int audit_receive_filter(int type, int pid, int uid, int seq, void *data,
312 uid_t loginuid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 struct audit_entry *entry;
David Woodhousef6a789d2005-06-21 16:22:01 +0100315 struct task_struct *tsk;
316 int *dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 int err = 0;
David Woodhouse0f45aa12005-06-19 19:35:50 +0100318 unsigned listnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 switch (type) {
321 case AUDIT_LIST:
David Woodhousef6a789d2005-06-21 16:22:01 +0100322 /* We can't just spew out the rules here because we might fill
323 * the available socket buffer space and deadlock waiting for
324 * auditctl to read from it... which isn't ever going to
325 * happen if we're actually running in the context of auditctl
326 * trying to _send_ the stuff */
327
328 dest = kmalloc(2 * sizeof(int), GFP_KERNEL);
329 if (!dest)
330 return -ENOMEM;
331 dest[0] = pid;
332 dest[1] = seq;
333
334 tsk = kthread_run(audit_list_rules, dest, "audit_list_rules");
335 if (IS_ERR(tsk)) {
336 kfree(dest);
337 err = PTR_ERR(tsk);
David Woodhouse0f45aa12005-06-19 19:35:50 +0100338 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 break;
340 case AUDIT_ADD:
341 if (!(entry = kmalloc(sizeof(*entry), GFP_KERNEL)))
342 return -ENOMEM;
343 if (audit_copy_rule(&entry->rule, data)) {
344 kfree(entry);
345 return -EINVAL;
346 }
David Woodhouse0f45aa12005-06-19 19:35:50 +0100347 listnr = entry->rule.flags & ~AUDIT_FILTER_PREPEND;
348 audit_add_rule(entry, &audit_filter_list[listnr]);
Steve Grubbc0404992005-05-13 18:17:42 +0100349 audit_log(NULL, AUDIT_CONFIG_CHANGE,
David Woodhousebccf6ae2005-05-23 21:35:28 +0100350 "auid=%u added an audit rule\n", loginuid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 break;
352 case AUDIT_DEL:
David Woodhouse0f45aa12005-06-19 19:35:50 +0100353 listnr =((struct audit_rule *)data)->flags & ~AUDIT_FILTER_PREPEND;
354 if (listnr >= AUDIT_NR_FILTERS)
355 return -EINVAL;
356
357 err = audit_del_rule(data, &audit_filter_list[listnr]);
358 if (!err)
359 audit_log(NULL, AUDIT_CONFIG_CHANGE,
360 "auid=%u removed an audit rule\n", loginuid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 break;
362 default:
363 return -EINVAL;
364 }
365
366 return err;
367}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369/* Compare a task_struct with an audit_rule. Return 1 on match, 0
370 * otherwise. */
371static int audit_filter_rules(struct task_struct *tsk,
372 struct audit_rule *rule,
373 struct audit_context *ctx,
374 enum audit_state *state)
375{
376 int i, j;
377
378 for (i = 0; i < rule->field_count; i++) {
379 u32 field = rule->fields[i] & ~AUDIT_NEGATE;
380 u32 value = rule->values[i];
381 int result = 0;
382
383 switch (field) {
384 case AUDIT_PID:
385 result = (tsk->pid == value);
386 break;
387 case AUDIT_UID:
388 result = (tsk->uid == value);
389 break;
390 case AUDIT_EUID:
391 result = (tsk->euid == value);
392 break;
393 case AUDIT_SUID:
394 result = (tsk->suid == value);
395 break;
396 case AUDIT_FSUID:
397 result = (tsk->fsuid == value);
398 break;
399 case AUDIT_GID:
400 result = (tsk->gid == value);
401 break;
402 case AUDIT_EGID:
403 result = (tsk->egid == value);
404 break;
405 case AUDIT_SGID:
406 result = (tsk->sgid == value);
407 break;
408 case AUDIT_FSGID:
409 result = (tsk->fsgid == value);
410 break;
411 case AUDIT_PERS:
412 result = (tsk->personality == value);
413 break;
2fd6f582005-04-29 16:08:28 +0100414 case AUDIT_ARCH:
415 if (ctx)
416 result = (ctx->arch == value);
417 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419 case AUDIT_EXIT:
420 if (ctx && ctx->return_valid)
421 result = (ctx->return_code == value);
422 break;
423 case AUDIT_SUCCESS:
424 if (ctx && ctx->return_valid)
2fd6f582005-04-29 16:08:28 +0100425 result = (ctx->return_valid == AUDITSC_SUCCESS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 break;
427 case AUDIT_DEVMAJOR:
428 if (ctx) {
429 for (j = 0; j < ctx->name_count; j++) {
430 if (MAJOR(ctx->names[j].dev)==value) {
431 ++result;
432 break;
433 }
434 }
435 }
436 break;
437 case AUDIT_DEVMINOR:
438 if (ctx) {
439 for (j = 0; j < ctx->name_count; j++) {
440 if (MINOR(ctx->names[j].dev)==value) {
441 ++result;
442 break;
443 }
444 }
445 }
446 break;
447 case AUDIT_INODE:
448 if (ctx) {
449 for (j = 0; j < ctx->name_count; j++) {
450 if (ctx->names[j].ino == value) {
451 ++result;
452 break;
453 }
454 }
455 }
456 break;
457 case AUDIT_LOGINUID:
458 result = 0;
459 if (ctx)
460 result = (ctx->loginuid == value);
461 break;
462 case AUDIT_ARG0:
463 case AUDIT_ARG1:
464 case AUDIT_ARG2:
465 case AUDIT_ARG3:
466 if (ctx)
467 result = (ctx->argv[field-AUDIT_ARG0]==value);
468 break;
469 }
470
471 if (rule->fields[i] & AUDIT_NEGATE)
472 result = !result;
473 if (!result)
474 return 0;
475 }
476 switch (rule->action) {
477 case AUDIT_NEVER: *state = AUDIT_DISABLED; break;
478 case AUDIT_POSSIBLE: *state = AUDIT_BUILD_CONTEXT; break;
479 case AUDIT_ALWAYS: *state = AUDIT_RECORD_CONTEXT; break;
480 }
481 return 1;
482}
483
484/* At process creation time, we can determine if system-call auditing is
485 * completely disabled for this task. Since we only have the task
486 * structure at this point, we can only check uid and gid.
487 */
488static enum audit_state audit_filter_task(struct task_struct *tsk)
489{
490 struct audit_entry *e;
491 enum audit_state state;
492
493 rcu_read_lock();
David Woodhouse0f45aa12005-06-19 19:35:50 +0100494 list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_TASK], list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 if (audit_filter_rules(tsk, &e->rule, NULL, &state)) {
496 rcu_read_unlock();
497 return state;
498 }
499 }
500 rcu_read_unlock();
501 return AUDIT_BUILD_CONTEXT;
502}
503
504/* At syscall entry and exit time, this filter is called if the
505 * audit_state is not low enough that auditing cannot take place, but is
Steve Grubb23f32d12005-05-13 18:35:15 +0100506 * also not high enough that we already know we have to write an audit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 * record (i.e., the state is AUDIT_SETUP_CONTEXT or AUDIT_BUILD_CONTEXT).
508 */
509static enum audit_state audit_filter_syscall(struct task_struct *tsk,
510 struct audit_context *ctx,
511 struct list_head *list)
512{
513 struct audit_entry *e;
514 enum audit_state state;
515 int word = AUDIT_WORD(ctx->major);
516 int bit = AUDIT_BIT(ctx->major);
517
David Woodhousef7056d62005-06-20 16:07:33 +0100518 if (audit_pid && ctx->pid == audit_pid)
519 return AUDIT_DISABLED;
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 rcu_read_lock();
522 list_for_each_entry_rcu(e, list, list) {
523 if ((e->rule.mask[word] & bit) == bit
524 && audit_filter_rules(tsk, &e->rule, ctx, &state)) {
525 rcu_read_unlock();
526 return state;
527 }
528 }
529 rcu_read_unlock();
530 return AUDIT_BUILD_CONTEXT;
531}
532
David Woodhouse0f45aa12005-06-19 19:35:50 +0100533int audit_filter_user(struct task_struct *tsk, int type)
534{
535 struct audit_entry *e;
536 enum audit_state state;
537
David Woodhousef7056d62005-06-20 16:07:33 +0100538 if (audit_pid && tsk->pid == audit_pid)
539 return AUDIT_DISABLED;
540
David Woodhouse0f45aa12005-06-19 19:35:50 +0100541 rcu_read_lock();
542 list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_USER], list) {
543 if (audit_filter_rules(tsk, &e->rule, NULL, &state)) {
544 rcu_read_unlock();
545 return state != AUDIT_DISABLED;
546 }
547 }
548 rcu_read_unlock();
549 return 1; /* Audit by default */
550
551}
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553/* This should be called with task_lock() held. */
554static inline struct audit_context *audit_get_context(struct task_struct *tsk,
555 int return_valid,
556 int return_code)
557{
558 struct audit_context *context = tsk->audit_context;
559
560 if (likely(!context))
561 return NULL;
562 context->return_valid = return_valid;
563 context->return_code = return_code;
564
565 if (context->in_syscall && !context->auditable) {
566 enum audit_state state;
David Woodhouse0f45aa12005-06-19 19:35:50 +0100567 state = audit_filter_syscall(tsk, context, &audit_filter_list[AUDIT_FILTER_EXIT]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 if (state == AUDIT_RECORD_CONTEXT)
569 context->auditable = 1;
570 }
571
572 context->pid = tsk->pid;
573 context->uid = tsk->uid;
574 context->gid = tsk->gid;
575 context->euid = tsk->euid;
576 context->suid = tsk->suid;
577 context->fsuid = tsk->fsuid;
578 context->egid = tsk->egid;
579 context->sgid = tsk->sgid;
580 context->fsgid = tsk->fsgid;
581 context->personality = tsk->personality;
582 tsk->audit_context = NULL;
583 return context;
584}
585
586static inline void audit_free_names(struct audit_context *context)
587{
588 int i;
589
590#if AUDIT_DEBUG == 2
591 if (context->auditable
592 ||context->put_count + context->ino_count != context->name_count) {
593 printk(KERN_ERR "audit.c:%d(:%d): major=%d in_syscall=%d"
594 " name_count=%d put_count=%d"
595 " ino_count=%d [NOT freeing]\n",
596 __LINE__,
597 context->serial, context->major, context->in_syscall,
598 context->name_count, context->put_count,
599 context->ino_count);
600 for (i = 0; i < context->name_count; i++)
601 printk(KERN_ERR "names[%d] = %p = %s\n", i,
602 context->names[i].name,
603 context->names[i].name);
604 dump_stack();
605 return;
606 }
607#endif
608#if AUDIT_DEBUG
609 context->put_count = 0;
610 context->ino_count = 0;
611#endif
612
613 for (i = 0; i < context->name_count; i++)
614 if (context->names[i].name)
615 __putname(context->names[i].name);
616 context->name_count = 0;
David Woodhouse8f37d472005-05-27 12:17:28 +0100617 if (context->pwd)
618 dput(context->pwd);
619 if (context->pwdmnt)
620 mntput(context->pwdmnt);
621 context->pwd = NULL;
622 context->pwdmnt = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623}
624
625static inline void audit_free_aux(struct audit_context *context)
626{
627 struct audit_aux_data *aux;
628
629 while ((aux = context->aux)) {
Stephen Smalley01116102005-05-21 00:15:52 +0100630 if (aux->type == AUDIT_AVC_PATH) {
631 struct audit_aux_data_path *axi = (void *)aux;
632 dput(axi->dentry);
633 mntput(axi->mnt);
634 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 context->aux = aux->next;
636 kfree(aux);
637 }
638}
639
640static inline void audit_zero_context(struct audit_context *context,
641 enum audit_state state)
642{
643 uid_t loginuid = context->loginuid;
644
645 memset(context, 0, sizeof(*context));
646 context->state = state;
647 context->loginuid = loginuid;
648}
649
650static inline struct audit_context *audit_alloc_context(enum audit_state state)
651{
652 struct audit_context *context;
653
654 if (!(context = kmalloc(sizeof(*context), GFP_KERNEL)))
655 return NULL;
656 audit_zero_context(context, state);
657 return context;
658}
659
660/* Filter on the task information and allocate a per-task audit context
661 * if necessary. Doing so turns on system call auditing for the
662 * specified task. This is called from copy_process, so no lock is
663 * needed. */
664int audit_alloc(struct task_struct *tsk)
665{
666 struct audit_context *context;
667 enum audit_state state;
668
669 if (likely(!audit_enabled))
670 return 0; /* Return if not auditing. */
671
672 state = audit_filter_task(tsk);
673 if (likely(state == AUDIT_DISABLED))
674 return 0;
675
676 if (!(context = audit_alloc_context(state))) {
677 audit_log_lost("out of memory in audit_alloc");
678 return -ENOMEM;
679 }
680
681 /* Preserve login uid */
682 context->loginuid = -1;
683 if (current->audit_context)
684 context->loginuid = current->audit_context->loginuid;
685
686 tsk->audit_context = context;
687 set_tsk_thread_flag(tsk, TIF_SYSCALL_AUDIT);
688 return 0;
689}
690
691static inline void audit_free_context(struct audit_context *context)
692{
693 struct audit_context *previous;
694 int count = 0;
695
696 do {
697 previous = context->previous;
698 if (previous || (count && count < 10)) {
699 ++count;
700 printk(KERN_ERR "audit(:%d): major=%d name_count=%d:"
701 " freeing multiple contexts (%d)\n",
702 context->serial, context->major,
703 context->name_count, count);
704 }
705 audit_free_names(context);
706 audit_free_aux(context);
707 kfree(context);
708 context = previous;
709 } while (context);
710 if (count >= 10)
711 printk(KERN_ERR "audit: freed %d contexts\n", count);
712}
713
Stephen Smalley219f0812005-04-18 10:47:35 -0700714static void audit_log_task_info(struct audit_buffer *ab)
715{
716 char name[sizeof(current->comm)];
717 struct mm_struct *mm = current->mm;
718 struct vm_area_struct *vma;
719
720 get_task_comm(name, current);
David Woodhouse99e45ee2005-05-23 21:57:41 +0100721 audit_log_format(ab, " comm=");
722 audit_log_untrustedstring(ab, name);
Stephen Smalley219f0812005-04-18 10:47:35 -0700723
724 if (!mm)
725 return;
726
727 down_read(&mm->mmap_sem);
728 vma = mm->mmap;
729 while (vma) {
730 if ((vma->vm_flags & VM_EXECUTABLE) &&
731 vma->vm_file) {
732 audit_log_d_path(ab, "exe=",
733 vma->vm_file->f_dentry,
734 vma->vm_file->f_vfsmnt);
735 break;
736 }
737 vma = vma->vm_next;
738 }
739 up_read(&mm->mmap_sem);
740}
741
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742static void audit_log_exit(struct audit_context *context)
743{
744 int i;
745 struct audit_buffer *ab;
David Woodhouse7551ced2005-05-26 12:04:57 +0100746 struct audit_aux_data *aux;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
Steve Grubbc0404992005-05-13 18:17:42 +0100748 ab = audit_log_start(context, AUDIT_SYSCALL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 if (!ab)
750 return; /* audit_panic has been called */
David Woodhousebccf6ae2005-05-23 21:35:28 +0100751 audit_log_format(ab, "arch=%x syscall=%d",
752 context->arch, context->major);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 if (context->personality != PER_LINUX)
754 audit_log_format(ab, " per=%lx", context->personality);
755 if (context->return_valid)
2fd6f582005-04-29 16:08:28 +0100756 audit_log_format(ab, " success=%s exit=%ld",
757 (context->return_valid==AUDITSC_SUCCESS)?"yes":"no",
758 context->return_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 audit_log_format(ab,
760 " a0=%lx a1=%lx a2=%lx a3=%lx items=%d"
Steve Grubb326e9c82005-05-21 00:22:31 +0100761 " pid=%d auid=%u uid=%u gid=%u"
762 " euid=%u suid=%u fsuid=%u"
763 " egid=%u sgid=%u fsgid=%u",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 context->argv[0],
765 context->argv[1],
766 context->argv[2],
767 context->argv[3],
768 context->name_count,
769 context->pid,
770 context->loginuid,
771 context->uid,
772 context->gid,
773 context->euid, context->suid, context->fsuid,
774 context->egid, context->sgid, context->fsgid);
Stephen Smalley219f0812005-04-18 10:47:35 -0700775 audit_log_task_info(ab);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 audit_log_end(ab);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
David Woodhouse7551ced2005-05-26 12:04:57 +0100778 for (aux = context->aux; aux; aux = aux->next) {
Steve Grubbc0404992005-05-13 18:17:42 +0100779
780 ab = audit_log_start(context, aux->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 if (!ab)
782 continue; /* audit_panic has been called */
783
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 switch (aux->type) {
Steve Grubbc0404992005-05-13 18:17:42 +0100785 case AUDIT_IPC: {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 struct audit_aux_data_ipcctl *axi = (void *)aux;
787 audit_log_format(ab,
Steve Grubb326e9c82005-05-21 00:22:31 +0100788 " qbytes=%lx iuid=%u igid=%u mode=%x",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 axi->qbytes, axi->uid, axi->gid, axi->mode);
David Woodhouse3ec3b2f2005-05-17 12:08:48 +0100790 break; }
791
792 case AUDIT_SOCKETCALL: {
793 int i;
794 struct audit_aux_data_socketcall *axs = (void *)aux;
795 audit_log_format(ab, "nargs=%d", axs->nargs);
796 for (i=0; i<axs->nargs; i++)
797 audit_log_format(ab, " a%d=%lx", i, axs->args[i]);
798 break; }
799
800 case AUDIT_SOCKADDR: {
801 struct audit_aux_data_sockaddr *axs = (void *)aux;
802
803 audit_log_format(ab, "saddr=");
804 audit_log_hex(ab, axs->a, axs->len);
805 break; }
Stephen Smalley01116102005-05-21 00:15:52 +0100806
807 case AUDIT_AVC_PATH: {
808 struct audit_aux_data_path *axi = (void *)aux;
809 audit_log_d_path(ab, "path=", axi->dentry, axi->mnt);
Stephen Smalley01116102005-05-21 00:15:52 +0100810 break; }
811
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 }
813 audit_log_end(ab);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 }
815
David Woodhouse8f37d472005-05-27 12:17:28 +0100816 if (context->pwd && context->pwdmnt) {
817 ab = audit_log_start(context, AUDIT_CWD);
818 if (ab) {
819 audit_log_d_path(ab, "cwd=", context->pwd, context->pwdmnt);
820 audit_log_end(ab);
821 }
822 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 for (i = 0; i < context->name_count; i++) {
Steve Grubbc0404992005-05-13 18:17:42 +0100824 ab = audit_log_start(context, AUDIT_PATH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 if (!ab)
826 continue; /* audit_panic has been called */
David Woodhouse8f37d472005-05-27 12:17:28 +0100827
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 audit_log_format(ab, "item=%d", i);
83c7d092005-04-29 15:54:44 +0100829 if (context->names[i].name) {
830 audit_log_format(ab, " name=");
831 audit_log_untrustedstring(ab, context->names[i].name);
832 }
David Woodhouseae7b9612005-06-20 16:11:05 +0100833 audit_log_format(ab, " flags=%x\n", context->names[i].flags);
834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 if (context->names[i].ino != (unsigned long)-1)
836 audit_log_format(ab, " inode=%lu dev=%02x:%02x mode=%#o"
Steve Grubb326e9c82005-05-21 00:22:31 +0100837 " ouid=%u ogid=%u rdev=%02x:%02x",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 context->names[i].ino,
839 MAJOR(context->names[i].dev),
840 MINOR(context->names[i].dev),
841 context->names[i].mode,
842 context->names[i].uid,
843 context->names[i].gid,
844 MAJOR(context->names[i].rdev),
845 MINOR(context->names[i].rdev));
846 audit_log_end(ab);
847 }
848}
849
850/* Free a per-task audit context. Called from copy_process and
851 * __put_task_struct. */
852void audit_free(struct task_struct *tsk)
853{
854 struct audit_context *context;
855
856 task_lock(tsk);
857 context = audit_get_context(tsk, 0, 0);
858 task_unlock(tsk);
859
860 if (likely(!context))
861 return;
862
863 /* Check for system calls that do not go through the exit
864 * function (e.g., exit_group), then free context block. */
David Woodhousef7056d62005-06-20 16:07:33 +0100865 if (context->in_syscall && context->auditable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 audit_log_exit(context);
867
868 audit_free_context(context);
869}
870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871/* Fill in audit context at syscall entry. This only happens if the
872 * audit context was created when the task was created and the state or
873 * filters demand the audit context be built. If the state from the
874 * per-task filter or from the per-syscall filter is AUDIT_RECORD_CONTEXT,
875 * then the record will be written at syscall exit time (otherwise, it
876 * will only be written if another part of the kernel requests that it
877 * be written). */
2fd6f582005-04-29 16:08:28 +0100878void audit_syscall_entry(struct task_struct *tsk, int arch, int major,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 unsigned long a1, unsigned long a2,
880 unsigned long a3, unsigned long a4)
881{
882 struct audit_context *context = tsk->audit_context;
883 enum audit_state state;
884
885 BUG_ON(!context);
886
887 /* This happens only on certain architectures that make system
888 * calls in kernel_thread via the entry.S interface, instead of
889 * with direct calls. (If you are porting to a new
890 * architecture, hitting this condition can indicate that you
891 * got the _exit/_leave calls backward in entry.S.)
892 *
893 * i386 no
894 * x86_64 no
895 * ppc64 yes (see arch/ppc64/kernel/misc.S)
896 *
897 * This also happens with vm86 emulation in a non-nested manner
898 * (entries without exits), so this case must be caught.
899 */
900 if (context->in_syscall) {
901 struct audit_context *newctx;
902
903#if defined(__NR_vm86) && defined(__NR_vm86old)
904 /* vm86 mode should only be entered once */
905 if (major == __NR_vm86 || major == __NR_vm86old)
906 return;
907#endif
908#if AUDIT_DEBUG
909 printk(KERN_ERR
910 "audit(:%d) pid=%d in syscall=%d;"
911 " entering syscall=%d\n",
912 context->serial, tsk->pid, context->major, major);
913#endif
914 newctx = audit_alloc_context(context->state);
915 if (newctx) {
916 newctx->previous = context;
917 context = newctx;
918 tsk->audit_context = newctx;
919 } else {
920 /* If we can't alloc a new context, the best we
921 * can do is to leak memory (any pending putname
922 * will be lost). The only other alternative is
923 * to abandon auditing. */
924 audit_zero_context(context, context->state);
925 }
926 }
927 BUG_ON(context->in_syscall || context->name_count);
928
929 if (!audit_enabled)
930 return;
931
2fd6f582005-04-29 16:08:28 +0100932 context->arch = arch;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 context->major = major;
934 context->argv[0] = a1;
935 context->argv[1] = a2;
936 context->argv[2] = a3;
937 context->argv[3] = a4;
938
939 state = context->state;
940 if (state == AUDIT_SETUP_CONTEXT || state == AUDIT_BUILD_CONTEXT)
David Woodhouse0f45aa12005-06-19 19:35:50 +0100941 state = audit_filter_syscall(tsk, context, &audit_filter_list[AUDIT_FILTER_ENTRY]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 if (likely(state == AUDIT_DISABLED))
943 return;
944
945 context->serial = audit_serial();
946 context->ctime = CURRENT_TIME;
947 context->in_syscall = 1;
948 context->auditable = !!(state == AUDIT_RECORD_CONTEXT);
949}
950
951/* Tear down after system call. If the audit context has been marked as
952 * auditable (either because of the AUDIT_RECORD_CONTEXT state from
953 * filtering, or because some other part of the kernel write an audit
954 * message), then write out the syscall information. In call cases,
955 * free the names stored from getname(). */
2fd6f582005-04-29 16:08:28 +0100956void audit_syscall_exit(struct task_struct *tsk, int valid, long return_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957{
958 struct audit_context *context;
959
960 get_task_struct(tsk);
961 task_lock(tsk);
2fd6f582005-04-29 16:08:28 +0100962 context = audit_get_context(tsk, valid, return_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 task_unlock(tsk);
964
965 /* Not having a context here is ok, since the parent may have
966 * called __put_task_struct. */
967 if (likely(!context))
968 return;
969
David Woodhousef7056d62005-06-20 16:07:33 +0100970 if (context->in_syscall && context->auditable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 audit_log_exit(context);
972
973 context->in_syscall = 0;
974 context->auditable = 0;
2fd6f582005-04-29 16:08:28 +0100975
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 if (context->previous) {
977 struct audit_context *new_context = context->previous;
978 context->previous = NULL;
979 audit_free_context(context);
980 tsk->audit_context = new_context;
981 } else {
982 audit_free_names(context);
983 audit_free_aux(context);
984 audit_zero_context(context, context->state);
985 tsk->audit_context = context;
986 }
987 put_task_struct(tsk);
988}
989
990/* Add a name to the list. Called from fs/namei.c:getname(). */
991void audit_getname(const char *name)
992{
993 struct audit_context *context = current->audit_context;
994
995 if (!context || IS_ERR(name) || !name)
996 return;
997
998 if (!context->in_syscall) {
999#if AUDIT_DEBUG == 2
1000 printk(KERN_ERR "%s:%d(:%d): ignoring getname(%p)\n",
1001 __FILE__, __LINE__, context->serial, name);
1002 dump_stack();
1003#endif
1004 return;
1005 }
1006 BUG_ON(context->name_count >= AUDIT_NAMES);
1007 context->names[context->name_count].name = name;
1008 context->names[context->name_count].ino = (unsigned long)-1;
1009 ++context->name_count;
David Woodhouse8f37d472005-05-27 12:17:28 +01001010 if (!context->pwd) {
1011 read_lock(&current->fs->lock);
1012 context->pwd = dget(current->fs->pwd);
1013 context->pwdmnt = mntget(current->fs->pwdmnt);
1014 read_unlock(&current->fs->lock);
1015 }
1016
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017}
1018
1019/* Intercept a putname request. Called from
1020 * include/linux/fs.h:putname(). If we have stored the name from
1021 * getname in the audit context, then we delay the putname until syscall
1022 * exit. */
1023void audit_putname(const char *name)
1024{
1025 struct audit_context *context = current->audit_context;
1026
1027 BUG_ON(!context);
1028 if (!context->in_syscall) {
1029#if AUDIT_DEBUG == 2
1030 printk(KERN_ERR "%s:%d(:%d): __putname(%p)\n",
1031 __FILE__, __LINE__, context->serial, name);
1032 if (context->name_count) {
1033 int i;
1034 for (i = 0; i < context->name_count; i++)
1035 printk(KERN_ERR "name[%d] = %p = %s\n", i,
1036 context->names[i].name,
1037 context->names[i].name);
1038 }
1039#endif
1040 __putname(name);
1041 }
1042#if AUDIT_DEBUG
1043 else {
1044 ++context->put_count;
1045 if (context->put_count > context->name_count) {
1046 printk(KERN_ERR "%s:%d(:%d): major=%d"
1047 " in_syscall=%d putname(%p) name_count=%d"
1048 " put_count=%d\n",
1049 __FILE__, __LINE__,
1050 context->serial, context->major,
1051 context->in_syscall, name, context->name_count,
1052 context->put_count);
1053 dump_stack();
1054 }
1055 }
1056#endif
1057}
1058
1059/* Store the inode and device from a lookup. Called from
1060 * fs/namei.c:path_lookup(). */
David Woodhouseae7b9612005-06-20 16:11:05 +01001061void audit_inode(const char *name, const struct inode *inode, unsigned flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062{
1063 int idx;
1064 struct audit_context *context = current->audit_context;
1065
1066 if (!context->in_syscall)
1067 return;
1068 if (context->name_count
1069 && context->names[context->name_count-1].name
1070 && context->names[context->name_count-1].name == name)
1071 idx = context->name_count - 1;
1072 else if (context->name_count > 1
1073 && context->names[context->name_count-2].name
1074 && context->names[context->name_count-2].name == name)
1075 idx = context->name_count - 2;
1076 else {
1077 /* FIXME: how much do we care about inodes that have no
1078 * associated name? */
1079 if (context->name_count >= AUDIT_NAMES - AUDIT_NAMES_RESERVED)
1080 return;
1081 idx = context->name_count++;
1082 context->names[idx].name = NULL;
1083#if AUDIT_DEBUG
1084 ++context->ino_count;
1085#endif
1086 }
David Woodhouseae7b9612005-06-20 16:11:05 +01001087 context->names[idx].flags = flags;
1088 context->names[idx].ino = inode->i_ino;
1089 context->names[idx].dev = inode->i_sb->s_dev;
1090 context->names[idx].mode = inode->i_mode;
1091 context->names[idx].uid = inode->i_uid;
1092 context->names[idx].gid = inode->i_gid;
1093 context->names[idx].rdev = inode->i_rdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094}
1095
David Woodhousebfb44962005-05-21 21:08:09 +01001096void auditsc_get_stamp(struct audit_context *ctx,
1097 struct timespec *t, unsigned int *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
David Woodhousebfb44962005-05-21 21:08:09 +01001099 t->tv_sec = ctx->ctime.tv_sec;
1100 t->tv_nsec = ctx->ctime.tv_nsec;
1101 *serial = ctx->serial;
1102 ctx->auditable = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103}
1104
Steve Grubb456be6c2005-04-29 17:30:07 +01001105int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106{
Steve Grubb456be6c2005-04-29 17:30:07 +01001107 if (task->audit_context) {
Steve Grubbc0404992005-05-13 18:17:42 +01001108 struct audit_buffer *ab;
1109
1110 ab = audit_log_start(NULL, AUDIT_LOGIN);
1111 if (ab) {
1112 audit_log_format(ab, "login pid=%d uid=%u "
Steve Grubb326e9c82005-05-21 00:22:31 +01001113 "old auid=%u new auid=%u",
Steve Grubbc0404992005-05-13 18:17:42 +01001114 task->pid, task->uid,
1115 task->audit_context->loginuid, loginuid);
1116 audit_log_end(ab);
1117 }
Steve Grubb456be6c2005-04-29 17:30:07 +01001118 task->audit_context->loginuid = loginuid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
1120 return 0;
1121}
1122
1123uid_t audit_get_loginuid(struct audit_context *ctx)
1124{
1125 return ctx ? ctx->loginuid : -1;
1126}
1127
1128int audit_ipc_perms(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode)
1129{
1130 struct audit_aux_data_ipcctl *ax;
1131 struct audit_context *context = current->audit_context;
1132
1133 if (likely(!context))
1134 return 0;
1135
1136 ax = kmalloc(sizeof(*ax), GFP_KERNEL);
1137 if (!ax)
1138 return -ENOMEM;
1139
1140 ax->qbytes = qbytes;
1141 ax->uid = uid;
1142 ax->gid = gid;
1143 ax->mode = mode;
1144
Steve Grubbc0404992005-05-13 18:17:42 +01001145 ax->d.type = AUDIT_IPC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 ax->d.next = context->aux;
1147 context->aux = (void *)ax;
1148 return 0;
1149}
Steve Grubbc2f0c7c2005-05-06 12:38:39 +01001150
David Woodhouse3ec3b2f2005-05-17 12:08:48 +01001151int audit_socketcall(int nargs, unsigned long *args)
1152{
1153 struct audit_aux_data_socketcall *ax;
1154 struct audit_context *context = current->audit_context;
1155
1156 if (likely(!context))
1157 return 0;
1158
1159 ax = kmalloc(sizeof(*ax) + nargs * sizeof(unsigned long), GFP_KERNEL);
1160 if (!ax)
1161 return -ENOMEM;
1162
1163 ax->nargs = nargs;
1164 memcpy(ax->args, args, nargs * sizeof(unsigned long));
1165
1166 ax->d.type = AUDIT_SOCKETCALL;
1167 ax->d.next = context->aux;
1168 context->aux = (void *)ax;
1169 return 0;
1170}
1171
1172int audit_sockaddr(int len, void *a)
1173{
1174 struct audit_aux_data_sockaddr *ax;
1175 struct audit_context *context = current->audit_context;
1176
1177 if (likely(!context))
1178 return 0;
1179
1180 ax = kmalloc(sizeof(*ax) + len, GFP_KERNEL);
1181 if (!ax)
1182 return -ENOMEM;
1183
1184 ax->len = len;
1185 memcpy(ax->a, a, len);
1186
1187 ax->d.type = AUDIT_SOCKADDR;
1188 ax->d.next = context->aux;
1189 context->aux = (void *)ax;
1190 return 0;
1191}
1192
Stephen Smalley01116102005-05-21 00:15:52 +01001193int audit_avc_path(struct dentry *dentry, struct vfsmount *mnt)
1194{
1195 struct audit_aux_data_path *ax;
1196 struct audit_context *context = current->audit_context;
1197
1198 if (likely(!context))
1199 return 0;
1200
1201 ax = kmalloc(sizeof(*ax), GFP_ATOMIC);
1202 if (!ax)
1203 return -ENOMEM;
1204
1205 ax->dentry = dget(dentry);
1206 ax->mnt = mntget(mnt);
1207
1208 ax->d.type = AUDIT_AVC_PATH;
1209 ax->d.next = context->aux;
1210 context->aux = (void *)ax;
1211 return 0;
1212}
1213
Steve Grubbc2f0c7c2005-05-06 12:38:39 +01001214void audit_signal_info(int sig, struct task_struct *t)
1215{
1216 extern pid_t audit_sig_pid;
1217 extern uid_t audit_sig_uid;
Steve Grubbc2f0c7c2005-05-06 12:38:39 +01001218
1219 if (unlikely(audit_pid && t->pid == audit_pid)) {
1220 if (sig == SIGTERM || sig == SIGHUP) {
1221 struct audit_context *ctx = current->audit_context;
1222 audit_sig_pid = current->pid;
1223 if (ctx)
1224 audit_sig_uid = ctx->loginuid;
1225 else
1226 audit_sig_uid = current->uid;
1227 }
1228 }
1229}
1230