mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master] fs: guard against unset dentry in get_fsdevice_by_dentry
Date: Wed, 15 Apr 2026 12:39:54 +0200	[thread overview]
Message-ID: <20260415103955.3792406-1-a.fatoum@pengutronix.de> (raw)

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@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




             reply	other threads:[~2026-04-15 10:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15 10:39 Ahmad Fatoum [this message]
2026-04-15 12:08 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260415103955.3792406-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox