mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] jffs2: initialize f->inocache to NULL in jffs2_init_inode_info()
@ 2026-11-03  3:26 Shuai Liu
  0 siblings, 0 replies; only message in thread
From: Shuai Liu @ 2026-11-03  3:26 UTC (permalink / raw)
  To: linux-mtd
  Cc: richard, syzbot+3a8099322b09d8d073d1, luquijeffrey, linux-kernel,
	Shuai Liu

new_inode() can hand back a jffs2_inode_info recycled from slab with a
stale f->inocache still pointing to a jffs2_inode_cache that was freed
by a previous mount's jffs2_free_ino_caches().  jffs2_init_inode_info()
initialises every other pointer field but leaves f->inocache untouched.

If jffs2_new_inode() then fails before jffs2_do_new_inode() assigns a
fresh f->inocache -- e.g. in jffs2_init_acl_pre() -- the error path does
make_bad_inode() + iput(), and evict() ends up calling
jffs2_xattr_delete_inode() which dereferences the stale pointer when
reading ic->pino_nlink, causing a slab-use-after-free:

  BUG: KASAN: slab-use-after-free in jffs2_xattr_delete_inode
  Read of size 4 at addr ... by task repro
    jffs2_xattr_delete_inode
    jffs2_do_clear_inode
    evict
    jffs2_new_inode
    jffs2_mkdir
  Allocated by jffs2_scan_make_ino_cache (jffs2_do_mount_fs)
  Freed by jffs2_free_ino_caches (jffs2_put_super)

Fix by clearing f->inocache in jffs2_init_inode_info(), consistent with
the other pointer fields there.  Verified with the syzbot C reproducer
under QEMU with KASAN: the UAF is reported before the patch and absent
after it.

Originally proposed by Lucas Jeffrey <luquijeffrey@gmail.com>
(Link: https://lore.kernel.org/all/20260909023955.1642244-1-luquijeffrey@gmail.com/);
that thread has seen no activity since September 10 while the bug is
still reproducing upstream, so resubmitting with his credit.

Reported-by: syzbot+3a8099322b09d8d073d1@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=3a8099322b09d8d073d1
Suggested-by: Lucas Jeffrey <luquijeffrey@gmail.com>
Signed-off-by: Shuai Liu <847807867@qq.com>
---
 fs/jffs2/os-linux.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/jffs2/os-linux.h b/fs/jffs2/os-linux.h
index bff2134d771d..e80b786c9ea2 100644
--- a/fs/jffs2/os-linux.h
+++ b/fs/jffs2/os-linux.h
@@ -55,6 +55,7 @@ static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
 	f->metadata = NULL;
 	f->dents = NULL;
 	f->target = NULL;
+	f->inocache = NULL;
 	f->flags = 0;
 	f->usercompr = 0;
 }
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-03  3:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03  3:26 [PATCH] jffs2: initialize f->inocache to NULL in jffs2_init_inode_info() Shuai Liu

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®