Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] jffs2: wait for INO_STATE_CLEARING in jffs2_do_read_inode()
@ 2026-12-04  5:13 Shuai Liu
  2026-12-04  5:36 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Shuai Liu @ 2026-12-04  5:13 UTC (permalink / raw)
  To: linux-mtd
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	David Woodhouse, syzbot+40179a6b1f86287d2848

A concurrent jffs2_do_read_inode() can observe an inocache in
INO_STATE_CLEARING and hit the BUG() at the end of the state switch.

jffs2_do_clear_inode() sets INO_STATE_CLEARING on the inocache before
releasing the metadata node, the fragtree and the dirents, and only
restores INO_STATE_CHECKEDABSENT afterwards.  During that window the
inocache stays on the inocache hash list, so a concurrent reader can
still find it.  Eviction is not serialized against the garbage
collector: jffs2_garbage_collect_pass() holds alloc_sem, but the final
iput() -> jffs2_evict_inode() -> jffs2_do_clear_inode() path needs no
alloc_sem, so the GC thread can iget() an inode whose in-core copy is
being cleared at that moment.  jffs2_gc_fetch_inode() then goes through
jffs2_iget() -> jffs2_do_read_inode(), which finds the inocache in
INO_STATE_CLEARING -- a state with no case in the switch -- and calls
BUG().

  kernel BUG at fs/jffs2/readinode.c:1365
  RIP: 0010:jffs2_do_read_inode+0x699/0x6a0
  Call Trace:
   jffs2_iget+0x228/0xcc0
   jffs2_gc_fetch_inode+0xd9/0x340
   jffs2_garbage_collect_pass+0x1a69/0x2170
   jffs2_garbage_collect_thread+0x693/0x720

The clearing state is transient and always ends in INO_STATE_CHECKEDABSENT
(jffs2_set_inocache_state() wakes the inocache wait queue on every
transition), so a reader can simply wait for it, exactly like it already
waits for INO_STATE_CHECKING and INO_STATE_GC.  If the inocache is removed
while waiting, the retry loop re-reads the hash and fails with -ENOENT as
it already does for a nonexistent inode.

Fixes: 67e345d17ff8 ("[JFFS2] Prevent ino cache removal for inodes in use")
Reported-by: syzbot+40179a6b1f86287d2848@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=40179a6b1f86287d2848
Signed-off-by: Shuai Liu <847807867@qq.com>
---
 fs/jffs2/readinode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index 1caabff9dc910..70df024789bdf 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -1344,7 +1344,8 @@ int jffs2_do_read_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
 
 		case INO_STATE_CHECKING:
 		case INO_STATE_GC:
-			/* If it's in either of these states, we need
+		case INO_STATE_CLEARING:
+			/* If it's in any of these states, we need
 			   to wait for whoever's got it to finish and
 			   put it back. */
 			dbg_readinode("waiting for ino #%u in state %d\n", ino, f->inocache->state);
-- 
2.43.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04  5:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  5:13 [PATCH] jffs2: wait for INO_STATE_CLEARING in jffs2_do_read_inode() Shuai Liu
2026-12-04  5:36 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox