[PATCH v4] jffs2: free xattr refs before deleting inode cache in jffs2_do_clear_inode
From: Tristan Madani
Date: Wed Dec 02 2026 - 09:22:46 EST
From: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
jffs2_del_ino_cache() triggers BUG_ON(old->xref) when an inode cache
entry still has xattr references. This can happen during unmount:
generic_shutdown_super() calls evict_inodes() before put_super(), but
jffs2_evict_inode -> jffs2_do_clear_inode -> jffs2_xattr_delete_inode
only clears xrefs when pino_nlink == 0. For inodes with nlink > 0
at unmount time, xrefs survive past eviction, and the subsequent
jffs2_del_ino_cache() hits the BUG_ON.
Call jffs2_xattr_free_inode() just before jffs2_del_ino_cache() in
jffs2_do_clear_inode(), where no spinlock is held and the semaphore
in jffs2_xattr_free_inode() can safely sleep. This cleans up the
remaining xrefs for inodes whose nlink was still positive at unmount.
The earlier jffs2_xattr_delete_inode() call at the top of
jffs2_do_clear_inode() already handles the nlink == 0 case by writing
delete markers to flash; jffs2_xattr_free_inode() handles the
remaining entries without writing to flash, which is appropriate
since the flash state is reconstructed by the next mount scan.
Reported-by: syzbot+44664704c1494ad5f7a0@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=44664704c1494ad5f7a0
Suggested-by: Haris Iqbal <haris.iqbal@xxxxxxxxx>
Fixes: aa98d7cf59b5 ("[JFFS2][XATTR] XATTR support on JFFS2 (version. 5)")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
---
Changes in v4:
- Move jffs2_xattr_free_inode() call from jffs2_del_ino_cache() (which
can be called under spinlock) to jffs2_do_clear_inode() (which holds
only the inode mutex), avoiding sleeping-in-atomic (Richard Weinberger).
- Use Haris Iqbal's approach of placing the call just before
jffs2_del_ino_cache() inside the nodes-exhausted check (Haris Iqbal).
- Dropped patches 1/3 and 3/3 from the original series; this v4 is a
standalone single patch replacing the entire series.
Changes in v3:
- Replace BUG_ON with jffs2_xattr_free_inode() call (v2 downgrade to
WARN still triggered syzbot).
Changes in v2:
- Downgrade BUG_ON to WARN_ON_ONCE (dropped in v3).
fs/jffs2/readinode.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index 1caabff9dc910..9ff780e5f65f1 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -1439,8 +1439,10 @@ void jffs2_do_clear_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f)
if (f->inocache && f->inocache->state != INO_STATE_CHECKING) {
jffs2_set_inocache_state(c, f->inocache, INO_STATE_CHECKEDABSENT);
- if (f->inocache->nodes == (void *)f->inocache)
+ if (f->inocache->nodes == (void *)f->inocache) {
+ jffs2_xattr_free_inode(c, f->inocache);
jffs2_del_ino_cache(c, f->inocache);
+ }
}
mutex_unlock(&f->sem);
--
2.47.3