Commit efe772d6 authored by Al Viro's avatar Al Viro

follow_dotdot_rcu(): be lazy about changing nd->path

Change nd->path only after the loop is done and only in case we hadn't
ended up finding ourselves in root.  Same for NO_XDEV check.  Don't
recheck mount_lock on each step either.

That separates the "check how far back do we need to go through the
mount stack" logics from the rest of .. traversal.

Note that the sequence for d_seq/d_inode here is
	* sample mount_lock seqcount
...
	* sample d_seq
	* fetch d_inode
	* verify mount_lock seqcount
The last step makes sure that d_inode value we'd got matches d_seq -
it dentry is guaranteed to have been a mountpoint through the
entire thing, so its d_inode must have been stable.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 12487f30
...@@ -1696,28 +1696,31 @@ static struct dentry *follow_dotdot_rcu(struct nameidata *nd, ...@@ -1696,28 +1696,31 @@ static struct dentry *follow_dotdot_rcu(struct nameidata *nd,
if (path_equal(&nd->path, &nd->root)) if (path_equal(&nd->path, &nd->root))
goto in_root; goto in_root;
if (unlikely(nd->path.dentry == nd->path.mnt->mnt_root)) { if (unlikely(nd->path.dentry == nd->path.mnt->mnt_root)) {
struct path path = nd->path;
unsigned seq;
while (1) { while (1) {
struct mount *mnt = real_mount(nd->path.mnt); struct mount *mnt = real_mount(path.mnt);
struct mount *mparent = mnt->mnt_parent; struct mount *mparent = mnt->mnt_parent;
struct dentry *mountpoint = mnt->mnt_mountpoint; struct dentry *mountpoint = mnt->mnt_mountpoint;
struct inode *inode = mountpoint->d_inode; seq = read_seqcount_begin(&mountpoint->d_seq);
unsigned seq = read_seqcount_begin(&mountpoint->d_seq); if (&mparent->mnt == path.mnt)
if (unlikely(read_seqretry(&mount_lock, nd->m_seq)))
return ERR_PTR(-ECHILD);
if (&mparent->mnt == nd->path.mnt)
goto in_root; goto in_root;
if (unlikely(nd->flags & LOOKUP_NO_XDEV)) path.dentry = mountpoint;
return ERR_PTR(-ECHILD); path.mnt = &mparent->mnt;
/* we know that mountpoint was pinned */ if (path_equal(&path, &nd->root))
nd->path.dentry = mountpoint;
nd->path.mnt = &mparent->mnt;
nd->inode = inode;
nd->seq = seq;
if (path_equal(&nd->path, &nd->root))
goto in_root; goto in_root;
if (nd->path.dentry != nd->path.mnt->mnt_root) if (path.dentry != path.mnt->mnt_root)
break; break;
} }
if (unlikely(nd->flags & LOOKUP_NO_XDEV))
return ERR_PTR(-ECHILD);
nd->path = path;
nd->inode = path.dentry->d_inode;
nd->seq = seq;
if (unlikely(read_seqretry(&mount_lock, nd->m_seq)))
return ERR_PTR(-ECHILD);
/* we know that mountpoint was pinned */
} }
old = nd->path.dentry; old = nd->path.dentry;
parent = old->d_parent; parent = old->d_parent;
...@@ -1729,6 +1732,8 @@ static struct dentry *follow_dotdot_rcu(struct nameidata *nd, ...@@ -1729,6 +1732,8 @@ static struct dentry *follow_dotdot_rcu(struct nameidata *nd,
return ERR_PTR(-ECHILD); return ERR_PTR(-ECHILD);
return parent; return parent;
in_root: in_root:
if (unlikely(read_seqretry(&mount_lock, nd->m_seq)))
return ERR_PTR(-ECHILD);
if (unlikely(nd->flags & LOOKUP_BENEATH)) if (unlikely(nd->flags & LOOKUP_BENEATH))
return ERR_PTR(-ECHILD); return ERR_PTR(-ECHILD);
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment