[PATCH 2/2] vfs: don't always include audit-specific members of struct filename

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The three members uptr, aname and refcnt are only used when
CONFIG_AUDITSYSCALL, a fact which is not obvious from the header file
or namei.c alone. So aside from eliminating a few useless instructions
in getname_flags and making EMBEDDED_NAME_MAX a little larger, this
patch also serves to document whoe the actual user of these members
is.

Signed-off-by: Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>
---
 fs/namei.c            | 10 ++++------
 include/linux/audit.h |  9 +++++++++
 include/linux/fs.h    |  2 ++
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index bd150fa799a2..21410db25814 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -185,7 +185,6 @@ getname_flags(const char __user *filename, int flags, int *empty)
 		}
 	}
 
-	result->refcnt = 1;
 	/* The empty path is special. */
 	if (unlikely(!len)) {
 		if (empty)
@@ -196,8 +195,7 @@ getname_flags(const char __user *filename, int flags, int *empty)
 		}
 	}
 
-	result->uptr = filename;
-	result->aname = NULL;
+	audit_init_filename(result, filename);
 	audit_getname(result);
 	return result;
 }
@@ -235,9 +233,7 @@ getname_kernel(const char * filename)
 		return ERR_PTR(-ENAMETOOLONG);
 	}
 	memcpy((char *)result->name, filename, len);
-	result->uptr = NULL;
-	result->aname = NULL;
-	result->refcnt = 1;
+	audit_init_filename(result, NULL);
 	audit_getname(result);
 
 	return result;
@@ -245,10 +241,12 @@ getname_kernel(const char * filename)
 
 void putname(struct filename *name)
 {
+#ifdef CONFIG_AUDITSYSCALL
 	BUG_ON(name->refcnt <= 0);
 
 	if (--name->refcnt > 0)
 		return;
+#endif
 
 	if (name->name != name->iname) {
 		__putname(name->name);
diff --git a/include/linux/audit.h b/include/linux/audit.h
index b40ed5df5542..7d7143674d85 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -232,6 +232,12 @@ extern void __audit_syscall_entry(int major, unsigned long a0, unsigned long a1,
 extern void __audit_syscall_exit(int ret_success, long ret_value);
 extern struct filename *__audit_reusename(const __user char *uptr);
 extern void __audit_getname(struct filename *name);
+static inline void audit_init_filename(struct filename *name, const __user char *uptr)
+{
+	name->refcnt = 1;
+	name->aname = NULL;
+	name->uptr = uptr;
+}
 
 #define AUDIT_INODE_PARENT	1	/* dentry represents the parent */
 #define AUDIT_INODE_HIDDEN	2	/* audit record should be hidden */
@@ -459,6 +465,9 @@ static inline struct filename *audit_reusename(const __user char *name)
 }
 static inline void audit_getname(struct filename *name)
 { }
+static inline void audit_init_filename(struct filename *name, const __user char *uptr)
+{ }
+
 static inline void __audit_inode(struct filename *name,
 					const struct dentry *dentry,
 					unsigned int flags)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index d522e6391855..df769f738695 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2243,12 +2243,14 @@ static inline int break_layout(struct inode *inode, bool wait)
 struct audit_names;
 struct filename {
 	const char		*name;	/* pointer to actual string */
+#ifdef CONFIG_AUDITSYSCALL
 	const __user char	*uptr;	/* original userland pointer */
 	struct audit_names	*aname;
 	union {
 		int		refcnt;
 		long		__padding;
 	};
+#endif
 	const char		iname[];
 };
 
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux