All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lucas Jeffrey" <luquijeffrey@gmail.com>, dwmw2@infradead.org
Cc: richard@nod.at, linux-mtd@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	syzbot+3a8099322b09d8d073d1@syzkaller.appspotmail.com
Subject: Re: [PATCH] jffs: initialize inocache to NULL when initializing a jffs2_inode_info
Date: Wed, 09 Sep 2026 02:54:07 +0000	[thread overview]
Message-ID: <20260909025407.7494D1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260909023955.1642244-1-luquijeffrey@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Double free of `f->target` on early VFS failure paths due to uninitialized slab memory.
--

commit 9fd2012cfec1b8d15df193fea97deabda99aa5e5
Author: Lucas Jeffrey <luquijeffrey@gmail.com>

jffs: initialize inocache to NULL when initializing a jffs2_inode_info

When a jffs2_inode_info is allocated via new_inode(), due to memory reuse it
can retain stale values from its previous use.

If the new jffs2_inode_info object allocated retains an old reference to a
freed inocache, the function jffs2_new_inode may crash if either
jffs2_init_acl_pre or jffs2_do_new_inode returns an error value because
when calling iput() with the inode it will eventually attempt to free again
the inocache.

Reported-by: syzbot+3a8099322b09d8d073d1@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=3a8099322b09d8d073d1
Signed-off-by: Lucas Jeffrey <luquijeffrey@gmail.com>

> diff --git a/fs/jffs2/os-linux.h b/fs/jffs2/os-linux.h
> index 86ab014a349c5..40f17218a276b 100644
> --- a/fs/jffs2/os-linux.h
> +++ b/fs/jffs2/os-linux.h
> @@ -52,6 +52,7 @@ static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
>  {
>  	f->highest_version = 0;
>  	f->fragtree = RB_ROOT;
> +	f->inocache = NULL;
>  	f->metadata = NULL;
>  	f->dents = NULL;
>  	f->target = NULL;

[Severity: Critical]
This isn't a bug introduced by this patch, but doesn't f->target suffer from
a similar issue due to uninitialized slab memory on early VFS failure paths?

When the VFS allocates a new inode via jffs2_alloc_inode() in
fs/jffs2/super.c, the object is returned from the SLAB cache without
__GFP_ZERO. It retains stale values from its previous lifecycle, including
a dangling pointer in f->target, because jffs2_free_inode() frees f->target
but does not nullify it.

JFFS2 defers initializing f->target = NULL to jffs2_init_inode_info(), which
is called after VFS initialization completes. If the VFS fails early (e.g.,
inode_init_always() fails due to an LSM memory allocation, or iget_locked()
in fs/inode.c encounters a hash collision race and drops the newly allocated
inode), the VFS destroys the inode via jffs2_free_inode() before JFFS2 ever
initializes it.

This causes a double free when kfree(f->target) executes again on the
dangling pointer:

fs/jffs2/super.c:jffs2_free_inode() {
	...
	kfree(f->target);
	kmem_cache_free(jffs2_inode_cachep, f);
}

Userspace can reliably trigger the iget_locked() hash collision race by
performing concurrent lookups (e.g., stat() or open()) on the same
non-resident inode:

fs/inode.c:iget_locked() {
	...
	if (unlikely(test_bit(__I_NEW, &inode->i_state))) {
		/* Uhhuh, somebody else created the same inode under us... */
		spin_unlock(&inode_hash_lock);
		destroy_inode(inode);
	...
}

Would it be safer to zero these fields in jffs2_alloc_inode() or ensure
jffs2_free_inode() nullifies them before returning the object to the slab
cache?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909023955.1642244-1-luquijeffrey@gmail.com?part=1

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2026-09-09  2:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09  2:39 [PATCH] jffs: initialize inocache to NULL when initializing a jffs2_inode_info Lucas Jeffrey
2026-09-09  2:54 ` sashiko-bot [this message]
2026-09-09  5:57   ` AW: " Richard Weinberger
2026-09-10  2:53     ` Lucas Jeffrey
2026-09-09  5:33 ` AW: " Richard Weinberger
2026-09-10  3:19 ` [PATCH v2] jffs2: initialize inocache and target to NULL when allocating and initializing an jffs2_inode_info Lucas Jeffrey

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=20260909025407.7494D1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=luquijeffrey@gmail.com \
    --cc=richard@nod.at \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=syzbot+3a8099322b09d8d073d1@syzkaller.appspotmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.