Skip to content

Commit c0eb027

Browse files
committed
vfs: don't do RCU lookup of empty pathnames
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 <[email protected]> Reported-by: Vegard Nossum <[email protected]> Acked-by: Al Viro <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1bf4b12 commit c0eb027

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

fs/namei.c

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

2148+
if (!*s)
2149+
flags &= ~LOOKUP_RCU;
2150+
21482151
nd->last_type = LAST_ROOT; /* if there are only slashes... */
21492152
nd->flags = flags | LOOKUP_JUMPED | LOOKUP_PARENT;
21502153
nd->depth = 0;

0 commit comments

Comments
 (0)