[PATCH] get rid of AVC_PATH postponed treatment

Selinux folks had been complaining about the lack of AVC_PATH
records when audit is disabled. I must admit my stupidity - I assumed
that avc_audit() really couldn't use audit_log_d_path() because of
deadlocks (== could be called with dcache_lock or vfsmount_lock held).
Shouldn't have made that assumption - it never gets called that way.
It _is_ called under spinlocks, but not those.

Since audit_log_d_path() uses ab->gfp_mask for allocations,
kmalloc() in there is not a problem. IOW, the simple fix is sufficient:
let's rip AUDIT_AVC_PATH out and simply generate pathname as part of main
record. It's trivial to do.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Acked-by: James Morris <jmorris@namei.org>

Al Viro 4259fa01 74f2345b

+8 -56
-2
include/linux/audit.h
··· 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; })
··· 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_set_macxattr(const char *name); 415 extern int __audit_mq_open(int oflag, mode_t mode, struct mq_attr __user *u_attr); 416 extern int __audit_mq_timedsend(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec __user *u_abs_timeout); ··· 491 #define audit_socketcall(n,a) ({ 0; }) 492 #define audit_fd_pair(n,a) ({ 0; }) 493 #define audit_sockaddr(len, addr) ({ 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; })
-47
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 } ··· 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 } ··· 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)