mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4] jffs2: free xattr refs before deleting inode cache in jffs2_do_clear_inode
@ 2026-12-02 14:22 Tristan Madani
  0 siblings, 0 replies; only message in thread
From: Tristan Madani @ 2026-12-02 14:22 UTC (permalink / raw)
  To: David Woodhouse, Richard Weinberger
  Cc: Haris Iqbal, KaiGai Kohei, linux-mtd, linux-kernel, stable,
	Tristan Madani, syzbot+44664704c1494ad5f7a0

From: Tristan Madani <tristan@talencesecurity.com>

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@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=44664704c1494ad5f7a0
Suggested-by: Haris Iqbal <haris.iqbal@linux.dev>
Fixes: aa98d7cf59b5 ("[JFFS2][XATTR] XATTR support on JFFS2 (version. 5)")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-02 14:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02 14:22 [PATCH v4] jffs2: free xattr refs before deleting inode cache in jffs2_do_clear_inode Tristan Madani

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

all inboxes | Powered by JetHome®