new helper: audit_file()
authorAl Viro <viro@zeniv.linux.org.uk>
Fri, 31 Oct 2014 21:44:57 +0000 (17:44 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 19 Nov 2014 18:01:26 +0000 (13:01 -0500)
... for situations when we don't have any candidate in pathnames - basically,
in descriptor-based syscalls.

[Folded the build fix for !CONFIG_AUDITSYSCALL configs from Chen Gang]

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/open.c
fs/xattr.c
include/linux/audit.h
ipc/mqueue.c
kernel/auditsc.c

index de92c13..b1bf3d5 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -516,7 +516,7 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
        int err = -EBADF;
 
        if (f.file) {
-               audit_inode(NULL, f.file->f_path.dentry, 0);
+               audit_file(f.file);
                err = chmod_common(&f.file->f_path, mode);
                fdput(f);
        }
@@ -642,7 +642,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
        error = mnt_want_write_file(f.file);
        if (error)
                goto out_fput;
-       audit_inode(NULL, f.file->f_path.dentry, 0);
+       audit_file(f.file);
        error = chown_common(&f.file->f_path, user, group);
        mnt_drop_write_file(f.file);
 out_fput:
index 64e83ef..4ef6985 100644 (file)
@@ -405,16 +405,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
                const void __user *,value, size_t, size, int, flags)
 {
        struct fd f = fdget(fd);
-       struct dentry *dentry;
        int error = -EBADF;
 
        if (!f.file)
                return error;
-       dentry = f.file->f_path.dentry;
-       audit_inode(NULL, dentry, 0);
+       audit_file(f.file);
        error = mnt_want_write_file(f.file);
        if (!error) {
-               error = setxattr(dentry, name, value, size, flags);
+               error = setxattr(f.file->f_path.dentry, name, value, size, flags);
                mnt_drop_write_file(f.file);
        }
        fdput(f);
@@ -509,7 +507,7 @@ SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
 
        if (!f.file)
                return error;
-       audit_inode(NULL, f.file->f_path.dentry, 0);
+       audit_file(f.file);
        error = getxattr(f.file->f_path.dentry, name, value, size);
        fdput(f);
        return error;
@@ -590,7 +588,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
 
        if (!f.file)
                return error;
-       audit_inode(NULL, f.file->f_path.dentry, 0);
+       audit_file(f.file);
        error = listxattr(f.file->f_path.dentry, list, size);
        fdput(f);
        return error;
@@ -651,16 +649,14 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
 {
        struct fd f = fdget(fd);
-       struct dentry *dentry;
        int error = -EBADF;
 
        if (!f.file)
                return error;
-       dentry = f.file->f_path.dentry;
-       audit_inode(NULL, dentry, 0);
+       audit_file(f.file);
        error = mnt_want_write_file(f.file);
        if (!error) {
-               error = removexattr(dentry, name);
+               error = removexattr(f.file->f_path.dentry, name);
                mnt_drop_write_file(f.file);
        }
        fdput(f);
index e58fe7d..0c04917 100644 (file)
@@ -130,6 +130,7 @@ extern void audit_putname(struct filename *name);
 #define AUDIT_INODE_HIDDEN     2       /* audit record should be hidden */
 extern void __audit_inode(struct filename *name, const struct dentry *dentry,
                                unsigned int flags);
+extern void __audit_file(const struct file *);
 extern void __audit_inode_child(const struct inode *parent,
                                const struct dentry *dentry,
                                const unsigned char type);
@@ -183,6 +184,11 @@ static inline void audit_inode(struct filename *name,
                __audit_inode(name, dentry, flags);
        }
 }
+static inline void audit_file(struct file *file)
+{
+       if (unlikely(!audit_dummy_context()))
+               __audit_file(file);
+}
 static inline void audit_inode_parent_hidden(struct filename *name,
                                                const struct dentry *dentry)
 {
@@ -357,6 +363,9 @@ static inline void audit_inode(struct filename *name,
                                const struct dentry *dentry,
                                unsigned int parent)
 { }
+static inline void audit_file(struct file *file)
+{
+}
 static inline void audit_inode_parent_hidden(struct filename *name,
                                const struct dentry *dentry)
 { }
index 4fcf39a..7635a1c 100644 (file)
@@ -990,7 +990,7 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr,
                goto out_fput;
        }
        info = MQUEUE_I(inode);
-       audit_inode(NULL, f.file->f_path.dentry, 0);
+       audit_file(f.file);
 
        if (unlikely(!(f.file->f_mode & FMODE_WRITE))) {
                ret = -EBADF;
@@ -1106,7 +1106,7 @@ SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr,
                goto out_fput;
        }
        info = MQUEUE_I(inode);
-       audit_inode(NULL, f.file->f_path.dentry, 0);
+       audit_file(f.file);
 
        if (unlikely(!(f.file->f_mode & FMODE_READ))) {
                ret = -EBADF;
index 0682065..c75522a 100644 (file)
@@ -1897,6 +1897,11 @@ out:
        audit_copy_inode(n, dentry, inode);
 }
 
+void __audit_file(const struct file *file)
+{
+       __audit_inode(NULL, file->f_path.dentry, 0);
+}
+
 /**
  * __audit_inode_child - collect inode info for created/removed objects
  * @parent: inode of dentry parent