From: Al Viro Date: Mon, 27 Apr 2026 18:19:28 +0000 (-0400) Subject: alloc_path_pseudo(): make sure we don't end up with NORCU dentries for directories X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a810147a07535e63a7c1fbb90975012e8d57f60;p=thirdparty%2Flinux.git alloc_path_pseudo(): make sure we don't end up with NORCU dentries for directories A lot of places relies upon directories never having NORCU dentries; currently that property holds, but the proof is not straightforward and rather brittle. It's better to have that verified in the sole caller of d_alloc_pseudo(), so that any future bugs in that direction were caught early. That way we can be sure that * current directory of any process is not NORCU * root directory of any process is not NORCU * starting point of any LOOKUP_RCU pathwalk is not NORCU * dget_parent() can rely upon ->d_parent not being NORCU * d_walk() and is_subdir() can rely upon the same * alloc_file_pseudo() won't create multiple aliases for a directory without having to go through a convoluted audit. Signed-off-by: Al Viro --- diff --git a/fs/file_table.c b/fs/file_table.c index 16e52e7fc2ace..108ba09fb402b 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -402,6 +402,8 @@ static struct file *alloc_file(const struct path *path, int flags, static inline int alloc_path_pseudo(const char *name, struct inode *inode, struct vfsmount *mnt, struct path *path) { + if (WARN_ON_ONCE(S_ISDIR(inode->i_mode))) + return -EINVAL; path->dentry = d_alloc_pseudo(mnt->mnt_sb, &QSTR(name)); if (!path->dentry) return -ENOMEM;