kernel BUG in __jffs2_dbg_acct_sanity_check_nolock

Status: moderation: reported on 2026/11/29 22:16
Subsystems: jffs2
Labels: prio:normal
[Documentation on labels]
Reported-by: syzbot+f9e8c522812e12a70ee5@syzkaller.appspotmail.com
First crash: 1h21m, last: 1h21m
✨ AI cause bisection: introduced by (AI job) :
commit 7807ef7ba2a41c05f6197381f572dd38baa6c1ce
Author: David Woodhouse <dwmw2@infradead.org>
Date: Sun May 21 02:45:27 2006 +0000

  [JFFS2] Fix summary handling of unknown but compatible nodes.

✨ AI-generated root cause summary:

In jffs2_sum_process_sum_data() (fs/jffs2/summary.c), when an eraseblock summary contains REF_UNCHECKED entries followed by an unsupported compatible node type (default: branch), the fallback-to-full-scan rollback restores c->free_size by c->sector_size - jeb->free_size and subtracts jeb->wasted_size, jeb->used_size, and jeb->dirty_size from the superblock counters, but forgets to subtract jeb->unchecked_size from c->unchecked_size or reset jeb->unchecked_size = 0. This leaves both c->unchecked_size and jeb->unchecked_size inflated by the previously scanned unchecked nodes (0x0b60 bytes in this report, making the superblock sum 0x020b60 != 0x020000). Because jffs2_dbg_acct_paranoia_check_nolock() is disabled when CONFIG_JFFS2_FS_DEBUG=0, scanning completes silently until jffs2_build_xattr_subsystem() later finds a corrupted xref node in another eraseblock and calls jffs2_mark_node_obsolete(), which invokes __jffs2_dbg_acct_sanity_check_nolock() (fs/jffs2/debug.c:47) and hits BUG().

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 4f069ab1ec24:

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.)

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
53e8b2ef bisect-cause IsRelease: ❌ ❓ kernel BUG in __jffs2_dbg_acct_sanity_check_nolock 2026/11/29 21:48 2026/11/29 21:48 2026/11/29 21:56 e1f06033
20a25ee6 assessment-security DenialOfService: ✅ Exploitable: ❌ FilesystemTrigger: ✅ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ kernel BUG in __jffs2_dbg_acct_sanity_check_nolock 2026/11/29 21:34 2026/11/29 21:34 2026/11/29 22:15 e1f06033

Sample crash report:
jffs2: error: (10291) verify_xattr_ref: node CRC failed at 0x014c90, read=0xf5b51bf7, calc=0xc505f375
jffs2: error: (10291) __jffs2_dbg_acct_sanity_check_nolock: eeep, space accounting superblock info is screwed.
jffs2: error: (10291) __jffs2_dbg_acct_sanity_check_nolock: free 0x003b9c + dirty 0x009000 + used 0x003828 + erasing 0x000000 + bad 0x000000 + wasted 0x00001c + unchecked 0x010780 != total 0x020000.
------------[ cut here ]------------
kernel BUG at fs/jffs2/debug.c:47!
Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
CPU: 0 UID: 0 PID: 10291 Comm: syz.0.954 Tainted: G             L      syzkaller #0 PREEMPT(full) 
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
RIP: 0010:__jffs2_dbg_acct_sanity_check_nolock.cold+0x409/0x540 fs/jffs2/debug.c:47
Code: 00 42 54 8c 8b 44 24 08 48 c7 c7 40 41 54 8c 50 8b 44 24 18 50 8b 44 24 38 50 8b 44 24 38 50 44 8b 4c 24 38 e8 1f ad f8 ff 90 <0f> 0b e8 b7 c1 5f 01 e9 1d fc ff ff 4c 89 e7 89 4c 24 20 e8 a6 c1
RSP: 0018:ffffc900052df7f8 EFLAGS: 00010282
RAX: 00000000000000c6 RBX: ffff888038134000 RCX: 0000000000000000
RDX: 00000000000000c6 RSI: ffffffff81ec5519 RDI: fffff52000a5bef0
RBP: ffff88803813416c R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000200 R11: 0000000000000001 R12: 0000000000009000
R13: ffff88803560abc0 R14: ffff88803560a580 R15: 0000000000020000
FS:  00007f906e8176c0(0000) GS:ffff88812245c000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fa593cade14 CR3: 00000000764eb000 CR4: 00000000003526f0
Call Trace:
 <TASK>
 jffs2_mark_node_obsolete+0x37b/0x1330 fs/jffs2/nodemgmt.c:682
 jffs2_build_xattr_subsystem.cold+0xcf/0x229 fs/jffs2/xattr.c:800
 jffs2_build_filesystem fs/jffs2/build.c:214 [inline]
 jffs2_do_mount_fs+0x16a8/0x22f0 fs/jffs2/build.c:416
 jffs2_do_fill_super+0x3d4/0xa60 fs/jffs2/fs.c:574
 jffs2_fill_super+0x283/0x370 fs/jffs2/super.c:290
 mtd_get_sb+0x2f9/0x4d0 drivers/mtd/mtdsuper.c:59
 mtd_get_sb_by_nr drivers/mtd/mtdsuper.c:90 [inline]
 get_tree_mtd+0x6f9/0x8a0 drivers/mtd/mtdsuper.c:143
 vfs_get_tree+0x92/0x320 fs/super.c:1881
 fc_mount fs/namespace.c:1282 [inline]
 do_new_mount_fc fs/namespace.c:3910 [inline]
 do_new_mount fs/namespace.c:3986 [inline]
 path_mount+0x7d0/0x2850 fs/namespace.c:4337
 do_mount fs/namespace.c:4350 [inline]
 __do_sys_mount fs/namespace.c:4563 [inline]
 __se_sys_mount fs/namespace.c:4540 [inline]
 __x64_sys_mount+0x293/0x310 fs/namespace.c:4540
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x123/0x7b0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f906d9a9b59
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f906e817028 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007f906dc35fa0 RCX: 00007f906d9a9b59
RDX: 0000200000000600 RSI: 00002000000005c0 RDI: 0000200000000580
RBP: 00007f906da3a18b R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000800000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f906dc36038 R14: 00007f906dc35fa0 R15: 00007ffedc9d04a8
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:__jffs2_dbg_acct_sanity_check_nolock.cold+0x409/0x540 fs/jffs2/debug.c:47
Code: 00 42 54 8c 8b 44 24 08 48 c7 c7 40 41 54 8c 50 8b 44 24 18 50 8b 44 24 38 50 8b 44 24 38 50 44 8b 4c 24 38 e8 1f ad f8 ff 90 <0f> 0b e8 b7 c1 5f 01 e9 1d fc ff ff 4c 89 e7 89 4c 24 20 e8 a6 c1
RSP: 0018:ffffc900052df7f8 EFLAGS: 00010282
RAX: 00000000000000c6 RBX: ffff888038134000 RCX: 0000000000000000
RDX: 00000000000000c6 RSI: ffffffff81ec5519 RDI: fffff52000a5bef0
RBP: ffff88803813416c R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000200 R11: 0000000000000001 R12: 0000000000009000
R13: ffff88803560abc0 R14: ffff88803560a580 R15: 0000000000020000
FS:  00007f906e8176c0(0000) GS:ffff88812245c000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fa593cade14 CR3: 00000000764eb000 CR4: 00000000003526f0

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/29 21:34 upstream 4f069ab1ec24 e1f06033 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-selinux-root kernel BUG in __jffs2_dbg_acct_sanity_check_nolock
* Struck through repros no longer work on HEAD.