Skip to contentSkip to conversation

fs: Fix error checking for d_hash_and_lookup()

PATCH Applied Wang Ming 2 participants 2 messages Jul 13, 2023 VFS

lore
Share & tools
lore

Wang Ming

author
#0 lore raw

PATCH 1/1 fs: Fix error checking for d_hash_and_lookup()

The d_hash_and_lookup() function returns error pointers or NULL. Most incorrect error checks were fixed, but the one in int path_pts() was forgotten.

Fixes eedf265aa003 ("devpts: Make each mount of devpts an independent filesystem.")
---
 fs/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/namei.c +1 -1
index e56ff39a79bc..2bae29ea52ff 100644
@@ -2890,7 +2890,7 @@ int path_pts(struct path *path)
 	dput(path->dentry);
 	path->dentry = parent;
 	child = d_hash_and_lookup(parent, &this);
-	if (!child)
+	if (IS_ERR_OR_NULL(child))
 		return -ENOENT;
 
 	path->dentry = child;
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 5 lines · Wang Ming

The d_hash_and_lookup() function returns error pointers or NULL. Most incorrect error checks were fixed, but the one in int path_pts() was forgotten.

That one is valid but the chance of running into this issue is almost zero. For this to be a problem a ptmx device node must have been created on a filesystem with a custom hash function that cannot hash a three ascii char string. The only filesystem that would reject this is efivarfs because it has very specific expectations about naming. But it neither allows the creation of symlinks nor device nodes and bind-mounts of ptmx don't have that issue.

The only other candidate would be ntfs and only if an oom condition hits. But the ntfs driver can't create any files so that device node would have to preexist.

So all in all mostly an academic issue but still.

---

Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] fs: Fix error checking for d_hash_and_lookup()

      https://git.kernel.org/vfs/vfs/c/5ad699137e4a