Skip to content

Commit 5943026

Browse files
committed
vfs: fix race in rcu lookup of pruned dentry
Don't update *inode in __follow_mount_rcu() until we'd verified that there is mountpoint there. Kudos to Hugh Dickins for catching that one in the first place and eventually figuring out the solution (and catching a braino in the earlier version of patch). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent fec11dd commit 5943026

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

fs/namei.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,6 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path,
942942
* Don't forget we might have a non-mountpoint managed dentry
943943
* that wants to block transit.
944944
*/
945-
*inode = path->dentry->d_inode;
946945
if (unlikely(managed_dentry_might_block(path->dentry)))
947946
return false;
948947

@@ -955,6 +954,12 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path,
955954
path->mnt = mounted;
956955
path->dentry = mounted->mnt_root;
957956
nd->seq = read_seqcount_begin(&path->dentry->d_seq);
957+
/*
958+
* Update the inode too. We don't need to re-check the
959+
* dentry sequence number here after this d_inode read,
960+
* because a mount-point is always pinned.
961+
*/
962+
*inode = path->dentry->d_inode;
958963
}
959964
return true;
960965
}

0 commit comments

Comments
 (0)