* [PATCH v4] jffs2: free xattr refs before deleting inode cache in jffs2_do_clear_inode
@ 2026-12-02 14:22 Tristan Madani
2026-12-02 14:54 ` sashiko-bot
0 siblings, 1 reply; 2+ messages 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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v4] jffs2: free xattr refs before deleting inode cache in jffs2_do_clear_inode
2026-12-02 14:22 [PATCH v4] jffs2: free xattr refs before deleting inode cache in jffs2_do_clear_inode Tristan Madani
@ 2026-12-02 14:54 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-02 14:54 UTC (permalink / raw)
To: Tristan Madani, David Woodhouse, Richard Weinberger
Cc: Haris Iqbal, KaiGai Kohei, linux-mtd, Tristan Madani,
syzbot+44664704c1494ad5f7a0
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] jffs2: slab use-after-free and double-free via
jffs2_xattr_free_inode()
- [Medium] jffs2: race in jffs2_do_clear_inode() sleeping before
jffs2_del_ino_cache()
--
commit f0babf6847b43591c83eb9e29c15e43ea415f4c6
Author: Tristan Madani <tristan@talencesecurity.com>
jffs2: free xattr refs before deleting inode cache in jffs2_do_clear_inode
This commit calls jffs2_xattr_free_inode() before jffs2_del_ino_cache() in
jffs2_do_clear_inode() to clear any remaining xattr references on the
inode cache entry before deleting it.
> 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);
[Severity: High]
Does calling jffs2_xattr_free_inode() here cause a use-after-free and
double free of struct jffs2_xattr_ref and struct jffs2_xattr_datum?
Each on-flash xattr node is tracked by a physical jffs2_raw_node_ref in
c->blocks whose next_in_ino list terminates directly at the
jffs2_xattr_ref or jffs2_xattr_datum object:
fs/jffs2/nodelist.h:jffs2_raw_ref_to_ic() {
while(raw->next_in_ino)
raw = raw->next_in_ino;
/* NB. This can be a jffs2_xattr_datum or jffs2_xattr_ref and
not actually a jffs2_inode_cache. Check ->class */
return ((struct jffs2_inode_cache *)raw);
}
jffs2_xattr_free_inode() is an unmount teardown helper that immediately
frees ref and xd back to their slab caches without unlinking or obsoleting
their raw_node_ref chains in c->blocks. In the normal unmount path,
jffs2_free_ino_caches() runs right before jffs2_free_raw_node_refs()
bulk-frees the raw_node_ref arrays.
When jffs2_do_clear_inode() runs earlier (for example during runtime
eviction after jffs2_iget() fails and obsoletes an inode's dnodes while
pino_nlink > 0, or during unmount before jffs2_put_super() flushes the
write buffer), the physical raw_node_ref entries for the xattrs remain
live in c->blocks. Later calls to jffs2_raw_ref_to_ic() during garbage
collection (jffs2_garbage_collect_pass()), eraseblock cleanup
(jffs2_remove_node_refs_from_ino_list()), or write-buffer recovery will
follow raw->next_in_ino into the freed xattr_ref and xattr_datum objects
(and dereference the freed inocache via ref->ic) and free them a second
time via jffs2_release_xattr_ref() and jffs2_release_xattr_datum().
[Severity: Medium]
Can sleeping in jffs2_xattr_free_inode() after setting the inocache state
to INO_STATE_CHECKEDABSENT also allow a concurrent reader to claim the
same f->inocache before jffs2_del_ino_cache() unlinks it?
jffs2_set_inocache_state() sets f->inocache->state to
INO_STATE_CHECKEDABSENT, wakes c->inocache_wq, and drops c->inocache_lock
while f->inocache is still linked in c->inocache_list. When
jffs2_do_clear_inode() is reached via iget_failed(), the VFS inode has
already been unhashed, so another thread calling jffs2_iget() for the same
inode number is not serialized by the VFS inode cache:
CPU0 CPU1
jffs2_do_clear_inode()
jffs2_set_inocache_state(...,
INO_STATE_CHECKEDABSENT)
jffs2_xattr_free_inode()
down_write(&c->xattr_sem)
[blocks]
jffs2_iget()
jffs2_do_read_inode()
f->inocache = jffs2_get_ino_cache()
/* sees INO_STATE_CHECKEDABSENT */
f->inocache->state = INO_STATE_READING
/* fails as nodes == inocache */
iget_failed()
...
jffs2_do_clear_inode()
jffs2_xattr_free_inode()
jffs2_del_ino_cache()
jffs2_free_inode_cache()
jffs2_del_ino_cache()
jffs2_free_inode_cache() <-- use-after-free / double free
Both threads end up running jffs2_xattr_free_inode() and
jffs2_del_ino_cache() on the same inocache entry.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202142230.2786265-1-tristmd@gmail.com?part=1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 14:54 UTC | newest]
Thread overview: 2+ messages (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
2026-12-02 14:54 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox