Skip to content

Commit 012e79b

Browse files
torvaldsgregkh
authored andcommitted
vfs: don't do RCU lookup of empty pathnames
commit c0eb027 upstream. Normal pathname lookup doesn't allow empty pathnames, but using AT_EMPTY_PATH (with name_to_handle_at() or fstatat(), for example) you can trigger an empty pathname lookup. And not only is the RCU lookup in that case entirely unnecessary (because we'll obviously immediately finalize the end result), it is actively wrong. Why? An empth path is a special case that will return the original 'dirfd' dentry - and that dentry may not actually be RCU-free'd, resulting in a potential use-after-free if we were to initialize the path lazily under the RCU read lock and depend on complete_walk() finalizing the dentry. Found by syzkaller and KASAN. Reported-by: Dmitry Vyukov <dvyukov@google.com> Reported-by: Vegard Nossum <vegard.nossum@gmail.com> Acked-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Cc: Eric Biggers <ebiggers3@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 95a440b commit 012e79b

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

fs/namei.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,6 +2138,9 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
21382138
int retval = 0;
21392139
const char *s = nd->name->name;
21402140

2141+
if (!*s)
2142+
flags &= ~LOOKUP_RCU;
2143+
21412144
nd->last_type = LAST_ROOT; /* if there are only slashes... */
21422145
nd->flags = flags | LOOKUP_JUMPED | LOOKUP_PARENT;
21432146
nd->depth = 0;

0 commit comments

Comments
 (0)