vfs: turn do_path_lookup into wrapper around struct filename variant
...and make the user_path callers use that variant instead. Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
7ac86265dc
commit
873f1eedc1
1 changed files with 26 additions and 10 deletions
36
fs/namei.c
36
fs/namei.c
|
@ -1988,18 +1988,28 @@ static int path_lookupat(int dfd, const char *name,
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int filename_lookup(int dfd, struct filename *name,
|
||||||
|
unsigned int flags, struct nameidata *nd)
|
||||||
|
{
|
||||||
|
int retval = path_lookupat(dfd, name->name, flags | LOOKUP_RCU, nd);
|
||||||
|
if (unlikely(retval == -ECHILD))
|
||||||
|
retval = path_lookupat(dfd, name->name, flags, nd);
|
||||||
|
if (unlikely(retval == -ESTALE))
|
||||||
|
retval = path_lookupat(dfd, name->name,
|
||||||
|
flags | LOOKUP_REVAL, nd);
|
||||||
|
|
||||||
|
if (likely(!retval))
|
||||||
|
audit_inode(name->name, nd->path.dentry,
|
||||||
|
flags & LOOKUP_PARENT);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
static int do_path_lookup(int dfd, const char *name,
|
static int do_path_lookup(int dfd, const char *name,
|
||||||
unsigned int flags, struct nameidata *nd)
|
unsigned int flags, struct nameidata *nd)
|
||||||
{
|
{
|
||||||
int retval = path_lookupat(dfd, name, flags | LOOKUP_RCU, nd);
|
struct filename filename = { .name = name };
|
||||||
if (unlikely(retval == -ECHILD))
|
|
||||||
retval = path_lookupat(dfd, name, flags, nd);
|
|
||||||
if (unlikely(retval == -ESTALE))
|
|
||||||
retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
|
|
||||||
|
|
||||||
if (likely(!retval))
|
return filename_lookup(dfd, &filename, flags, nd);
|
||||||
audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* does lookup, returns the object with parent locked */
|
/* does lookup, returns the object with parent locked */
|
||||||
|
@ -2125,7 +2135,7 @@ int user_path_at_empty(int dfd, const char __user *name, unsigned flags,
|
||||||
|
|
||||||
BUG_ON(flags & LOOKUP_PARENT);
|
BUG_ON(flags & LOOKUP_PARENT);
|
||||||
|
|
||||||
err = do_path_lookup(dfd, tmp->name, flags, &nd);
|
err = filename_lookup(dfd, tmp, flags, &nd);
|
||||||
putname(tmp);
|
putname(tmp);
|
||||||
if (!err)
|
if (!err)
|
||||||
*path = nd.path;
|
*path = nd.path;
|
||||||
|
@ -2139,6 +2149,12 @@ int user_path_at(int dfd, const char __user *name, unsigned flags,
|
||||||
return user_path_at_empty(dfd, name, flags, path, NULL);
|
return user_path_at_empty(dfd, name, flags, path, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NB: most callers don't do anything directly with the reference to the
|
||||||
|
* to struct filename, but the nd->last pointer points into the name string
|
||||||
|
* allocated by getname. So we must hold the reference to it until all
|
||||||
|
* path-walking is complete.
|
||||||
|
*/
|
||||||
static struct filename *
|
static struct filename *
|
||||||
user_path_parent(int dfd, const char __user *path, struct nameidata *nd)
|
user_path_parent(int dfd, const char __user *path, struct nameidata *nd)
|
||||||
{
|
{
|
||||||
|
@ -2148,7 +2164,7 @@ user_path_parent(int dfd, const char __user *path, struct nameidata *nd)
|
||||||
if (IS_ERR(s))
|
if (IS_ERR(s))
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
error = do_path_lookup(dfd, s->name, LOOKUP_PARENT, nd);
|
error = filename_lookup(dfd, s, LOOKUP_PARENT, nd);
|
||||||
if (error) {
|
if (error) {
|
||||||
putname(s);
|
putname(s);
|
||||||
return ERR_PTR(error);
|
return ERR_PTR(error);
|
||||||
|
|
Loading…
Add table
Reference in a new issue