@@ -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);
@@ -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)
@@ -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[];
};
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@rasmusvillemoes.dk> --- fs/namei.c | 10 ++++------ include/linux/audit.h | 9 +++++++++ include/linux/fs.h | 2 ++ 3 files changed, 15 insertions(+), 6 deletions(-)