make path_init() unconditionally paired with terminate_walk()
including the failure exits Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
5014c2f378
commit
edc2b1da77
28
fs/namei.c
28
fs/namei.c
@ -2125,12 +2125,15 @@ OK:
|
||||
}
|
||||
}
|
||||
|
||||
/* must be paired with terminate_walk() */
|
||||
static const char *path_init(struct nameidata *nd, unsigned flags)
|
||||
{
|
||||
const char *s = nd->name->name;
|
||||
|
||||
if (!*s)
|
||||
flags &= ~LOOKUP_RCU;
|
||||
if (flags & LOOKUP_RCU)
|
||||
rcu_read_lock();
|
||||
|
||||
nd->last_type = LAST_ROOT; /* if there are only slashes... */
|
||||
nd->flags = flags | LOOKUP_JUMPED | LOOKUP_PARENT;
|
||||
@ -2143,7 +2146,6 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
|
||||
nd->path = nd->root;
|
||||
nd->inode = inode;
|
||||
if (flags & LOOKUP_RCU) {
|
||||
rcu_read_lock();
|
||||
nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq);
|
||||
nd->root_seq = nd->seq;
|
||||
nd->m_seq = read_seqbegin(&mount_lock);
|
||||
@ -2159,21 +2161,15 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
|
||||
|
||||
nd->m_seq = read_seqbegin(&mount_lock);
|
||||
if (*s == '/') {
|
||||
if (flags & LOOKUP_RCU)
|
||||
rcu_read_lock();
|
||||
set_root(nd);
|
||||
if (likely(!nd_jump_root(nd)))
|
||||
return s;
|
||||
nd->root.mnt = NULL;
|
||||
rcu_read_unlock();
|
||||
return ERR_PTR(-ECHILD);
|
||||
} else if (nd->dfd == AT_FDCWD) {
|
||||
if (flags & LOOKUP_RCU) {
|
||||
struct fs_struct *fs = current->fs;
|
||||
unsigned seq;
|
||||
|
||||
rcu_read_lock();
|
||||
|
||||
do {
|
||||
seq = read_seqcount_begin(&fs->seq);
|
||||
nd->path = fs->pwd;
|
||||
@ -2195,16 +2191,13 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
|
||||
|
||||
dentry = f.file->f_path.dentry;
|
||||
|
||||
if (*s) {
|
||||
if (!d_can_lookup(dentry)) {
|
||||
if (*s && unlikely(!d_can_lookup(dentry))) {
|
||||
fdput(f);
|
||||
return ERR_PTR(-ENOTDIR);
|
||||
}
|
||||
}
|
||||
|
||||
nd->path = f.file->f_path;
|
||||
if (flags & LOOKUP_RCU) {
|
||||
rcu_read_lock();
|
||||
nd->inode = nd->path.dentry->d_inode;
|
||||
nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
|
||||
} else {
|
||||
@ -2272,8 +2265,10 @@ static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path
|
||||
const char *s = path_init(nd, flags);
|
||||
int err;
|
||||
|
||||
if (IS_ERR(s))
|
||||
if (IS_ERR(s)) {
|
||||
terminate_walk(nd);
|
||||
return PTR_ERR(s);
|
||||
}
|
||||
|
||||
if (unlikely(flags & LOOKUP_DOWN)) {
|
||||
err = handle_lookup_down(nd);
|
||||
@ -2337,8 +2332,10 @@ static int path_parentat(struct nameidata *nd, unsigned flags,
|
||||
{
|
||||
const char *s = path_init(nd, flags);
|
||||
int err;
|
||||
if (IS_ERR(s))
|
||||
if (IS_ERR(s)) {
|
||||
terminate_walk(nd);
|
||||
return PTR_ERR(s);
|
||||
}
|
||||
err = link_path_walk(s, nd);
|
||||
if (!err)
|
||||
err = complete_walk(nd);
|
||||
@ -2666,8 +2663,10 @@ path_mountpoint(struct nameidata *nd, unsigned flags, struct path *path)
|
||||
{
|
||||
const char *s = path_init(nd, flags);
|
||||
int err;
|
||||
if (IS_ERR(s))
|
||||
if (IS_ERR(s)) {
|
||||
terminate_walk(nd);
|
||||
return PTR_ERR(s);
|
||||
}
|
||||
while (!(err = link_path_walk(s, nd)) &&
|
||||
(err = mountpoint_last(nd)) > 0) {
|
||||
s = trailing_symlink(nd);
|
||||
@ -3512,6 +3511,7 @@ static struct file *path_openat(struct nameidata *nd,
|
||||
|
||||
s = path_init(nd, flags);
|
||||
if (IS_ERR(s)) {
|
||||
terminate_walk(nd);
|
||||
fput(file);
|
||||
return ERR_CAST(s);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user