From: FredTheDude <FredTheDude@proton.me>
To: "sfrench@samba.org" <sfrench@samba.org>
Cc: "linux-cifs@vger.kernel.org" <linux-cifs@vger.kernel.org>
Subject: [PATCH] fs/smb/client: fix out-of-bounds read in cifs_sanitize_prepath
Date: Mon, 30 Mar 2026 21:10:14 +0000 [thread overview]
Message-ID: <f6jyHqZ0Ycp1KP50Nf0K6QULaw7WbojZIPK4NrYYw6zNoj93MvpecYMT0xE5mjChSgdLhieKk9rpjUDjWtY73UAjwFGS85VxlkO4yJuEInE=@proton.me> (raw)
When cifs_sanitize_prepath is called with an empty string or a string
containing only delimiters (e.g., "/"), the current logic attempts to
check *(cursor2 - 1) before cursor2 has advanced. This results in an
out-of-bounds read.
This patch adds an early exit check after stripping prepended
delimiters. If no path content remains, the function returns NULL.
The bug was identified via manual audit and verified using a
standalone test case compiled with AddressSanitizer, which
triggered a SEGV on affected inputs.
Signed-off-by: Fredric Cover <FredTheDude@proton.me>
---
If I made any stupid mistakes, let me know.
I am just a high-school freshman, and I have a lot to learn, especially in C.
Thanks for taking your time to look at my patch.
---
fs/smb/client/fs_context.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/smb/client/fs_context.c b/fs/smb/client/fs_context.c
index 03c112f4d..3f0faae99 100644
--- a/fs/smb/client/fs_context.c
+++ b/fs/smb/client/fs_context.c
@@ -588,6 +588,10 @@ char *cifs_sanitize_prepath(char *prepath, gfp_t gfp)
while (IS_DELIM(*cursor1))
cursor1++;
+ /* exit in case of only delimiters */
+ if (!*cursor1)
+ return NULL;
+
/* copy the first letter */
*cursor2 = *cursor1;
--
2.43.0
next reply other threads:[~2026-03-30 21:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 21:10 FredTheDude [this message]
2026-03-31 21:03 ` [PATCH] fs/smb/client: fix out-of-bounds read in cifs_sanitize_prepath Henrique Carvalho
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='f6jyHqZ0Ycp1KP50Nf0K6QULaw7WbojZIPK4NrYYw6zNoj93MvpecYMT0xE5mjChSgdLhieKk9rpjUDjWtY73UAjwFGS85VxlkO4yJuEInE=@proton.me' \
--to=fredthedude@proton.me \
--cc=linux-cifs@vger.kernel.org \
--cc=sfrench@samba.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).