···2323~0U2424};25252626+int audit_classify_syscall(int abi, unsigned syscall)2727+{2828+ switch(syscall) {2929+ case __NR_open:3030+ return 2;3131+ case __NR_openat:3232+ return 3;3333+ case __NR_socketcall:3434+ return 4;3535+ case __NR_execve:3636+ return 5;3737+ default:3838+ return 0;3939+ }4040+}4141+2642static int __init audit_classes_init(void)2743{2844 audit_register_class(AUDIT_CLASS_WRITE, write_class);
+16
arch/ia64/ia32/audit.c
···1919#include <asm-generic/audit_read.h>2020~0U2121};2222+2323+int ia32_classify_syscall(unsigned syscall)2424+{2525+ switch(syscall) {2626+ case __NR_open:2727+ return 2;2828+ case __NR_openat:2929+ return 3;3030+ case __NR_socketcall:3131+ return 4;3232+ case __NR_execve:3333+ return 5;3434+ default:3535+ return 1;3636+ }3737+}
+19
arch/ia64/kernel/audit.c
···2323~0U2424};25252626+int audit_classify_syscall(int abi, unsigned syscall)2727+{2828+#ifdef CONFIG_IA32_SUPPORT2929+ extern int ia32_classify_syscall(unsigned);3030+ if (abi == AUDIT_ARCH_I386)3131+ return ia32_classify_syscall(syscall);3232+#endif3333+ switch(syscall) {3434+ case __NR_open:3535+ return 2;3636+ case __NR_openat:3737+ return 3;3838+ case __NR_execve:3939+ return 5;4040+ default:4141+ return 0;4242+ }4343+}4444+2645static int __init audit_classes_init(void)2746{2847#ifdef CONFIG_IA32_SUPPORT
+21
arch/powerpc/kernel/audit.c
···2323~0U2424};25252626+int audit_classify_syscall(int abi, unsigned syscall)2727+{2828+#ifdef CONFIG_PPC642929+ extern int ppc32_classify_syscall(unsigned);3030+ if (abi == AUDIT_ARCH_PPC)3131+ return ppc32_classify_syscall(syscall);3232+#endif3333+ switch(syscall) {3434+ case __NR_open:3535+ return 2;3636+ case __NR_openat:3737+ return 3;3838+ case __NR_socketcall:3939+ return 4;4040+ case __NR_execve:4141+ return 5;4242+ default:4343+ return 0;4444+ }4545+}4646+2647static int __init audit_classes_init(void)2748{2849#ifdef CONFIG_PPC64
+16
arch/powerpc/kernel/compat_audit.c
···2020#include <asm-generic/audit_read.h>2121~0U2222};2323+2424+int ppc32_classify_syscall(unsigned syscall)2525+{2626+ switch(syscall) {2727+ case __NR_open:2828+ return 2;2929+ case __NR_openat:3030+ return 3;3131+ case __NR_socketcall:3232+ return 4;3333+ case __NR_execve:3434+ return 5;3535+ default:3636+ return 1;3737+ }3838+}
+21
arch/s390/kernel/audit.c
···2323~0U2424};25252626+int audit_classify_syscall(int abi, unsigned syscall)2727+{2828+#ifdef CONFIG_COMPAT2929+ extern int s390_classify_syscall(unsigned);3030+ if (abi == AUDIT_ARCH_S390)3131+ return s390_classify_syscall(syscall);3232+#endif3333+ switch(syscall) {3434+ case __NR_open:3535+ return 2;3636+ case __NR_openat:3737+ return 3;3838+ case __NR_socketcall:3939+ return 4;4040+ case __NR_execve:4141+ return 5;4242+ default:4343+ return 0;4444+ }4545+}4646+2647static int __init audit_classes_init(void)2748{2849#ifdef CONFIG_COMPAT
+16
arch/s390/kernel/compat_audit.c
···2020#include <asm-generic/audit_read.h>2121~0U2222};2323+2424+int s390_classify_syscall(unsigned syscall)2525+{2626+ switch(syscall) {2727+ case __NR_open:2828+ return 2;2929+ case __NR_openat:3030+ return 3;3131+ case __NR_socketcall:3232+ return 4;3333+ case __NR_execve:3434+ return 5;3535+ default:3636+ return 1;3737+ }3838+}
+16
arch/x86_64/ia32/audit.c
···1919#include <asm-generic/audit_read.h>2020~0U2121};2222+2323+int ia32_classify_syscall(unsigned syscall)2424+{2525+ switch(syscall) {2626+ case __NR_open:2727+ return 2;2828+ case __NR_openat:2929+ return 3;3030+ case __NR_socketcall:3131+ return 4;3232+ case __NR_execve:3333+ return 5;3434+ default:3535+ return 1;3636+ }3737+}
+19
arch/x86_64/kernel/audit.c
···2323~0U2424};25252626+int audit_classify_syscall(int abi, unsigned syscall)2727+{2828+#ifdef CONFIG_IA32_EMULATION2929+ extern int ia32_classify_syscall(unsigned);3030+ if (abi == AUDIT_ARCH_I386)3131+ return ia32_classify_syscall(syscall);3232+#endif3333+ switch(syscall) {3434+ case __NR_open:3535+ return 2;3636+ case __NR_openat:3737+ return 3;3838+ case __NR_execve:3939+ return 5;4040+ default:4141+ return 0;4242+ }4343+}4444+2645static int __init audit_classes_init(void)2746{2847#ifdef CONFIG_IA32_EMULATION
+7
include/linux/audit.h
···181181#define AUDIT_EXIT 103182182#define AUDIT_SUCCESS 104 /* exit >= 0; value ignored */183183#define AUDIT_WATCH 105184184+#define AUDIT_PERM 106184185185186#define AUDIT_ARG0 200186187#define AUDIT_ARG1 (AUDIT_ARG0+1)···257256#define AUDIT_ARCH_V850 (EM_V850|__AUDIT_ARCH_LE)258257#define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)259258259259+#define AUDIT_PERM_EXEC 1260260+#define AUDIT_PERM_WRITE 2261261+#define AUDIT_PERM_READ 4262262+#define AUDIT_PERM_ATTR 8263263+260264struct audit_status {261265 __u32 mask; /* Bit mask for valid entries */262266 __u32 enabled; /* 1 = enabled, 0 = disabled */···324318#define AUDITSC_FAILURE 2325319#define AUDITSC_RESULT(x) ( ((long)(x))<0?AUDITSC_FAILURE:AUDITSC_SUCCESS )326320extern int __init audit_register_class(int class, unsigned *list);321321+extern int audit_classify_syscall(int abi, unsigned syscall);327322#ifdef CONFIG_AUDITSYSCALL328323/* These are defined in auditsc.c */329324 /* Public API */
+1
kernel/audit.h
···104104 return (ino & (AUDIT_INODE_BUCKETS-1));105105}106106107107+extern int audit_match_class(int class, unsigned syscall);107108extern int audit_comparator(const u32 left, const u32 op, const u32 right);108109extern int audit_compare_dname_path(const char *dname, const char *path,109110 int *dirlen);
+17
kernel/auditfilter.c
···302302 return 0;303303}304304305305+int audit_match_class(int class, unsigned syscall)306306+{307307+ if (unlikely(syscall >= AUDIT_BITMASK_SIZE * sizeof(__u32)))308308+ return 0;309309+ if (unlikely(class >= AUDIT_SYSCALL_CLASSES || !classes[class]))310310+ return 0;311311+ return classes[class][AUDIT_WORD(syscall)] & AUDIT_BIT(syscall);312312+}313313+305314/* Common user-space to kernel rule translation. */306315static inline struct audit_entry *audit_to_entry_common(struct audit_rule *rule)307316{···422413 case AUDIT_ARG1:423414 case AUDIT_ARG2:424415 case AUDIT_ARG3:416416+ break;417417+ case AUDIT_PERM:418418+ if (f->val & ~15)419419+ goto exit_free;425420 break;426421 case AUDIT_INODE:427422 err = audit_to_inode(&entry->rule, f);···580567 goto exit_free;581568 entry->rule.buflen += f->val;582569 entry->rule.filterkey = str;570570+ break;571571+ case AUDIT_PERM:572572+ if (f->val & ~15)573573+ goto exit_free;583574 break;584575 default:585576 goto exit_free;
+51
kernel/auditsc.c
···209209#endif210210};211211212212+#define ACC_MODE(x) ("\004\002\006\006"[(x)&O_ACCMODE])213213+static inline int open_arg(int flags, int mask)214214+{215215+ int n = ACC_MODE(flags);216216+ if (flags & (O_TRUNC | O_CREAT))217217+ n |= AUDIT_PERM_WRITE;218218+ return n & mask;219219+}220220+221221+static int audit_match_perm(struct audit_context *ctx, int mask)222222+{223223+ unsigned n = ctx->major;224224+ switch (audit_classify_syscall(ctx->arch, n)) {225225+ case 0: /* native */226226+ if ((mask & AUDIT_PERM_WRITE) &&227227+ audit_match_class(AUDIT_CLASS_WRITE, n))228228+ return 1;229229+ if ((mask & AUDIT_PERM_READ) &&230230+ audit_match_class(AUDIT_CLASS_READ, n))231231+ return 1;232232+ if ((mask & AUDIT_PERM_ATTR) &&233233+ audit_match_class(AUDIT_CLASS_CHATTR, n))234234+ return 1;235235+ return 0;236236+ case 1: /* 32bit on biarch */237237+ if ((mask & AUDIT_PERM_WRITE) &&238238+ audit_match_class(AUDIT_CLASS_WRITE_32, n))239239+ return 1;240240+ if ((mask & AUDIT_PERM_READ) &&241241+ audit_match_class(AUDIT_CLASS_READ_32, n))242242+ return 1;243243+ if ((mask & AUDIT_PERM_ATTR) &&244244+ audit_match_class(AUDIT_CLASS_CHATTR_32, n))245245+ return 1;246246+ return 0;247247+ case 2: /* open */248248+ return mask & ACC_MODE(ctx->argv[1]);249249+ case 3: /* openat */250250+ return mask & ACC_MODE(ctx->argv[2]);251251+ case 4: /* socketcall */252252+ return ((mask & AUDIT_PERM_WRITE) && ctx->argv[0] == SYS_BIND);253253+ case 5: /* execve */254254+ return mask & AUDIT_PERM_EXEC;255255+ default:256256+ return 0;257257+ }258258+}259259+212260/* Determine if any context name data matches a rule's watch data */213261/* Compare a task_struct with an audit_rule. Return 1 on match, 0214262 * otherwise. */···444396 case AUDIT_FILTERKEY:445397 /* ignore this field for filtering */446398 result = 1;399399+ break;400400+ case AUDIT_PERM:401401+ result = audit_match_perm(ctx, f->val);447402 break;448403 }449404