Merge branch 'audit.b39' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/audit-current

* 'audit.b39' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/audit-current:
[PATCH] get rid of AVC_PATH postponed treatment
[PATCH] allow audit filtering on bit & operations
[PATCH] audit: fix broken class-based syscall audit
[PATCH] Make IPC mode consistent

+39 -72
+17 -15
include/linux/audit.h
··· 161 * are currently used in an audit field constant understood by the kernel. 162 * If you are adding a new #define AUDIT_<whatever>, please ensure that 163 * AUDIT_UNUSED_BITS is updated if need be. */ 164 - #define AUDIT_UNUSED_BITS 0x0FFFFC00 165 166 167 /* Rule fields */ ··· 213 #define AUDIT_NEGATE 0x80000000 214 215 /* These are the supported operators. 216 - * 4 2 1 217 - * = > < 218 - * ------- 219 - * 0 0 0 0 nonsense 220 - * 0 0 1 1 < 221 - * 0 1 0 2 > 222 - * 0 1 1 3 != 223 - * 1 0 0 4 = 224 - * 1 0 1 5 <= 225 - * 1 1 0 6 >= 226 - * 1 1 1 7 all operators 227 */ 228 #define AUDIT_LESS_THAN 0x10000000 229 #define AUDIT_GREATER_THAN 0x20000000 230 #define AUDIT_NOT_EQUAL 0x30000000 231 #define AUDIT_EQUAL 0x40000000 232 #define AUDIT_LESS_THAN_OR_EQUAL (AUDIT_LESS_THAN|AUDIT_EQUAL) 233 #define AUDIT_GREATER_THAN_OR_EQUAL (AUDIT_GREATER_THAN|AUDIT_EQUAL) 234 - #define AUDIT_OPERATORS (AUDIT_EQUAL|AUDIT_NOT_EQUAL) 235 236 /* Status symbols */ 237 /* Mask values */ ··· 411 extern int audit_socketcall(int nargs, unsigned long *args); 412 extern int audit_sockaddr(int len, void *addr); 413 extern int __audit_fd_pair(int fd1, int fd2); 414 - extern int audit_avc_path(struct dentry *dentry, struct vfsmount *mnt); 415 extern int audit_set_macxattr(const char *name); 416 extern int __audit_mq_open(int oflag, mode_t mode, struct mq_attr __user *u_attr); 417 extern int __audit_mq_timedsend(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec __user *u_abs_timeout); ··· 490 #define audit_socketcall(n,a) ({ 0; }) 491 #define audit_fd_pair(n,a) ({ 0; }) 492 #define audit_sockaddr(len, addr) ({ 0; }) 493 - #define audit_avc_path(dentry, mnt) ({ 0; }) 494 #define audit_set_macxattr(n) do { ; } while (0) 495 #define audit_mq_open(o,m,a) ({ 0; }) 496 #define audit_mq_timedsend(d,l,p,t) ({ 0; })
··· 161 * are currently used in an audit field constant understood by the kernel. 162 * If you are adding a new #define AUDIT_<whatever>, please ensure that 163 * AUDIT_UNUSED_BITS is updated if need be. */ 164 + #define AUDIT_UNUSED_BITS 0x07FFFC00 165 166 167 /* Rule fields */ ··· 213 #define AUDIT_NEGATE 0x80000000 214 215 /* These are the supported operators. 216 + * 4 2 1 8 217 + * = > < ? 218 + * ---------- 219 + * 0 0 0 0 00 nonsense 220 + * 0 0 0 1 08 & bit mask 221 + * 0 0 1 0 10 < 222 + * 0 1 0 0 20 > 223 + * 0 1 1 0 30 != 224 + * 1 0 0 0 40 = 225 + * 1 0 0 1 48 &= bit test 226 + * 1 0 1 0 50 <= 227 + * 1 1 0 0 60 >= 228 + * 1 1 1 1 78 all operators 229 */ 230 + #define AUDIT_BIT_MASK 0x08000000 231 #define AUDIT_LESS_THAN 0x10000000 232 #define AUDIT_GREATER_THAN 0x20000000 233 #define AUDIT_NOT_EQUAL 0x30000000 234 #define AUDIT_EQUAL 0x40000000 235 + #define AUDIT_BIT_TEST (AUDIT_BIT_MASK|AUDIT_EQUAL) 236 #define AUDIT_LESS_THAN_OR_EQUAL (AUDIT_LESS_THAN|AUDIT_EQUAL) 237 #define AUDIT_GREATER_THAN_OR_EQUAL (AUDIT_GREATER_THAN|AUDIT_EQUAL) 238 + #define AUDIT_OPERATORS (AUDIT_EQUAL|AUDIT_NOT_EQUAL|AUDIT_BIT_MASK) 239 240 /* Status symbols */ 241 /* Mask values */ ··· 407 extern int audit_socketcall(int nargs, unsigned long *args); 408 extern int audit_sockaddr(int len, void *addr); 409 extern int __audit_fd_pair(int fd1, int fd2); 410 extern int audit_set_macxattr(const char *name); 411 extern int __audit_mq_open(int oflag, mode_t mode, struct mq_attr __user *u_attr); 412 extern int __audit_mq_timedsend(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec __user *u_abs_timeout); ··· 487 #define audit_socketcall(n,a) ({ 0; }) 488 #define audit_fd_pair(n,a) ({ 0; }) 489 #define audit_sockaddr(len, addr) ({ 0; }) 490 #define audit_set_macxattr(n) do { ; } while (0) 491 #define audit_mq_open(o,m,a) ({ 0; }) 492 #define audit_mq_timedsend(d,l,p,t) ({ 0; })
+12 -1
kernel/auditfilter.c
··· 304 305 int audit_match_class(int class, unsigned syscall) 306 { 307 - if (unlikely(syscall >= AUDIT_BITMASK_SIZE * sizeof(__u32))) 308 return 0; 309 if (unlikely(class >= AUDIT_SYSCALL_CLASSES || !classes[class])) 310 return 0; ··· 456 case AUDIT_DEVMINOR: 457 case AUDIT_EXIT: 458 case AUDIT_SUCCESS: 459 case AUDIT_ARG0: 460 case AUDIT_ARG1: 461 case AUDIT_ARG2: ··· 1573 return (left > right); 1574 case AUDIT_GREATER_THAN_OR_EQUAL: 1575 return (left >= right); 1576 } 1577 BUG(); 1578 return 0;
··· 304 305 int audit_match_class(int class, unsigned syscall) 306 { 307 + if (unlikely(syscall >= AUDIT_BITMASK_SIZE * 32)) 308 return 0; 309 if (unlikely(class >= AUDIT_SYSCALL_CLASSES || !classes[class])) 310 return 0; ··· 456 case AUDIT_DEVMINOR: 457 case AUDIT_EXIT: 458 case AUDIT_SUCCESS: 459 + /* bit ops are only useful on syscall args */ 460 + if (f->op == AUDIT_BIT_MASK || 461 + f->op == AUDIT_BIT_TEST) { 462 + err = -EINVAL; 463 + goto exit_free; 464 + } 465 + break; 466 case AUDIT_ARG0: 467 case AUDIT_ARG1: 468 case AUDIT_ARG2: ··· 1566 return (left > right); 1567 case AUDIT_GREATER_THAN_OR_EQUAL: 1568 return (left >= right); 1569 + case AUDIT_BIT_MASK: 1570 + return (left & right); 1571 + case AUDIT_BIT_TEST: 1572 + return ((left & right) == right); 1573 } 1574 BUG(); 1575 return 0;
+2 -49
kernel/auditsc.c
··· 173 int fd[2]; 174 }; 175 176 - struct audit_aux_data_path { 177 - struct audit_aux_data d; 178 - struct dentry *dentry; 179 - struct vfsmount *mnt; 180 - }; 181 - 182 struct audit_aux_data_pids { 183 struct audit_aux_data d; 184 pid_t target_pid[AUDIT_AUX_PIDS]; ··· 648 struct audit_aux_data *aux; 649 650 while ((aux = context->aux)) { 651 - if (aux->type == AUDIT_AVC_PATH) { 652 - struct audit_aux_data_path *axi = (void *)aux; 653 - dput(axi->dentry); 654 - mntput(axi->mnt); 655 - } 656 - 657 context->aux = aux->next; 658 kfree(aux); 659 } ··· 983 case AUDIT_IPC: { 984 struct audit_aux_data_ipcctl *axi = (void *)aux; 985 audit_log_format(ab, 986 - "ouid=%u ogid=%u mode=%x", 987 axi->uid, axi->gid, axi->mode); 988 if (axi->osid != 0) { 989 char *ctx = NULL; ··· 1002 case AUDIT_IPC_SET_PERM: { 1003 struct audit_aux_data_ipcctl *axi = (void *)aux; 1004 audit_log_format(ab, 1005 - "qbytes=%lx ouid=%u ogid=%u mode=%x", 1006 axi->qbytes, axi->uid, axi->gid, axi->mode); 1007 break; } 1008 ··· 1024 1025 audit_log_format(ab, "saddr="); 1026 audit_log_hex(ab, axs->a, axs->len); 1027 - break; } 1028 - 1029 - case AUDIT_AVC_PATH: { 1030 - struct audit_aux_data_path *axi = (void *)aux; 1031 - audit_log_d_path(ab, "path=", axi->dentry, axi->mnt); 1032 break; } 1033 1034 case AUDIT_FD_PAIR: { ··· 1971 1972 context->target_pid = t->pid; 1973 selinux_get_task_sid(t, &context->target_sid); 1974 - } 1975 - 1976 - /** 1977 - * audit_avc_path - record the granting or denial of permissions 1978 - * @dentry: dentry to record 1979 - * @mnt: mnt to record 1980 - * 1981 - * Returns 0 for success or NULL context or < 0 on error. 1982 - * 1983 - * Called from security/selinux/avc.c::avc_audit() 1984 - */ 1985 - int audit_avc_path(struct dentry *dentry, struct vfsmount *mnt) 1986 - { 1987 - struct audit_aux_data_path *ax; 1988 - struct audit_context *context = current->audit_context; 1989 - 1990 - if (likely(!context)) 1991 - return 0; 1992 - 1993 - ax = kmalloc(sizeof(*ax), GFP_ATOMIC); 1994 - if (!ax) 1995 - return -ENOMEM; 1996 - 1997 - ax->dentry = dget(dentry); 1998 - ax->mnt = mntget(mnt); 1999 - 2000 - ax->d.type = AUDIT_AVC_PATH; 2001 - ax->d.next = context->aux; 2002 - context->aux = (void *)ax; 2003 - return 0; 2004 } 2005 2006 /**
··· 173 int fd[2]; 174 }; 175 176 struct audit_aux_data_pids { 177 struct audit_aux_data d; 178 pid_t target_pid[AUDIT_AUX_PIDS]; ··· 654 struct audit_aux_data *aux; 655 656 while ((aux = context->aux)) { 657 context->aux = aux->next; 658 kfree(aux); 659 } ··· 995 case AUDIT_IPC: { 996 struct audit_aux_data_ipcctl *axi = (void *)aux; 997 audit_log_format(ab, 998 + "ouid=%u ogid=%u mode=%#o", 999 axi->uid, axi->gid, axi->mode); 1000 if (axi->osid != 0) { 1001 char *ctx = NULL; ··· 1014 case AUDIT_IPC_SET_PERM: { 1015 struct audit_aux_data_ipcctl *axi = (void *)aux; 1016 audit_log_format(ab, 1017 + "qbytes=%lx ouid=%u ogid=%u mode=%#o", 1018 axi->qbytes, axi->uid, axi->gid, axi->mode); 1019 break; } 1020 ··· 1036 1037 audit_log_format(ab, "saddr="); 1038 audit_log_hex(ab, axs->a, axs->len); 1039 break; } 1040 1041 case AUDIT_FD_PAIR: { ··· 1988 1989 context->target_pid = t->pid; 1990 selinux_get_task_sid(t, &context->target_sid); 1991 } 1992 1993 /**
+8 -7
security/selinux/avc.c
··· 570 case AVC_AUDIT_DATA_FS: 571 if (a->u.fs.dentry) { 572 struct dentry *dentry = a->u.fs.dentry; 573 - if (a->u.fs.mnt) 574 - audit_avc_path(dentry, a->u.fs.mnt); 575 - audit_log_format(ab, " name="); 576 - audit_log_untrustedstring(ab, dentry->d_name.name); 577 inode = dentry->d_inode; 578 } else if (a->u.fs.inode) { 579 struct dentry *dentry; ··· 626 case AF_UNIX: 627 u = unix_sk(sk); 628 if (u->dentry) { 629 - audit_avc_path(u->dentry, u->mnt); 630 - audit_log_format(ab, " name="); 631 - audit_log_untrustedstring(ab, u->dentry->d_name.name); 632 break; 633 } 634 if (!u->addr)
··· 570 case AVC_AUDIT_DATA_FS: 571 if (a->u.fs.dentry) { 572 struct dentry *dentry = a->u.fs.dentry; 573 + if (a->u.fs.mnt) { 574 + audit_log_d_path(ab, "path=", dentry, a->u.fs.mnt); 575 + } else { 576 + audit_log_format(ab, " name="); 577 + audit_log_untrustedstring(ab, dentry->d_name.name); 578 + } 579 inode = dentry->d_inode; 580 } else if (a->u.fs.inode) { 581 struct dentry *dentry; ··· 624 case AF_UNIX: 625 u = unix_sk(sk); 626 if (u->dentry) { 627 + audit_log_d_path(ab, "path=", 628 + u->dentry, u->mnt); 629 break; 630 } 631 if (!u->addr)