[PATCH] jffs2: reset unchecked_size on summary fallback to full scan

From: Thanh Nguyen

Date: Tue Dec 01 2026 - 03:33:16 EST


In jffs2_sum_process_sum_data(), summary entries for INODE, DIRENT,
XATTR, and XREF nodes are linked via sum_link_node_ref() with
REF_UNCHECKED, which increments both c->unchecked_size and
jeb->unchecked_size while decrementing free_size.

When an unsupported compatible node type is later encountered in the
same summary, the default branch falls back to a full eraseblock scan
and restores c->free_size by (c->sector_size - jeb->free_size), while
subtracting wasted_size, used_size, and dirty_size from the superblock
counters. However, it fails to subtract jeb->unchecked_size from
c->unchecked_size or reset jeb->unchecked_size to 0.

This leaves both c->unchecked_size and jeb->unchecked_size inflated by
the previously scanned unchecked nodes, violating the space-accounting
invariant and triggering BUG() in __jffs2_dbg_acct_sanity_check_nolock().

Subtract jeb->unchecked_size from c->unchecked_size and reset
jeb->unchecked_size to 0 before calling jffs2_free_jeb_node_refs().

Fixes: 7807ef7ba2a4 ("[JFFS2] Fix summary handling of unknown but compatible nodes.")
Reported-by: syzbot+f9e8c522812e12a70ee5@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=f9e8c522812e12a70ee5
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Thanh Nguyen <thanhnguyxntester@xxxxxxxxx>
---
fs/jffs2/summary.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/fs/jffs2/summary.c b/fs/jffs2/summary.c
index 4521a7723..94d0ce7bb 100644
--- a/fs/jffs2/summary.c
+++ b/fs/jffs2/summary.c
@@ -557,7 +557,9 @@ static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eras
c->free_size += c->sector_size - jeb->free_size;
c->used_size -= jeb->used_size;
c->dirty_size -= jeb->dirty_size;
+ c->unchecked_size -= jeb->unchecked_size;
jeb->wasted_size = jeb->used_size = jeb->dirty_size = 0;
+ jeb->unchecked_size = 0;
jeb->free_size = c->sector_size;

jffs2_free_jeb_node_refs(c, jeb);
--
2.56.1