mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] jffs2: fix double-free of f->target in jffs2_alloc_inode()
@ 2026-08-23 15:26 Deepanshu Kartikey
  2026-09-12  1:08 ` Deepanshu Kartikey
  0 siblings, 1 reply; 7+ messages in thread
From: Deepanshu Kartikey @ 2026-08-23 15:26 UTC (permalink / raw)
  To: dwmw2, richard
  Cc: kees, viro, linux-mtd, linux-kernel, Deepanshu Kartikey,
	syzbot+675e84fdf3dde67b4946

jffs2_alloc_inode() does not initialize f->target before returning
the new inode. It is normally cleared later by
jffs2_init_inode_info(), called from jffs2_iget(), but that runs
only after alloc_inode() has already returned successfully.

If inode_init_always() fails in between, alloc_inode() calls
->free_inode() directly on the half-initialized inode.
jffs2_free_inode() then does kfree(f->target) on whatever stale
value was left in the reused slab object, which can be a pointer
that was already freed, causing a double-free.

Initialize f->target to NULL in jffs2_alloc_inode() to close this
window, and clear it in jffs2_free_inode() after freeing it so a
reused or re-freed object can never carry a dangling pointer.

Fixes: 4fdcfab5b553 ("jffs2: fix use-after-free on symlink traversal")
Reported-by: syzbot+675e84fdf3dde67b4946@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=675e84fdf3dde67b4946
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
 fs/jffs2/super.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index 81396a092ba8..30d753d4c263 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -42,6 +42,7 @@ 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;
 }
 
@@ -50,6 +51,7 @@ static void jffs2_free_inode(struct inode *inode)
 	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
 
 	kfree(f->target);
+	f->target = NULL;
 	kmem_cache_free(jffs2_inode_cachep, f);
 }
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-09-23  3:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-23 15:26 [PATCH] jffs2: fix double-free of f->target in jffs2_alloc_inode() Deepanshu Kartikey
2026-09-12  1:08 ` Deepanshu Kartikey
2026-09-12  6:57   ` AW: " Richard Weinberger
2026-09-12  7:59     ` Deepanshu Kartikey
2026-09-12 16:57       ` AW: " Richard Weinberger
2026-09-13  3:24         ` Deepanshu Kartikey
2026-09-23  3:29           ` Deepanshu Kartikey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®