From: Muhammad Bilal <meatuni001@gmail.com>
To: dhowells@redhat.com
Cc: David.Woodhouse@intel.com, linux-kernel@vger.kernel.org,
Muhammad Bilal <meatuni001@gmail.com>
Subject: [PATCH] romfs: reject short MTD reads in strnlen/strcmp helpers
Date: Sun, 20 Sep 2026 00:20:03 +0500 [thread overview]
Message-ID: <20260919192003.271402-1-meatuni001@gmail.com> (raw)
romfs_mtd_strnlen() and romfs_mtd_strcmp() assume each ROMFS_MTD_READ()
call fully satisfies the requested segment length. Neither checks the
returned length before using it.
If mtd_read() ever returns success with retlen 0 for a nonzero
request, romfs_mtd_strnlen() makes no progress on maxlen/pos/n and
loops forever. romfs_mtd_strcmp() decrements the size_t length by one
to drop the padding byte it asked for; with retlen 0 that underflows
to SIZE_MAX, and the following memcmp()/buf[len] run far outside the
16/17-byte stack buffers.
romfs_mtd_read() already treats "rlen != buflen" as -EIO for plain
reads; apply the same requirement here so a short read is rejected
instead of silently mishandled.
Fixes: da4458bda237 ("NOMMU: Make it possible for RomFS to use MTD devices directly")
Signed-off-by: Muhammad Bilal <meatuni001@gmail.com>
---
fs/romfs/storage.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/romfs/storage.c b/fs/romfs/storage.c
index b57b3ffcbc32..6313e218b8da 100644
--- a/fs/romfs/storage.c
+++ b/fs/romfs/storage.c
@@ -48,6 +48,8 @@ static ssize_t romfs_mtd_strnlen(struct super_block *sb,
ret = ROMFS_MTD_READ(sb, pos, segment, &len, buf);
if (ret < 0)
return ret;
+ if (len != segment)
+ return -EIO;
p = memchr(buf, 0, len);
if (p)
return n + (p - buf);
@@ -79,6 +81,8 @@ static int romfs_mtd_strcmp(struct super_block *sb, unsigned long pos,
ret = ROMFS_MTD_READ(sb, pos, segment, &len, buf);
if (ret < 0)
return ret;
+ if (len != segment)
+ return -EIO;
len--;
if (memcmp(buf, str, len) != 0)
return 0;
--
2.55.0
reply other threads:[~2026-09-19 19:20 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=20260919192003.271402-1-meatuni001@gmail.com \
--to=meatuni001@gmail.com \
--cc=David.Woodhouse@intel.com \
--cc=dhowells@redhat.com \
--cc=linux-kernel@vger.kernel.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
all inboxes | Powered by JetHome®