[PATCH master] fs: guard against unset dentry in get_fsdevice_by_dentry

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Apr 15 03:39:54 PDT 2026


dentry exists embedded within struct path and may not be initialized at
all places we call get_fsdevice_by_dentry().

Allow handling this gracefully by having the function return NULL
instead of dereferencing potential NULL pointers.

This issue has been detected in combination with the
"fs: fix relative path resolution when CWD is on a TFTP mount" patch
sitting in next, where the MLO runs into the NULL pointer dereference.
It has not been observed in other  configurations.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 fs/fs.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 6a73a5baa26e..c28192cb8260 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2099,9 +2099,12 @@ static void putname(struct filename *name)
 
 static struct fs_device *get_fsdevice_by_dentry(struct dentry *dentry)
 {
-	struct super_block *sb;
+	struct super_block *sb = NULL;
 
-	sb = dentry->d_sb;
+	if (dentry)
+		sb = dentry->d_sb;
+	if (!sb)
+		return NULL;
 
 	return container_of(sb, struct fs_device, sb);
 }
-- 
2.47.3




More information about the barebox mailing list