Root Cause
The superblock space-accounting mismatch is caused by an incomplete rollback in jffs2_sum_process_sum_data() (fs/jffs2/summary.c:549-565) when falling back from summary scanning to a full eraseblock scan.
1. How the Accounting Invariant Is Violated (fs/jffs2/summary.c)
During mount (jffs2_do_mount_fs() -> jffs2_build_filesystem() -> jffs2_scan_medium()), c->free_size is initialized to c->flash_size and each struct jffs2_eraseblock's free_size is initialized to c->sector_size.
When CONFIG_JFFS2_SUMMARY=y is enabled, jffs2_scan_eraseblock() calls jffs2_sum_scan_sumnode() -> jffs2_sum_process_sum_data() (fs/jffs2/summary.c:386) to process summary items in an eraseblock:
- For
JFFS2_NODETYPE_INODE, JFFS2_NODETYPE_DIRENT, JFFS2_NODETYPE_XATTR, and JFFS2_NODETYPE_XREF, jffs2_sum_process_sum_data() links nodes via sum_link_node_ref() -> jffs2_link_node_ref() (fs/jffs2/nodelist.c:585) with the REF_UNCHECKED flag (0).
jffs2_link_node_ref() accounts REF_UNCHECKED nodes by incrementing c->unchecked_size and jeb->unchecked_size by len and decrementing c->free_size and jeb->free_size by len.
- Any preceding alignment/gap space is marked dirty via
jffs2_scan_dirty_space().
If jffs2_sum_process_sum_data() subsequently encounters an unsupported compatible node type (not matching JFFS2_FEATURE_INCOMPAT), it enters the default: branch (fs/jffs2/summary.c:549-565) and attempts to undo the eraseblock's partial accounting before returning -ENOTRECOVERABLE (which causes jffs2_sum_scan_sumnode() to return 0 and jffs2_scan_eraseblock() to fall back to full_scan:):
/* For compatible node types, just fall back to the full scan */
c->wasted_size -= jeb->wasted_size;
c->free_size += c->sector_size - jeb->free_size;
c->used_size -= jeb->used_size;
c->dirty_size -= jeb->dirty_size;
jeb->wasted_size = jeb->used_size = jeb->dirty_size = 0;
jeb->free_size = c->sector_size;
jffs2_free_jeb_node_refs(c, jeb);
return -ENOTRECOVERABLE;
Here, c->sector_size - jeb->free_size equals jeb->wasted_size + jeb->used_size + jeb->dirty_size + jeb->unchecked_size. Because the rollback adds c->sector_size - jeb->free_size back to c->free_size and subtracts wasted_size, used_size, and dirty_size from c, while omitting c->unchecked_size -= jeb->unchecked_size and jeb->unchecked_size = 0, both c->unchecked_size and jeb->unchecked_size retain the previously accumulated unchecked node bytes (0x0b60 in this crash). The subsequent full_scan: then adds the eraseblock's actual node sizes on top of those stale unchecked_size values.
All other accounting updates reachable during jffs2_do_mount_fs() perform balanced transfers (c->X_size -= delta; c->Y_size += delta;), preserving the c->used_size + c->dirty_size + c->free_size + c->erasing_size + c->bad_size + c->wasted_size + c->unchecked_size == c->flash_size invariant. (Note that JFFS2_WARNING in the default: branch has loglevel KERN_WARNING, so it does not appear on a console with quiet loglevel 4, unlike JFFS2_ERROR / KERN_ERR.)
2. Why the Failure Manifests Later in jffs2_build_xattr_subsystem()
- During
jffs2_scan_medium(), only jffs2_dbg_acct_paranoia_check_nolock() is called, which is a no-op when CONFIG_JFFS2_FS_DEBUG=0, so the +0x0b60 discrepancy goes unnoticed during scanning.
- Another eraseblock (containing offset
0x014c90) is scanned via summary with a JFFS2_NODETYPE_XREF node at 0x014c90, linked with REF_UNCHECKED. That block's own jeb accounting sums consistently to c->sector_size.
- During
jffs2_build_xattr_subsystem() (fs/jffs2/xattr.c:796-803), verify_xattr_ref() (fs/jffs2/xattr.c:444) checks the XREF node at 0x014c90 because ref_flags(ref->node) != REF_PRISTINE. Its CRC check fails (read=0xf5b51bf7, calc=0xc505f375), returning JFFS2_XATTR_IS_CORRUPTED.
jffs2_build_xattr_subsystem() then calls jffs2_mark_node_obsolete(c, ref->node) (fs/jffs2/xattr.c:800), which invokes jffs2_dbg_acct_sanity_check_nolock(c, jeb) (fs/jffs2/nodemgmt.c:682).
- Unlike
paranoia_check, JFFS2_DBG_SANITY_CHECKS (fs/jffs2/debug.h) is enabled unconditionally. In __jffs2_dbg_acct_sanity_check_nolock() (fs/jffs2/debug.c:31-48), the per-block check on the 0x014c90 jeb passes, and the superblock check detects 0x003b9c + 0x009000 + 0x003828 + 0x00001c + 0x010780 = 0x020b60 != 0x020000, triggering BUG() at fs/jffs2/debug.c:47.
Fix
In jffs2_sum_process_sum_data() (fs/jffs2/summary.c), the default: fallback must also subtract jeb->unchecked_size from c->unchecked_size and reset jeb->unchecked_size = 0 before calling jffs2_free_jeb_node_refs(c, jeb). (In addition, note that DIRENT / XATTR / XREF summary items processed prior to hitting default: in the same block may already have queued jffs2_full_dirent or jffs2_xattr_ref allocations referencing the soon-to-be-freed jffs2_raw_node_ref entries, which should also be audited when fixing this fallback path.)