Skip to content

Commit cdb67fd

Browse files
author
Al Viro
committed
rcu pathwalk: prevent bogus hard errors from may_lookup()
If lazy call of ->permission() returns a hard error, check that try_to_unlazy() succeeds before returning it. That both makes life easier for ->permission() instances and closes the race in ENOTDIR handling - it is possible that positive d_can_lookup() seen in link_path_walk() applies to the state *after* unlink() + mkdir(), while nd->inode matches the state prior to that. Normally seeing e.g. EACCES from permission check in rcu pathwalk means that with some timings non-rcu pathwalk would've run into the same; however, running into a non-executable regular file in the middle of a pathname would not get to permission check - it would fail with ENOTDIR instead. Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 583340d commit cdb67fd

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

fs/namei.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,11 @@ static inline int may_lookup(struct mnt_idmap *idmap,
17171717
{
17181718
if (nd->flags & LOOKUP_RCU) {
17191719
int err = inode_permission(idmap, nd->inode, MAY_EXEC|MAY_NOT_BLOCK);
1720-
if (err != -ECHILD || !try_to_unlazy(nd))
1720+
if (!err) // success, keep going
1721+
return 0;
1722+
if (!try_to_unlazy(nd))
1723+
return -ECHILD; // redo it all non-lazy
1724+
if (err != -ECHILD) // hard error
17211725
return err;
17221726
}
17231727
return inode_permission(idmap, nd->inode, MAY_EXEC);

0 commit comments

Comments
 (0)