Skip to content

Commit

Permalink
audit: allow audit code to satisfy getname requests from its names_list
Browse files Browse the repository at this point in the history
Currently, if we call getname() on a userland string more than once,
we'll get multiple copies of the string and multiple audit_names
records.

Add a function that will allow the audit_names code to satisfy getname
requests using info from the audit_names list, avoiding a new allocation
and audit_names records.

Signed-off-by: Jeff Layton <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
jtlayton authored and Al Viro committed Oct 13, 2012
1 parent 91a27b2 commit 7ac8626
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ getname_flags(const char __user *filename, int flags, int *empty)
char *kname;
int len;

result = audit_reusename(filename);
if (result)
return result;

/* FIXME: create dedicated slabcache? */
result = kzalloc(sizeof(*result), GFP_KERNEL);
if (unlikely(!result))
Expand Down
11 changes: 11 additions & 0 deletions include/linux/audit.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ extern void __audit_syscall_entry(int arch,
int major, unsigned long a0, unsigned long a1,
unsigned long a2, unsigned long a3);
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);
extern void audit_putname(struct filename *name);
extern void __audit_inode(const char *name, const struct dentry *dentry,
Expand Down Expand Up @@ -507,6 +508,12 @@ static inline void audit_syscall_exit(void *pt_regs)
__audit_syscall_exit(success, return_code);
}
}
static inline struct filename *audit_reusename(const __user char *name)
{
if (unlikely(!audit_dummy_context()))
return __audit_reusename(name);
return NULL;
}
static inline void audit_getname(struct filename *name)
{
if (unlikely(!audit_dummy_context()))
Expand Down Expand Up @@ -665,6 +672,10 @@ static inline int audit_dummy_context(void)
{
return 1;
}
static inline struct filename *audit_reusename(const __user char *name)
{
return NULL;
}
static inline void audit_getname(struct filename *name)
{ }
static inline void audit_putname(struct filename *name)
Expand Down
23 changes: 23 additions & 0 deletions kernel/auditsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,29 @@ static struct audit_names *audit_alloc_name(struct audit_context *context,
return aname;
}

/**
* audit_reusename - fill out filename with info from existing entry
* @uptr: userland ptr to pathname
*
* Search the audit_names list for the current audit context. If there is an
* existing entry with a matching "uptr" then return the filename
* associated with that audit_name. If not, return NULL.
*/
struct filename *
__audit_reusename(const __user char *uptr)
{
struct audit_context *context = current->audit_context;
struct audit_names *n;

list_for_each_entry(n, &context->names_list, list) {
if (!n->name)
continue;
if (n->name->uptr == uptr)
return n->name;
}
return NULL;
}

/**
* audit_getname - add a name to the list
* @name: name to add
Expand Down

0 comments on commit 7ac8626

Please sign in to comment.