From: Michael Bommarito <michael.bommarito@gmail.com>
To: linux-mtd@lists.infradead.org,
David Woodhouse <dwmw2@infradead.org>,
Richard Weinberger <richard@nod.at>
Cc: Zhihao Cheng <chengzhihao1@huawei.com>,
Artem Sadovnikov <a.sadovnikov@ispras.ru>,
Kees Cook <kees@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] jffs2: reject truncated summary node before header validation
Date: Wed, 15 Apr 2026 08:48:12 -0400 [thread overview]
Message-ID: <20260415124813.246588-2-michael.bommarito@gmail.com> (raw)
In-Reply-To: <20260415124813.246588-1-michael.bommarito@gmail.com>
jffs2_sum_scan_sumnode() is called from jffs2_scan_eraseblock() with
sumsize derived from the on-flash jffs2_sum_marker::offset:
sumlen = c->sector_size - je32_to_cpu(sm->offset);
A crafted flash image can set sm->offset so that
sumsize < JFFS2_SUMMARY_FRAME_SIZE
(= sizeof(struct jffs2_raw_summary) + sizeof(struct jffs2_sum_marker)
= 40, the minimum frame the writer at jffs2_sum_write_sumnode() emits
and the minimum sumlen that corresponds to a legitimate on-flash
layout). The function then reads the summary header unchecked:
crcnode.totlen = summary->totlen; /* offset +4 */
crc = crc32(0, &crcnode, sizeof(crcnode)-4);
if (je32_to_cpu(summary->hdr_crc) != crc) /* offset +8 */
goto crc_err;
if (je32_to_cpu(summary->totlen) != sumsize)
goto crc_err;
crc = crc32(0, summary, sizeof(struct jffs2_raw_summary)-8);
if (je32_to_cpu(summary->node_crc) != crc) /* offset +28 */
goto crc_err;
crc = crc32(0, summary->sum,
sumsize - sizeof(struct jffs2_raw_summary));
Each header read at offset +4, +8 and +28 of a too-small buffer is a
slab out-of-bounds read. Worse, sumsize - sizeof(struct
jffs2_raw_summary) underflows in size_t and the final crc32() walks
~16 EiB of memory, which translates to a kernel oops on mount once the
walk hits unmapped memory.
Reachable whenever a crafted JFFS2 flash image is mounted: typical in
embedded systems where flash can be rewritten out-of-band (JTAG, SPI
flasher, hostile firmware update) and the device auto-mounts JFFS2 on
boot, or any CAP_SYS_ADMIN context that supplies the MTD backing.
Bounding on JFFS2_SUMMARY_FRAME_SIZE matches the actual on-flash frame
layout the writer emits and does not reject any legitimate image.
Reproduced on v7.0-rc7 under UML + CONFIG_KASAN=y with a 16 MiB
block2mtd-backed image whose first erase block's jffs2_sum_marker
points at sector_size; pre-fix:
BUG: KASAN: slab-out-of-bounds in jffs2_sum_scan_sumnode+0x131/0x1611
Read of size 4 at addr 00000000621fb004 by task mount/31
Allocated by mtd_kmalloc_up_to via jffs2_scan_medium+0x246
Located 4 bytes to the right of allocated 4096-byte region
Post-fix the same image is rejected cleanly with a warning and mount
falls back to the full scan path.
Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com>
---
fs/jffs2/summary.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/fs/jffs2/summary.c b/fs/jffs2/summary.c
index 4521a7723f30..150a9c83cb05 100644
--- a/fs/jffs2/summary.c
+++ b/fs/jffs2/summary.c
@@ -577,6 +577,15 @@ int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb
int ret, ofs;
uint32_t crc;
+ /* Reject frames that can't hold the header + marker the writer
+ * always emits (also blocks the sumsize - sizeof(*summary)
+ * size_t underflow at the sum_crc check below). */
+ if (sumsize < JFFS2_SUMMARY_FRAME_SIZE) {
+ JFFS2_WARNING("Summary node too small (%u bytes), skipping.\n",
+ sumsize);
+ return 0;
+ }
+
ofs = c->sector_size - sumsize;
dbg_summary("summary found for 0x%08x at 0x%08x (0x%x bytes)\n",
--
2.53.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2026-04-15 12:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 12:48 [PATCH 0/2] jffs2: bound summary reads on crafted flash Michael Bommarito
2026-04-15 12:48 ` Michael Bommarito [this message]
2026-04-15 12:48 ` [PATCH 2/2] jffs2: bound summary entry walks against the payload Michael Bommarito
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=20260415124813.246588-2-michael.bommarito@gmail.com \
--to=michael.bommarito@gmail.com \
--cc=a.sadovnikov@ispras.ru \
--cc=chengzhihao1@huawei.com \
--cc=dwmw2@infradead.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
/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