From: Lucas Jeffrey <luquijeffrey@gmail.com>
To: dwmw2@infradead.org
Cc: richard@nod.at, linux-mtd@lists.infradead.org,
linux-kernel@vger.kernel.org,
syzbot+3a8099322b09d8d073d1@syzkaller.appspotmail.com,
Lucas Jeffrey <luquijeffrey@gmail.com>
Subject: [PATCH v2] jffs2: initialize inocache and target to NULL when allocating and initializing an jffs2_inode_info
Date: Thu, 10 Sep 2026 00:19:12 -0300 [thread overview]
Message-ID: <20260910031912.2283174-1-luquijeffrey@gmail.com> (raw)
In-Reply-To: <20260909023955.1642244-1-luquijeffrey@gmail.com>
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.
There is another failure path which is, if target is not null when allocating
the object in jffs2_alloc_inode, and immediately after returning the newly allocated object,
and if the 'inode_init_always' returns an error value (allocation failure for example)
then the vfs will attempt to free the inode and jffs2_free_inode will attempt to free f->target,
which can be a stale value from a previous allocation, generating a double free/use after free.
Reported-by: syzbot+3a8099322b09d8d073d1@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=3a8099322b09d8d073d1
Signed-off-by: Lucas Jeffrey <luquijeffrey@gmail.com>
---
Changes in V2: initializing target field to NULL in jffs2_alloc_inode
---
fs/jffs2/os-linux.h | 1 +
fs/jffs2/super.c | 2 ++
2 files changed, 3 insertions(+)
diff --git a/fs/jffs2/os-linux.h b/fs/jffs2/os-linux.h
index 86ab014a349c..40f17218a276 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;
diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index 81396a092ba8..2343c21b49e6 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -42,6 +42,8 @@ static struct inode *jffs2_alloc_inode(struct super_block *sb)
f = alloc_inode_sb(sb, jffs2_inode_cachep, GFP_KERNEL);
if (!f)
return NULL;
+
+ f->target = NULL;
return &f->vfs_inode;
}
--
2.43.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
prev parent reply other threads:[~2026-09-10 3:19 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
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 ` Lucas Jeffrey [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=20260910031912.2283174-1-luquijeffrey@gmail.com \
--to=luquijeffrey@gmail.com \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
--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.