Re: [PATCH 2/2] jffs2: bound summary entry walks against the payload

From: Richard Weinberger

Date: Tue Dec 01 2026 - 17:27:27 EST


On Mittwoch, 15. April 2026 14:48 Michael Bommarito wrote:
> jffs2_sum_process_sum_data() iterates summary->sum_num times, reading
> the next entry's nodetype from the current sp and dispatching into
> type-specific handlers that advance sp by a fixed or nsize-dependent
> amount. There is no upper bound on sum_num from the writer side, and
> on read the scanner trusts the on-flash value unchecked.
>
> A crafted flash image can therefore set sum_num > (actual entries
> that fit in the payload). Once sp runs off the end of the summary
> buffer the nodetype read at summary.c:407 lands on adjacent slab
> memory. If those bytes happen to decode as one of the known types
> (JFFS2_NODETYPE_INODE / _DIRENT / _XATTR / _XREF) the handler calls
> sum_link_node_ref() with offset / totlen pulled from whatever slab
> neighbor is next to the scan buffer.
>
> Reproduced on v7.0-rc7 under UML + CONFIG_KASAN=y with a crafted
> image carrying one real INODE entry and sum_num=2:
>
> BUG: KASAN: slab-out-of-bounds in jffs2_sum_scan_sumnode+0x6bd
> Read of size 2 at addr 00000000621fb000 by task mount/31
> Located 0 bytes to the right of allocated 4096-byte region
>
> The matching sum_num=1 image (same bytes, honest sum_num) mounts
> without a KASAN report, so the OOB is sum_num-specific.
>
> Pass sumsize into jffs2_sum_process_sum_data() and bound sp against
> summary + sumsize - sizeof(struct jffs2_sum_marker) before every
> nodetype read and before every type-specific field access. If the
> advance would leave the payload, warn and fall back to a full scan
> via -ENOTRECOVERABLE.

I fear this is not correct. If you return -ENOTRECOVERABLE you have
to undo first everything what the summary code did before.
See the existing -ENOTRECOVERABLE case, it resets the counters and
calls jffs2_free_jeb_node_refs().

Thanks,
//richard

--
​​​​​sigma star gmbh | Eduard-Bodem-Gasse 6, 6020 Innsbruck, AUT UID/VAT Nr:
ATU 66964118 | FN: 374287y