kernel BUG in jffs2_do_read_inode

Status: moderation: reported on 2026/12/02 07:16
Subsystems: jffs2
Labels: prio:normal
[Documentation on labels]
Reported-by: syzbot+6dfb1c4676ceb40c9f46@syzkaller.appspotmail.com
First crash: 46m, last: 46m
✨ AI cause bisection: introduced by (AI job) :
commit 67e345d17ff8c2085a54c293001ae548f7be7b21
Author: David Woodhouse <dwmw2@infradead.org>
Date: Sun Feb 27 23:01:36 2005 +0000

  [JFFS2] Prevent ino cache removal for inodes in use

✨ AI-generated root cause summary:

jffs2_do_read_inode() in fs/jffs2/readinode.c does not handle INO_STATE_CLEARING (state 6) in its switch (f->inocache->state) statement and falls into default: BUG(); at line 1365. When iget_failed() runs on a JFFS2 inode (e.g., after a failed jffs2_iget() or failed creation in jffs2_create()/jffs2_mkdir()/jffs2_symlink()/jffs2_mknod()), make_bad_inode() unhashes the VFS inode before iput() invokes jffs2_evict_inode() -> jffs2_do_clear_inode(), bypassing VFS __wait_on_freeing_inode() serialization. A concurrent jffs2_garbage_collect_pass() (which also omits INO_STATE_CLEARING from its switch (ic->state) at fs/jffs2/gc.c:365) can then call jffs2_gc_fetch_inode() -> jffs2_iget() -> jffs2_do_read_inode() while the inocache is in INO_STATE_CLEARING, triggering the BUG().

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 693c2e04e3f1:

Root Cause

The crash at fs/jffs2/readinode.c:1365 occurs because jffs2_do_read_inode() (and jffs2_garbage_collect_pass()) fails to handle the INO_STATE_CLEARING (6) state of struct jffs2_inode_cache::state (which matches R09/R12 = 6 in the crash register dump).

1. Missing INO_STATE_CLEARING handling in jffs2_do_read_inode() and jffs2_garbage_collect_pass()

In fs/jffs2/nodelist.h:188-194, JFFS2 defines seven INO_STATE_* values, including INO_STATE_CLEARING (6). However:

  • In fs/jffs2/readinode.c:1339-1366, jffs2_do_read_inode() switches on f->inocache->state under c->inocache_lock:

    • INO_STATE_UNCHECKED, INO_STATE_CHECKEDABSENT -> transitions to INO_STATE_READING
    • INO_STATE_CHECKING, INO_STATE_GC -> sleeps on c->inocache_wq and retries
    • INO_STATE_READING, INO_STATE_PRESENT -> logs an error and sets f->inocache = NULL
    • default: -> hits BUG(); at fs/jffs2/readinode.c:1365

    INO_STATE_CLEARING is not handled anywhere in this switch, so observing f->inocache->state == INO_STATE_CLEARING triggers BUG().

  • Similarly, in fs/jffs2/gc.c:365-419, jffs2_garbage_collect_pass() switches on ic->state after choosing a node to garbage-collect. While it waits on c->inocache_wq for INO_STATE_READING and BUG()s on INO_STATE_UNCHECKED/INO_STATE_CHECKING/INO_STATE_GC, it omits INO_STATE_CLEARING and has no default: branch. Thus, when ic->state == INO_STATE_CLEARING, GC silently falls out of the switch, drops c->inocache_lock, and calls jffs2_gc_fetch_inode(c, inum, !nlink) (fs/jffs2/gc.c:454) -> jffs2_iget() (fs/jffs2/fs.c:673) -> jffs2_do_read_inode() (fs/jffs2/fs.c:277). (Note that the CRC-check loop earlier in jffs2_garbage_collect_pass() at fs/jffs2/gc.c:198-230 also hits default: BUG() on INO_STATE_CLEARING.)

2. How jffs2_do_read_inode() observes INO_STATE_CLEARING

Normally, VFS inode eviction (evict() in fs/inode.c:798-854) invokes op->evict_inode(inode) -> jffs2_evict_inode() (fs/jffs2/fs.c:238) -> jffs2_do_clear_inode() (fs/jffs2/readinode.c:1413) before calling remove_inode_hash(inode). While jffs2_do_clear_inode() holds f->inocache->state in INO_STATE_CLEARING (between fs/jffs2/readinode.c:1423 and 1441), the struct inode remains in inode_hashtable with I_FREEING set, so any concurrent iget_locked() waits in __wait_on_freeing_inode() until eviction finishes.

However, iget_failed() (fs/bad_inode.c:245-250) breaks that assumption:

void iget_failed(struct inode *inode)
{
    make_bad_inode(inode);  /* calls remove_inode_hash(inode) */
    unlock_new_inode(inode);
    iput(inode);            /* calls evict() -> jffs2_evict_inode() -> jffs2_do_clear_inode() */
}

JFFS2 calls iget_failed(inode) on error paths in:

  • jffs2_iget() (fs/jffs2/fs.c:368) when jffs2_do_read_inode() or jffs2_read_dnode() fails (e.g., on a corrupted flash node),
  • jffs2_create(), jffs2_symlink(), jffs2_mkdir(), and jffs2_mknod() (fs/jffs2/dir.c:222, 446, 590, 768) when creation fails after jffs2_new_inode(), and similarly make_bad_inode() + iput() in jffs2_new_inode() (fs/jffs2/fs.c:486-487) if insert_inode_locked() fails.

Because make_bad_inode(inode) removes inode from inode_hashtable before iput(inode) triggers jffs2_evict_inode() -> jffs2_do_clear_inode():

  1. Thread A runs jffs2_do_clear_inode(c, f) without holding c->alloc_sem and sets f->inocache->state = INO_STATE_CLEARING (fs/jffs2/readinode.c:1423) while freeing f->metadata, f->fragtree, and f->dents before setting INO_STATE_CHECKEDABSENT and waking c->inocache_wq at line 1441.
  2. Concurrently, jffs2_gcd_mtd0 runs jffs2_garbage_collect_pass(), sees ic->state == INO_STATE_CLEARING (with ic->pino_nlink != 0), falls through the switch at fs/jffs2/gc.c:365, and calls jffs2_gc_fetch_inode() -> jffs2_iget().
  3. Because inode was already unhashed by make_bad_inode(), iget_locked() does not find the freeing inode in inode_hashtable, allocates a new I_NEW inode, and calls jffs2_do_read_inode().
  4. jffs2_do_read_inode() looks up f->inocache in c->inocache_list, observes f->inocache->state == INO_STATE_CLEARING, and hits BUG() at fs/jffs2/readinode.c:1365.

Fix Direction

Both jffs2_do_read_inode() (fs/jffs2/readinode.c:1345) and jffs2_garbage_collect_pass() (fs/jffs2/gc.c:211 and fs/jffs2/gc.c:397) should treat INO_STATE_CLEARING as a transient state to wait on via sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock) (matching INO_STATE_CHECKING/INO_STATE_GC in jffs2_do_read_inode() and INO_STATE_READING in jffs2_garbage_collect_pass()), since jffs2_do_clear_inode() wakes c->inocache_wq via jffs2_set_inocache_state() when transitioning out of INO_STATE_CLEARING.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
04b4d0fa bisect-cause IsRelease: ❌ ❓ kernel BUG in jffs2_do_read_inode 2026/12/02 07:26 2026/12/02 07:26 2026/12/02 07:40 35891725
336736d2 assessment-security DenialOfService: ✅ Exploitable: ❌ FilesystemTrigger: ✅ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ kernel BUG in jffs2_do_read_inode 2026/12/02 07:10 2026/12/02 07:10 2026/12/02 07:16 35891725

Sample crash report:
------------[ cut here ]------------
kernel BUG at fs/jffs2/readinode.c:1365!
Oops: invalid opcode: 0000 [#1] SMP KASAN PTI
CPU: 1 UID: 0 PID: 10842 Comm: jffs2_gcd_mtd0 Not tainted syzkaller #0 PREEMPT_{RT,(full)} 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
RIP: 0010:jffs2_do_read_inode+0x699/0x6a0 fs/jffs2/readinode.c:1365
Code: f5 fe e9 ab fe ff ff 89 d9 80 e1 07 80 c1 03 38 c1 0f 8c fd fe ff ff 48 89 df e8 02 83 f5 fe e9 f0 fe ff ff e8 98 78 81 fe 90 <0f> 0b 0f 1f 44 00 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90
RSP: 0000:ffffc90004b97740 EFLAGS: 00010293
RAX: ffffffff8346a078 RBX: 1ffff1100582914a RCX: ffff88802fa1be80
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
RBP: ffffc90004b97870 R08: ffff88802fa1be80 R09: 0000000000000006
R10: 0000000000000100 R11: 0000000000000005 R12: 0000000000000006
R13: 1ffff92000972ef4 R14: dffffc0000000000 R15: ffff88802c148a52
FS:  0000000000000000(0000) GS:ffff8881247fa000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b342ccff8 CR3: 0000000072e72000 CR4: 00000000003526f0
DR0: 0000000000000008 DR1: 0000000000000007 DR2: 0000000000000004
DR3: 0000000000000008 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Call Trace:
 <TASK>
 jffs2_iget+0x228/0xcc0 fs/jffs2/fs.c:277
 jffs2_gc_fetch_inode+0xd9/0x340 fs/jffs2/fs.c:673
 jffs2_garbage_collect_pass+0x1a69/0x2170 fs/jffs2/gc.c:454
 jffs2_garbage_collect_thread+0x693/0x720 fs/jffs2/background.c:155
 kthread+0x38b/0x470 kernel/kthread.c:436
 ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:jffs2_do_read_inode+0x699/0x6a0 fs/jffs2/readinode.c:1365
Code: f5 fe e9 ab fe ff ff 89 d9 80 e1 07 80 c1 03 38 c1 0f 8c fd fe ff ff 48 89 df e8 02 83 f5 fe e9 f0 fe ff ff e8 98 78 81 fe 90 <0f> 0b 0f 1f 44 00 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90
RSP: 0000:ffffc90004b97740 EFLAGS: 00010293
RAX: ffffffff8346a078 RBX: 1ffff1100582914a RCX: ffff88802fa1be80
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
RBP: ffffc90004b97870 R08: ffff88802fa1be80 R09: 0000000000000006
R10: 0000000000000100 R11: 0000000000000005 R12: 0000000000000006
R13: 1ffff92000972ef4 R14: dffffc0000000000 R15: ffff88802c148a52
FS:  0000000000000000(0000) GS:ffff8881247fa000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000055b7581d3f40 CR3: 0000000035b8c000 CR4: 00000000003526f0
DR0: 0000000000000008 DR1: 0000000000000007 DR2: 0000000000000004
DR3: 0000000000000008 DR6: 00000000ffff0ff0 DR7: 0000000000000400

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/12/02 07:10 upstream 693c2e04e3f1 35891725 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-smack-root kernel BUG in jffs2_do_read_inode
* Struck through repros no longer work on HEAD.