1 /* auditsc.c -- System-call auditing support -*- linux-c -*-
2 * Handles all system-call specific auditing features.
4 * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
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.
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.
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
21 * Written by Rickard E. (Rik) Faith <faith@redhat.com>
23 * Many of the ideas implemented here are from Stephen C. Tweedie,
24 * especially the idea of avoiding a copy by using getname.
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.
32 #include <linux/init.h>
33 #include <asm/atomic.h>
34 #include <asm/types.h>
36 #include <linux/module.h>
38 #include <linux/audit.h>
39 #include <linux/personality.h>
40 #include <linux/time.h>
41 #include <asm/unistd.h>
44 1 = put_count checking
45 2 = verbose put_count checking
49 /* No syscall auditing will take place unless audit_enabled != 0. */
50 extern int audit_enabled;
52 /* AUDIT_NAMES is the number of slots we reserve in the audit_context
53 * for saving names from getname(). */
54 #define AUDIT_NAMES 20
56 /* AUDIT_NAMES_RESERVED is the number of slots we reserve in the
57 * audit_context from being used for nameless inodes from
59 #define AUDIT_NAMES_RESERVED 7
61 /* At task start time, the audit_state is set in the audit_context using
62 a per-task filter. At syscall entry, the audit_state is augmented by
63 the syscall filter. */
65 AUDIT_DISABLED, /* Do not create per-task audit_context.
66 * No syscall-specific audit records can
68 AUDIT_SETUP_CONTEXT, /* Create the per-task audit_context,
69 * but don't necessarily fill it in at
70 * syscall entry time (i.e., filter
72 AUDIT_BUILD_CONTEXT, /* Create the per-task audit_context,
73 * and always fill it in at syscall
74 * entry time. This makes a full
75 * syscall record available if some
76 * other part of the kernel decides it
77 * should be recorded. */
78 AUDIT_RECORD_CONTEXT /* Create the per-task audit_context,
79 * always fill it in at syscall entry
80 * time, and always write out the audit
81 * record at syscall exit time. */
84 /* When fs/namei.c:getname() is called, we store the pointer in name and
85 * we don't let putname() free it (instead we free all of the saved
86 * pointers at syscall exit time).
88 * Further, in fs/namei.c:path_lookup() we store the inode and device. */
99 struct audit_aux_data {
100 struct audit_aux_data *next;
104 #define AUDIT_AUX_IPCPERM 0
106 struct audit_aux_data_ipcctl {
107 struct audit_aux_data d;
109 unsigned long qbytes;
116 /* The per-task audit context. */
117 struct audit_context {
118 int in_syscall; /* 1 if task is in a syscall */
119 enum audit_state state;
120 unsigned int serial; /* serial number for record */
121 struct timespec ctime; /* time of syscall entry */
122 uid_t loginuid; /* login uid (identity) */
123 int major; /* syscall number */
124 unsigned long argv[4]; /* syscall arguments */
125 int return_valid; /* return code is valid */
126 int return_code;/* syscall return code */
127 int auditable; /* 1 if record should be written */
129 struct audit_names names[AUDIT_NAMES];
130 struct audit_context *previous; /* For nested syscalls */
131 struct audit_aux_data *aux;
133 /* Save things to print about task_struct */
135 uid_t uid, euid, suid, fsuid;
136 gid_t gid, egid, sgid, fsgid;
137 unsigned long personality;
146 /* There are three lists of rules -- one to search at task creation
147 * time, one to search at syscall entry time, and another to search at
148 * syscall exit time. */
149 static LIST_HEAD(audit_tsklist);
150 static LIST_HEAD(audit_entlist);
151 static LIST_HEAD(audit_extlist);
154 struct list_head list;
156 struct audit_rule rule;
159 /* Check to see if two rules are identical. It is called from
160 * audit_del_rule during AUDIT_DEL. */
161 static int audit_compare_rule(struct audit_rule *a, struct audit_rule *b)
165 if (a->flags != b->flags)
168 if (a->action != b->action)
171 if (a->field_count != b->field_count)
174 for (i = 0; i < a->field_count; i++) {
175 if (a->fields[i] != b->fields[i]
176 || a->values[i] != b->values[i])
180 for (i = 0; i < AUDIT_BITMASK_SIZE; i++)
181 if (a->mask[i] != b->mask[i])
187 /* Note that audit_add_rule and audit_del_rule are called via
188 * audit_receive() in audit.c, and are protected by
189 * audit_netlink_sem. */
190 static inline int audit_add_rule(struct audit_entry *entry,
191 struct list_head *list)
193 if (entry->rule.flags & AUDIT_PREPEND) {
194 entry->rule.flags &= ~AUDIT_PREPEND;
195 list_add_rcu(&entry->list, list);
197 list_add_tail_rcu(&entry->list, list);
202 static void audit_free_rule(struct rcu_head *head)
204 struct audit_entry *e = container_of(head, struct audit_entry, rcu);
208 /* Note that audit_add_rule and audit_del_rule are called via
209 * audit_receive() in audit.c, and are protected by
210 * audit_netlink_sem. */
211 static inline int audit_del_rule(struct audit_rule *rule,
212 struct list_head *list)
214 struct audit_entry *e;
216 /* Do not use the _rcu iterator here, since this is the only
217 * deletion routine. */
218 list_for_each_entry(e, list, list) {
219 if (!audit_compare_rule(rule, &e->rule)) {
220 list_del_rcu(&e->list);
221 call_rcu(&e->rcu, audit_free_rule);
225 return -EFAULT; /* No matching rule */
229 /* Copy rule from user-space to kernel-space. Called during
231 static int audit_copy_rule(struct audit_rule *d, struct audit_rule *s)
235 if (s->action != AUDIT_NEVER
236 && s->action != AUDIT_POSSIBLE
237 && s->action != AUDIT_ALWAYS)
239 if (s->field_count < 0 || s->field_count > AUDIT_MAX_FIELDS)
243 d->action = s->action;
244 d->field_count = s->field_count;
245 for (i = 0; i < d->field_count; i++) {
246 d->fields[i] = s->fields[i];
247 d->values[i] = s->values[i];
249 for (i = 0; i < AUDIT_BITMASK_SIZE; i++) d->mask[i] = s->mask[i];
253 int audit_receive_filter(int type, int pid, int uid, int seq, void *data)
256 struct audit_entry *entry;
261 /* The *_rcu iterators not needed here because we are
262 always called with audit_netlink_sem held. */
263 list_for_each_entry(entry, &audit_tsklist, list)
264 audit_send_reply(pid, seq, AUDIT_LIST, 0, 1,
265 &entry->rule, sizeof(entry->rule));
266 list_for_each_entry(entry, &audit_entlist, list)
267 audit_send_reply(pid, seq, AUDIT_LIST, 0, 1,
268 &entry->rule, sizeof(entry->rule));
269 list_for_each_entry(entry, &audit_extlist, list)
270 audit_send_reply(pid, seq, AUDIT_LIST, 0, 1,
271 &entry->rule, sizeof(entry->rule));
272 audit_send_reply(pid, seq, AUDIT_LIST, 1, 1, NULL, 0);
275 if (!(entry = kmalloc(sizeof(*entry), GFP_KERNEL)))
277 if (audit_copy_rule(&entry->rule, data)) {
281 flags = entry->rule.flags;
282 if (!err && (flags & AUDIT_PER_TASK))
283 err = audit_add_rule(entry, &audit_tsklist);
284 if (!err && (flags & AUDIT_AT_ENTRY))
285 err = audit_add_rule(entry, &audit_entlist);
286 if (!err && (flags & AUDIT_AT_EXIT))
287 err = audit_add_rule(entry, &audit_extlist);
290 flags =((struct audit_rule *)data)->flags;
291 if (!err && (flags & AUDIT_PER_TASK))
292 err = audit_del_rule(data, &audit_tsklist);
293 if (!err && (flags & AUDIT_AT_ENTRY))
294 err = audit_del_rule(data, &audit_entlist);
295 if (!err && (flags & AUDIT_AT_EXIT))
296 err = audit_del_rule(data, &audit_extlist);
306 /* Compare a task_struct with an audit_rule. Return 1 on match, 0
308 static int audit_filter_rules(struct task_struct *tsk,
309 struct audit_rule *rule,
310 struct audit_context *ctx,
311 enum audit_state *state)
315 for (i = 0; i < rule->field_count; i++) {
316 u32 field = rule->fields[i] & ~AUDIT_NEGATE;
317 u32 value = rule->values[i];
322 result = (tsk->pid == value);
325 result = (tsk->uid == value);
328 result = (tsk->euid == value);
331 result = (tsk->suid == value);
334 result = (tsk->fsuid == value);
337 result = (tsk->gid == value);
340 result = (tsk->egid == value);
343 result = (tsk->sgid == value);
346 result = (tsk->fsgid == value);
349 result = (tsk->personality == value);
353 if (ctx && ctx->return_valid)
354 result = (ctx->return_code == value);
357 if (ctx && ctx->return_valid)
358 result = (ctx->return_code >= 0);
362 for (j = 0; j < ctx->name_count; j++) {
363 if (MAJOR(ctx->names[j].dev)==value) {
372 for (j = 0; j < ctx->name_count; j++) {
373 if (MINOR(ctx->names[j].dev)==value) {
382 for (j = 0; j < ctx->name_count; j++) {
383 if (ctx->names[j].ino == value) {
393 result = (ctx->loginuid == value);
400 result = (ctx->argv[field-AUDIT_ARG0]==value);
404 if (rule->fields[i] & AUDIT_NEGATE)
409 switch (rule->action) {
410 case AUDIT_NEVER: *state = AUDIT_DISABLED; break;
411 case AUDIT_POSSIBLE: *state = AUDIT_BUILD_CONTEXT; break;
412 case AUDIT_ALWAYS: *state = AUDIT_RECORD_CONTEXT; break;
417 /* At process creation time, we can determine if system-call auditing is
418 * completely disabled for this task. Since we only have the task
419 * structure at this point, we can only check uid and gid.
421 static enum audit_state audit_filter_task(struct task_struct *tsk)
423 struct audit_entry *e;
424 enum audit_state state;
427 list_for_each_entry_rcu(e, &audit_tsklist, list) {
428 if (audit_filter_rules(tsk, &e->rule, NULL, &state)) {
434 return AUDIT_BUILD_CONTEXT;
437 /* At syscall entry and exit time, this filter is called if the
438 * audit_state is not low enough that auditing cannot take place, but is
439 * also not high enough that we already know we have to write and audit
440 * record (i.e., the state is AUDIT_SETUP_CONTEXT or AUDIT_BUILD_CONTEXT).
442 static enum audit_state audit_filter_syscall(struct task_struct *tsk,
443 struct audit_context *ctx,
444 struct list_head *list)
446 struct audit_entry *e;
447 enum audit_state state;
448 int word = AUDIT_WORD(ctx->major);
449 int bit = AUDIT_BIT(ctx->major);
452 list_for_each_entry_rcu(e, list, list) {
453 if ((e->rule.mask[word] & bit) == bit
454 && audit_filter_rules(tsk, &e->rule, ctx, &state)) {
460 return AUDIT_BUILD_CONTEXT;
463 /* This should be called with task_lock() held. */
464 static inline struct audit_context *audit_get_context(struct task_struct *tsk,
468 struct audit_context *context = tsk->audit_context;
470 if (likely(!context))
472 context->return_valid = return_valid;
473 context->return_code = return_code;
475 if (context->in_syscall && !context->auditable) {
476 enum audit_state state;
477 state = audit_filter_syscall(tsk, context, &audit_extlist);
478 if (state == AUDIT_RECORD_CONTEXT)
479 context->auditable = 1;
482 context->pid = tsk->pid;
483 context->uid = tsk->uid;
484 context->gid = tsk->gid;
485 context->euid = tsk->euid;
486 context->suid = tsk->suid;
487 context->fsuid = tsk->fsuid;
488 context->egid = tsk->egid;
489 context->sgid = tsk->sgid;
490 context->fsgid = tsk->fsgid;
491 context->personality = tsk->personality;
492 tsk->audit_context = NULL;
496 static inline void audit_free_names(struct audit_context *context)
501 if (context->auditable
502 ||context->put_count + context->ino_count != context->name_count) {
503 printk(KERN_ERR "audit.c:%d(:%d): major=%d in_syscall=%d"
504 " name_count=%d put_count=%d"
505 " ino_count=%d [NOT freeing]\n",
507 context->serial, context->major, context->in_syscall,
508 context->name_count, context->put_count,
510 for (i = 0; i < context->name_count; i++)
511 printk(KERN_ERR "names[%d] = %p = %s\n", i,
512 context->names[i].name,
513 context->names[i].name);
519 context->put_count = 0;
520 context->ino_count = 0;
523 for (i = 0; i < context->name_count; i++)
524 if (context->names[i].name)
525 __putname(context->names[i].name);
526 context->name_count = 0;
529 static inline void audit_free_aux(struct audit_context *context)
531 struct audit_aux_data *aux;
533 while ((aux = context->aux)) {
534 context->aux = aux->next;
539 static inline void audit_zero_context(struct audit_context *context,
540 enum audit_state state)
542 uid_t loginuid = context->loginuid;
544 memset(context, 0, sizeof(*context));
545 context->state = state;
546 context->loginuid = loginuid;
549 static inline struct audit_context *audit_alloc_context(enum audit_state state)
551 struct audit_context *context;
553 if (!(context = kmalloc(sizeof(*context), GFP_KERNEL)))
555 audit_zero_context(context, state);
559 /* Filter on the task information and allocate a per-task audit context
560 * if necessary. Doing so turns on system call auditing for the
561 * specified task. This is called from copy_process, so no lock is
563 int audit_alloc(struct task_struct *tsk)
565 struct audit_context *context;
566 enum audit_state state;
568 if (likely(!audit_enabled))
569 return 0; /* Return if not auditing. */
571 state = audit_filter_task(tsk);
572 if (likely(state == AUDIT_DISABLED))
575 if (!(context = audit_alloc_context(state))) {
576 audit_log_lost("out of memory in audit_alloc");
580 /* Preserve login uid */
581 context->loginuid = -1;
582 if (current->audit_context)
583 context->loginuid = current->audit_context->loginuid;
585 tsk->audit_context = context;
586 set_tsk_thread_flag(tsk, TIF_SYSCALL_AUDIT);
590 static inline void audit_free_context(struct audit_context *context)
592 struct audit_context *previous;
596 previous = context->previous;
597 if (previous || (count && count < 10)) {
599 printk(KERN_ERR "audit(:%d): major=%d name_count=%d:"
600 " freeing multiple contexts (%d)\n",
601 context->serial, context->major,
602 context->name_count, count);
604 audit_free_names(context);
605 audit_free_aux(context);
610 printk(KERN_ERR "audit: freed %d contexts\n", count);
613 static void audit_log_task_info(struct audit_buffer *ab)
615 char name[sizeof(current->comm)];
616 struct mm_struct *mm = current->mm;
617 struct vm_area_struct *vma;
619 get_task_comm(name, current);
620 audit_log_format(ab, " comm=%s", name);
625 down_read(&mm->mmap_sem);
628 if ((vma->vm_flags & VM_EXECUTABLE) &&
630 audit_log_d_path(ab, "exe=",
631 vma->vm_file->f_dentry,
632 vma->vm_file->f_vfsmnt);
637 up_read(&mm->mmap_sem);
640 static void audit_log_exit(struct audit_context *context)
643 struct audit_buffer *ab;
645 ab = audit_log_start(context);
647 return; /* audit_panic has been called */
648 audit_log_format(ab, "syscall=%d", context->major);
649 if (context->personality != PER_LINUX)
650 audit_log_format(ab, " per=%lx", context->personality);
651 if (context->return_valid)
652 audit_log_format(ab, " exit=%d", context->return_code);
654 " a0=%lx a1=%lx a2=%lx a3=%lx items=%d"
655 " pid=%d loginuid=%d uid=%d gid=%d"
656 " euid=%d suid=%d fsuid=%d"
657 " egid=%d sgid=%d fsgid=%d",
667 context->euid, context->suid, context->fsuid,
668 context->egid, context->sgid, context->fsgid);
669 audit_log_task_info(ab);
671 while (context->aux) {
672 struct audit_aux_data *aux;
674 ab = audit_log_start(context);
676 continue; /* audit_panic has been called */
679 context->aux = aux->next;
681 audit_log_format(ab, "auxitem=%d", aux->type);
683 case AUDIT_AUX_IPCPERM: {
684 struct audit_aux_data_ipcctl *axi = (void *)aux;
686 " qbytes=%lx uid=%d gid=%d mode=%x",
687 axi->qbytes, axi->uid, axi->gid, axi->mode);
694 for (i = 0; i < context->name_count; i++) {
695 ab = audit_log_start(context);
697 continue; /* audit_panic has been called */
698 audit_log_format(ab, "item=%d", i);
699 if (context->names[i].name)
700 audit_log_format(ab, " name=%s",
701 context->names[i].name);
702 if (context->names[i].ino != (unsigned long)-1)
703 audit_log_format(ab, " inode=%lu dev=%02x:%02x mode=%#o"
704 " uid=%d gid=%d rdev=%02x:%02x",
705 context->names[i].ino,
706 MAJOR(context->names[i].dev),
707 MINOR(context->names[i].dev),
708 context->names[i].mode,
709 context->names[i].uid,
710 context->names[i].gid,
711 MAJOR(context->names[i].rdev),
712 MINOR(context->names[i].rdev));
717 /* Free a per-task audit context. Called from copy_process and
718 * __put_task_struct. */
719 void audit_free(struct task_struct *tsk)
721 struct audit_context *context;
724 context = audit_get_context(tsk, 0, 0);
727 if (likely(!context))
730 /* Check for system calls that do not go through the exit
731 * function (e.g., exit_group), then free context block. */
732 if (context->in_syscall && context->auditable)
733 audit_log_exit(context);
735 audit_free_context(context);
738 /* Compute a serial number for the audit record. Audit records are
739 * written to user-space as soon as they are generated, so a complete
740 * audit record may be written in several pieces. The timestamp of the
741 * record and this serial number are used by the user-space daemon to
742 * determine which pieces belong to the same audit record. The
743 * (timestamp,serial) tuple is unique for each syscall and is live from
744 * syscall entry to syscall exit.
746 * Atomic values are only guaranteed to be 24-bit, so we count down.
748 * NOTE: Another possibility is to store the formatted records off the
749 * audit context (for those records that have a context), and emit them
750 * all at syscall exit. However, this could delay the reporting of
751 * significant errors until syscall exit (or never, if the system
753 static inline unsigned int audit_serial(void)
755 static atomic_t serial = ATOMIC_INIT(0xffffff);
759 a = atomic_read(&serial);
760 if (atomic_dec_and_test(&serial))
761 atomic_set(&serial, 0xffffff);
762 b = atomic_read(&serial);
763 } while (b != a - 1);
768 /* Fill in audit context at syscall entry. This only happens if the
769 * audit context was created when the task was created and the state or
770 * filters demand the audit context be built. If the state from the
771 * per-task filter or from the per-syscall filter is AUDIT_RECORD_CONTEXT,
772 * then the record will be written at syscall exit time (otherwise, it
773 * will only be written if another part of the kernel requests that it
775 void audit_syscall_entry(struct task_struct *tsk, int major,
776 unsigned long a1, unsigned long a2,
777 unsigned long a3, unsigned long a4)
779 struct audit_context *context = tsk->audit_context;
780 enum audit_state state;
784 /* This happens only on certain architectures that make system
785 * calls in kernel_thread via the entry.S interface, instead of
786 * with direct calls. (If you are porting to a new
787 * architecture, hitting this condition can indicate that you
788 * got the _exit/_leave calls backward in entry.S.)
792 * ppc64 yes (see arch/ppc64/kernel/misc.S)
794 * This also happens with vm86 emulation in a non-nested manner
795 * (entries without exits), so this case must be caught.
797 if (context->in_syscall) {
798 struct audit_context *newctx;
800 #if defined(__NR_vm86) && defined(__NR_vm86old)
801 /* vm86 mode should only be entered once */
802 if (major == __NR_vm86 || major == __NR_vm86old)
807 "audit(:%d) pid=%d in syscall=%d;"
808 " entering syscall=%d\n",
809 context->serial, tsk->pid, context->major, major);
811 newctx = audit_alloc_context(context->state);
813 newctx->previous = context;
815 tsk->audit_context = newctx;
817 /* If we can't alloc a new context, the best we
818 * can do is to leak memory (any pending putname
819 * will be lost). The only other alternative is
820 * to abandon auditing. */
821 audit_zero_context(context, context->state);
824 BUG_ON(context->in_syscall || context->name_count);
829 context->major = major;
830 context->argv[0] = a1;
831 context->argv[1] = a2;
832 context->argv[2] = a3;
833 context->argv[3] = a4;
835 state = context->state;
836 if (state == AUDIT_SETUP_CONTEXT || state == AUDIT_BUILD_CONTEXT)
837 state = audit_filter_syscall(tsk, context, &audit_entlist);
838 if (likely(state == AUDIT_DISABLED))
841 context->serial = audit_serial();
842 context->ctime = CURRENT_TIME;
843 context->in_syscall = 1;
844 context->auditable = !!(state == AUDIT_RECORD_CONTEXT);
847 /* Tear down after system call. If the audit context has been marked as
848 * auditable (either because of the AUDIT_RECORD_CONTEXT state from
849 * filtering, or because some other part of the kernel write an audit
850 * message), then write out the syscall information. In call cases,
851 * free the names stored from getname(). */
852 void audit_syscall_exit(struct task_struct *tsk, int return_code)
854 struct audit_context *context;
856 get_task_struct(tsk);
858 context = audit_get_context(tsk, 1, return_code);
861 /* Not having a context here is ok, since the parent may have
862 * called __put_task_struct. */
863 if (likely(!context))
866 if (context->in_syscall && context->auditable)
867 audit_log_exit(context);
869 context->in_syscall = 0;
870 context->auditable = 0;
871 if (context->previous) {
872 struct audit_context *new_context = context->previous;
873 context->previous = NULL;
874 audit_free_context(context);
875 tsk->audit_context = new_context;
877 audit_free_names(context);
878 audit_free_aux(context);
879 audit_zero_context(context, context->state);
880 tsk->audit_context = context;
882 put_task_struct(tsk);
885 /* Add a name to the list. Called from fs/namei.c:getname(). */
886 void audit_getname(const char *name)
888 struct audit_context *context = current->audit_context;
890 if (!context || IS_ERR(name) || !name)
893 if (!context->in_syscall) {
895 printk(KERN_ERR "%s:%d(:%d): ignoring getname(%p)\n",
896 __FILE__, __LINE__, context->serial, name);
901 BUG_ON(context->name_count >= AUDIT_NAMES);
902 context->names[context->name_count].name = name;
903 context->names[context->name_count].ino = (unsigned long)-1;
904 ++context->name_count;
907 /* Intercept a putname request. Called from
908 * include/linux/fs.h:putname(). If we have stored the name from
909 * getname in the audit context, then we delay the putname until syscall
911 void audit_putname(const char *name)
913 struct audit_context *context = current->audit_context;
916 if (!context->in_syscall) {
918 printk(KERN_ERR "%s:%d(:%d): __putname(%p)\n",
919 __FILE__, __LINE__, context->serial, name);
920 if (context->name_count) {
922 for (i = 0; i < context->name_count; i++)
923 printk(KERN_ERR "name[%d] = %p = %s\n", i,
924 context->names[i].name,
925 context->names[i].name);
932 ++context->put_count;
933 if (context->put_count > context->name_count) {
934 printk(KERN_ERR "%s:%d(:%d): major=%d"
935 " in_syscall=%d putname(%p) name_count=%d"
938 context->serial, context->major,
939 context->in_syscall, name, context->name_count,
947 /* Store the inode and device from a lookup. Called from
948 * fs/namei.c:path_lookup(). */
949 void audit_inode(const char *name, const struct inode *inode)
952 struct audit_context *context = current->audit_context;
954 if (!context->in_syscall)
956 if (context->name_count
957 && context->names[context->name_count-1].name
958 && context->names[context->name_count-1].name == name)
959 idx = context->name_count - 1;
960 else if (context->name_count > 1
961 && context->names[context->name_count-2].name
962 && context->names[context->name_count-2].name == name)
963 idx = context->name_count - 2;
965 /* FIXME: how much do we care about inodes that have no
966 * associated name? */
967 if (context->name_count >= AUDIT_NAMES - AUDIT_NAMES_RESERVED)
969 idx = context->name_count++;
970 context->names[idx].name = NULL;
972 ++context->ino_count;
975 context->names[idx].ino = inode->i_ino;
976 context->names[idx].dev = inode->i_sb->s_dev;
977 context->names[idx].mode = inode->i_mode;
978 context->names[idx].uid = inode->i_uid;
979 context->names[idx].gid = inode->i_gid;
980 context->names[idx].rdev = inode->i_rdev;
983 void audit_get_stamp(struct audit_context *ctx,
984 struct timespec *t, int *serial)
987 t->tv_sec = ctx->ctime.tv_sec;
988 t->tv_nsec = ctx->ctime.tv_nsec;
989 *serial = ctx->serial;
997 extern int audit_set_type(struct audit_buffer *ab, int type);
999 int audit_set_loginuid(struct audit_context *ctx, uid_t loginuid)
1002 struct audit_buffer *ab;
1004 ab = audit_log_start(NULL);
1006 audit_log_format(ab, "login pid=%d uid=%u "
1007 "old loginuid=%u new loginuid=%u",
1008 ctx->pid, ctx->uid, ctx->loginuid, loginuid);
1009 audit_set_type(ab, AUDIT_LOGIN);
1012 ctx->loginuid = loginuid;
1017 uid_t audit_get_loginuid(struct audit_context *ctx)
1019 return ctx ? ctx->loginuid : -1;
1022 int audit_ipc_perms(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode)
1024 struct audit_aux_data_ipcctl *ax;
1025 struct audit_context *context = current->audit_context;
1027 if (likely(!context))
1030 ax = kmalloc(sizeof(*ax), GFP_KERNEL);
1034 ax->qbytes = qbytes;
1039 ax->d.type = AUDIT_AUX_IPCPERM;
1040 ax->d.next = context->aux;
1041 context->aux = (void *)ax;