mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arbab Haider <arbabhaider649@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: Eric Sandeen <sandeen@redhat.com>,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+1d23ad199a3bfd6f9149@syzkaller.appspotmail.com,
	stable@vger.kernel.org, Arbab Haider <arbabhaider649@gmail.com>
Subject: [PATCH] ext2: handle NULL fc->source in ext2_msg_fc()
Date: Sun, 22 Nov 2026 23:23:31 +0500	[thread overview]
Message-ID: <20261122182331.13740-2-arbabhaider649@gmail.com> (raw)

With the new mount API (fsopen()/fsconfig()), userspace can pass mount
options such as "nobh", "dax", or "reservation" before setting the
"source" parameter, leaving fc->source as NULL during option parsing.

In ext2_msg_fc(), when fc->purpose != FS_CONTEXT_FOR_RECONFIGURE,
strrchr(fc->source, '/') is called unconditionally without checking if
fc->source is non-NULL, causing a kernel NULL pointer dereference:

  KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
  RIP: 0010:strrchr+0x24/0x80
  ext2_msg_fc+0x157/0x1e3

Check fc->source before calling strrchr(), and omit the "(%s)" device
prefix when s_id is NULL or empty (e.g., when source is unset, empty,
or ends with '/').

Tested locally in QEMU (x86_64, KASAN+UBSAN) using fsopen()/fsconfig()
with NULL, empty, trailing-slash, relative, and full-path sources.

Reported-by: syzbot+1d23ad199a3bfd6f9149@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=1d23ad199a3bfd6f9149
Fixes: 98f18c76c2c3 ("ext2: create ext2_msg_fc for use during parsing")
Cc: stable@vger.kernel.org
Signed-off-by: Arbab Haider <arbabhaider649@gmail.com>
---
 fs/ext2/super.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 54a6c26d0..c99367652 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -89,20 +89,25 @@ static void ext2_msg_fc(struct fs_context *fc, const char *prefix,
 
 	if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) {
 		s_id = fc->root->d_sb->s_id;
-	} else {
+	} else if (fc->source) {
 		/* get last path component of source */
 		s_id = strrchr(fc->source, '/');
 		if (s_id)
 			s_id++;
 		else
 			s_id = fc->source;
+	} else {
+		s_id = NULL;
 	}
 	va_start(args, fmt);
 
 	vaf.fmt = fmt;
 	vaf.va = &args;
 
-	printk("%sEXT2-fs (%s): %pV\n", prefix, s_id, &vaf);
+	if (s_id && *s_id)
+		printk("%sEXT2-fs (%s): %pV\n", prefix, s_id, &vaf);
+	else
+		printk("%sEXT2-fs: %pV\n", prefix, &vaf);
 
 	va_end(args);
 }
-- 
2.53.0


                 reply	other threads:[~2026-11-22 18:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261122182331.13740-2-arbabhaider649@gmail.com \
    --to=arbabhaider649@gmail.com \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sandeen@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+1d23ad199a3bfd6f9149@syzkaller.appspotmail.com \
    /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

all inboxes | Powered by JetHome®