[PATCH 5/9] fs: allow trailing symlinks pointing to the root directory

Sascha Hauer s.hauer at pengutronix.de
Tue Oct 20 00:09:30 PDT 2026


When the target of a trailing symlink consists only of slashes,
get_link() moves the lookup to the root directory and returns NULL, and
trailing_symlink() hands an empty remaining path to link_path_walk().
link_path_walk() rejects it with -ENOENT, so any lookup of such a link
fails:

  ln -s / /tmp/root
  ls /tmp/root      -> No such file or directory

The -ENOENT was added in commit 74946415a5 ("fs: Fix link_path_walk to
return -ENOENT on empty path") to fix a crash with 'cat ""'. Shortly
after, commit ef98a567d7 ("fs: check for empty name in getname()")
started rejecting empty names in getname(), which all lookups go through,
so the empty path from a symlink is the only one that still reaches
link_path_walk(). Drop the check again, as Linux does. 'cat ""' still
fails with -ENOENT, from getname().

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 fs/fs.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index edb68cf455..40dc32b3c4 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2195,8 +2195,6 @@ static int link_path_walk(const char *name, struct nameidata *nd)
 	int err;
 	char separator = '/';
 
-	if (!*name)
-		return -ENOENT;
 	while (*name=='/')
 		name++;
 	if (!*name)

-- 
2.47.3




More information about the barebox mailing list