audit: make audit_inode take struct filename
Keep a pointer to the audit_names "slot" in struct filename. Have all of the audit_inode callers pass a struct filename ponter to audit_inode instead of a string pointer. If the aname field is already populated, then we can skip walking the list altogether and just use it directly. Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
669abf4e55
commit
adb5c2473d
16
fs/namei.c
16
fs/namei.c
|
@ -1999,8 +1999,7 @@ static int filename_lookup(int dfd, struct filename *name,
|
||||||
flags | LOOKUP_REVAL, nd);
|
flags | LOOKUP_REVAL, nd);
|
||||||
|
|
||||||
if (likely(!retval))
|
if (likely(!retval))
|
||||||
audit_inode(name->name, nd->path.dentry,
|
audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
|
||||||
flags & LOOKUP_PARENT);
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2674,7 +2673,6 @@ static int do_last(struct nameidata *nd, struct path *path,
|
||||||
struct path save_parent = { .dentry = NULL, .mnt = NULL };
|
struct path save_parent = { .dentry = NULL, .mnt = NULL };
|
||||||
bool retried = false;
|
bool retried = false;
|
||||||
int error;
|
int error;
|
||||||
const char *pathname = name->name;
|
|
||||||
|
|
||||||
nd->flags &= ~LOOKUP_PARENT;
|
nd->flags &= ~LOOKUP_PARENT;
|
||||||
nd->flags |= op->intent;
|
nd->flags |= op->intent;
|
||||||
|
@ -2690,7 +2688,7 @@ static int do_last(struct nameidata *nd, struct path *path,
|
||||||
error = complete_walk(nd);
|
error = complete_walk(nd);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
audit_inode(pathname, nd->path.dentry, 0);
|
audit_inode(name, nd->path.dentry, 0);
|
||||||
if (open_flag & O_CREAT) {
|
if (open_flag & O_CREAT) {
|
||||||
error = -EISDIR;
|
error = -EISDIR;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -2700,7 +2698,7 @@ static int do_last(struct nameidata *nd, struct path *path,
|
||||||
error = complete_walk(nd);
|
error = complete_walk(nd);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
audit_inode(pathname, dir, 0);
|
audit_inode(name, dir, 0);
|
||||||
goto finish_open;
|
goto finish_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2729,7 +2727,7 @@ static int do_last(struct nameidata *nd, struct path *path,
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
audit_inode(pathname, dir, 0);
|
audit_inode(name, dir, 0);
|
||||||
error = -EISDIR;
|
error = -EISDIR;
|
||||||
/* trailing slashes? */
|
/* trailing slashes? */
|
||||||
if (nd->last.name[nd->last.len])
|
if (nd->last.name[nd->last.len])
|
||||||
|
@ -2759,7 +2757,7 @@ retry_lookup:
|
||||||
!S_ISREG(file->f_path.dentry->d_inode->i_mode))
|
!S_ISREG(file->f_path.dentry->d_inode->i_mode))
|
||||||
will_truncate = false;
|
will_truncate = false;
|
||||||
|
|
||||||
audit_inode(pathname, file->f_path.dentry, 0);
|
audit_inode(name, file->f_path.dentry, 0);
|
||||||
goto opened;
|
goto opened;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2776,7 +2774,7 @@ retry_lookup:
|
||||||
* create/update audit record if it already exists.
|
* create/update audit record if it already exists.
|
||||||
*/
|
*/
|
||||||
if (path->dentry->d_inode)
|
if (path->dentry->d_inode)
|
||||||
audit_inode(pathname, path->dentry, 0);
|
audit_inode(name, path->dentry, 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If atomic_open() acquired write access it is dropped now due to
|
* If atomic_open() acquired write access it is dropped now due to
|
||||||
|
@ -2841,7 +2839,7 @@ finish_lookup:
|
||||||
error = -ENOTDIR;
|
error = -ENOTDIR;
|
||||||
if ((nd->flags & LOOKUP_DIRECTORY) && !nd->inode->i_op->lookup)
|
if ((nd->flags & LOOKUP_DIRECTORY) && !nd->inode->i_op->lookup)
|
||||||
goto out;
|
goto out;
|
||||||
audit_inode(pathname, nd->path.dentry, 0);
|
audit_inode(name, nd->path.dentry, 0);
|
||||||
finish_open:
|
finish_open:
|
||||||
if (!S_ISREG(nd->inode->i_mode))
|
if (!S_ISREG(nd->inode->i_mode))
|
||||||
will_truncate = false;
|
will_truncate = false;
|
||||||
|
|
|
@ -474,7 +474,7 @@ extern void __audit_syscall_exit(int ret_success, long ret_value);
|
||||||
extern struct filename *__audit_reusename(const __user char *uptr);
|
extern struct filename *__audit_reusename(const __user char *uptr);
|
||||||
extern void __audit_getname(struct filename *name);
|
extern void __audit_getname(struct filename *name);
|
||||||
extern void audit_putname(struct filename *name);
|
extern void audit_putname(struct filename *name);
|
||||||
extern void __audit_inode(const char *name, const struct dentry *dentry,
|
extern void __audit_inode(struct filename *name, const struct dentry *dentry,
|
||||||
unsigned int parent);
|
unsigned int parent);
|
||||||
extern void __audit_inode_child(const struct inode *parent,
|
extern void __audit_inode_child(const struct inode *parent,
|
||||||
const struct dentry *dentry,
|
const struct dentry *dentry,
|
||||||
|
@ -519,7 +519,7 @@ static inline void audit_getname(struct filename *name)
|
||||||
if (unlikely(!audit_dummy_context()))
|
if (unlikely(!audit_dummy_context()))
|
||||||
__audit_getname(name);
|
__audit_getname(name);
|
||||||
}
|
}
|
||||||
static inline void audit_inode(const char *name, const struct dentry *dentry,
|
static inline void audit_inode(struct filename *name, const struct dentry *dentry,
|
||||||
unsigned int parent) {
|
unsigned int parent) {
|
||||||
if (unlikely(!audit_dummy_context()))
|
if (unlikely(!audit_dummy_context()))
|
||||||
__audit_inode(name, dentry, parent);
|
__audit_inode(name, dentry, parent);
|
||||||
|
@ -680,14 +680,16 @@ static inline void audit_getname(struct filename *name)
|
||||||
{ }
|
{ }
|
||||||
static inline void audit_putname(struct filename *name)
|
static inline void audit_putname(struct filename *name)
|
||||||
{ }
|
{ }
|
||||||
static inline void __audit_inode(const char *name, const struct dentry *dentry,
|
static inline void __audit_inode(struct filename *name,
|
||||||
|
const struct dentry *dentry,
|
||||||
unsigned int parent)
|
unsigned int parent)
|
||||||
{ }
|
{ }
|
||||||
static inline void __audit_inode_child(const struct inode *parent,
|
static inline void __audit_inode_child(const struct inode *parent,
|
||||||
const struct dentry *dentry,
|
const struct dentry *dentry,
|
||||||
const unsigned char type)
|
const unsigned char type)
|
||||||
{ }
|
{ }
|
||||||
static inline void audit_inode(const char *name, const struct dentry *dentry,
|
static inline void audit_inode(struct filename *name,
|
||||||
|
const struct dentry *dentry,
|
||||||
unsigned int parent)
|
unsigned int parent)
|
||||||
{ }
|
{ }
|
||||||
static inline void audit_inode_child(const struct inode *parent,
|
static inline void audit_inode_child(const struct inode *parent,
|
||||||
|
|
|
@ -2196,9 +2196,11 @@ static inline int break_lease(struct inode *inode, unsigned int mode)
|
||||||
#endif /* CONFIG_FILE_LOCKING */
|
#endif /* CONFIG_FILE_LOCKING */
|
||||||
|
|
||||||
/* fs/open.c */
|
/* fs/open.c */
|
||||||
|
struct audit_names;
|
||||||
struct filename {
|
struct filename {
|
||||||
const char *name; /* pointer to actual string */
|
const char *name; /* pointer to actual string */
|
||||||
const __user char *uptr; /* original userland pointer */
|
const __user char *uptr; /* original userland pointer */
|
||||||
|
struct audit_names *aname;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs,
|
extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs,
|
||||||
|
|
|
@ -804,7 +804,7 @@ SYSCALL_DEFINE4(mq_open, const char __user *, u_name, int, oflag, umode_t, mode,
|
||||||
|
|
||||||
if (oflag & O_CREAT) {
|
if (oflag & O_CREAT) {
|
||||||
if (path.dentry->d_inode) { /* entry already exists */
|
if (path.dentry->d_inode) { /* entry already exists */
|
||||||
audit_inode(name->name, path.dentry, 0);
|
audit_inode(name, path.dentry, 0);
|
||||||
if (oflag & O_EXCL) {
|
if (oflag & O_EXCL) {
|
||||||
error = -EEXIST;
|
error = -EEXIST;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -824,7 +824,7 @@ SYSCALL_DEFINE4(mq_open, const char __user *, u_name, int, oflag, umode_t, mode,
|
||||||
error = -ENOENT;
|
error = -ENOENT;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
audit_inode(name->name, path.dentry, 0);
|
audit_inode(name, path.dentry, 0);
|
||||||
filp = do_open(&path, oflag);
|
filp = do_open(&path, oflag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2076,6 +2076,7 @@ void __audit_getname(struct filename *name)
|
||||||
n->name = name;
|
n->name = name;
|
||||||
n->name_len = AUDIT_NAME_FULL;
|
n->name_len = AUDIT_NAME_FULL;
|
||||||
n->name_put = true;
|
n->name_put = true;
|
||||||
|
name->aname = n;
|
||||||
|
|
||||||
if (!context->pwd.dentry)
|
if (!context->pwd.dentry)
|
||||||
get_fs_pwd(current->fs, &context->pwd);
|
get_fs_pwd(current->fs, &context->pwd);
|
||||||
|
@ -2166,7 +2167,7 @@ static void audit_copy_inode(struct audit_names *name, const struct dentry *dent
|
||||||
* @dentry: dentry being audited
|
* @dentry: dentry being audited
|
||||||
* @parent: does this dentry represent the parent?
|
* @parent: does this dentry represent the parent?
|
||||||
*/
|
*/
|
||||||
void __audit_inode(const char *name, const struct dentry *dentry,
|
void __audit_inode(struct filename *name, const struct dentry *dentry,
|
||||||
unsigned int parent)
|
unsigned int parent)
|
||||||
{
|
{
|
||||||
struct audit_context *context = current->audit_context;
|
struct audit_context *context = current->audit_context;
|
||||||
|
@ -2179,9 +2180,29 @@ void __audit_inode(const char *name, const struct dentry *dentry,
|
||||||
if (!name)
|
if (!name)
|
||||||
goto out_alloc;
|
goto out_alloc;
|
||||||
|
|
||||||
|
#if AUDIT_DEBUG
|
||||||
|
/* The struct filename _must_ have a populated ->name */
|
||||||
|
BUG_ON(!name->name);
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* If we have a pointer to an audit_names entry already, then we can
|
||||||
|
* just use it directly if the type is correct.
|
||||||
|
*/
|
||||||
|
n = name->aname;
|
||||||
|
if (n) {
|
||||||
|
if (parent) {
|
||||||
|
if (n->type == AUDIT_TYPE_PARENT ||
|
||||||
|
n->type == AUDIT_TYPE_UNKNOWN)
|
||||||
|
goto out;
|
||||||
|
} else {
|
||||||
|
if (n->type != AUDIT_TYPE_PARENT)
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
list_for_each_entry_reverse(n, &context->names_list, list) {
|
list_for_each_entry_reverse(n, &context->names_list, list) {
|
||||||
/* does the name pointer match? */
|
/* does the name pointer match? */
|
||||||
if (!n->name || n->name->name != name)
|
if (!n->name || n->name->name != name->name)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* match the correct record type */
|
/* match the correct record type */
|
||||||
|
|
Reference in New Issue