From: sashiko-bot@kernel.org
To: "Tristan Madani" <tristmd@gmail.com>,
"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,
"Tristan Madani" <tristan@talencesecurity.com>,
syzbot+44664704c1494ad5f7a0@syzkaller.appspotmail.com
Subject: Re: [PATCH v4] jffs2: free xattr refs before deleting inode cache in jffs2_do_clear_inode
Date: Wed, 02 Dec 2026 14:54:19 +0000 [thread overview]
Message-ID: <sashiko-outbox-246013@kernel.org> (raw)
In-Reply-To: <20261202142230.2786265-1-tristmd@gmail.com>
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/
prev parent reply other threads:[~2026-12-02 14:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
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=sashiko-outbox-246013@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dwmw2@infradead.org \
--cc=haris.iqbal@linux.dev \
--cc=kaigai@ak.jp.nec.com \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
--cc=sashiko-reviews@lists.linux.dev \
--cc=syzbot+44664704c1494ad5f7a0@syzkaller.appspotmail.com \
--cc=tristan@talencesecurity.com \
--cc=tristmd@gmail.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