From: Tristan Madani <tristmd@gmail.com>
To: David Woodhouse <dwmw2@infradead.org>,
Richard Weinberger <richard@nod.at>
Cc: Haris Iqbal <haris.iqbal@linux.dev>,
KaiGai Kohei <kaigai@ak.jp.nec.com>,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org,
Tristan Madani <tristan@talencesecurity.com>,
syzbot+44664704c1494ad5f7a0@syzkaller.appspotmail.com
Subject: [PATCH v4] jffs2: free xattr refs before deleting inode cache in jffs2_do_clear_inode
Date: Wed, 2 Dec 2026 14:22:29 +0000 [thread overview]
Message-ID: <20261202142230.2786265-1-tristmd@gmail.com> (raw)
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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
reply other threads:[~2026-12-02 14:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202142230.2786265-1-tristmd@gmail.com \
--to=tristmd@gmail.com \
--cc=dwmw2@infradead.org \
--cc=haris.iqbal@linux.dev \
--cc=kaigai@ak.jp.nec.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
--cc=stable@vger.kernel.org \
--cc=syzbot+44664704c1494ad5f7a0@syzkaller.appspotmail.com \
--cc=tristan@talencesecurity.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox