[BUG] KASAN: slab-use-after-free in nvme_fc_fcpio_done

From: Shuangpeng

Date: Thu Jun 04 2026 - 14:28:04 EST


Hi Kernel Maintainers,

I hit the following KASAN report while testing current upstream kernel:

KASAN: slab-use-after-free in nvme_fc_fcpio_done

on upstream commit: e8c2f9fdadee7cbc75134dc463c1e0d856d6e5c7 (May 25 2026)

This was found with nvme-fcloop. A previous fcloop-related report I sent hit
nvmet_fc_tgt_q_put on the target side:
https://lore.kernel.org/linux-nvme/56c826df-efe7-4c48-9142-c32c8e3415a8@xxxxxxxxx/

This report is different in that the freed object is the host-side
nvme_fc_ctrl, freed through nvme_sysfs_delete() -> nvme_free_ctrl(), and the
later access happens in nvme_fc_fcpio_done() after fcloop calls the host
completion path.

To help trigger the bug more reliably, we applied a minimal diagnostic patch
that only adds delays and print statements.

The reproducer and .config files are here.
https://gist.github.com/shuangpengbai/b88810aba94d68ae11ac65b8d1e03a5b

I’m happy to test debug patches or provide additional information.

Reported-by: Shuangpeng Bai <shuangpeng.kernel@xxxxxxxxx>

[ 117.632186][ T1165] ==================================================================
[ 117.632793][ T1165] BUG: KASAN: slab-use-after-free in nvme_fc_fcpio_done (./drivers/nvme/host/nvme.h:473 drivers/nvme/host/fc.c:2063)
[ 117.634328][ T1165] Read of size 4 at addr ffff8881269fc3f4 by task kworker/u9:2/1165
[ 117.634865][ T1165]
[ 117.635075][ T1165] Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
[ 117.635078][ T1165] Workqueue: nvmet-wq fcloop_fcp_abort_recv_work
[ 117.635098][ T1165] Call Trace:
[ 117.635108][ T1165] <TASK>
[ 117.635111][ T1165] dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120)
[ 117.635145][ T1165] print_report (mm/kasan/report.c:378 mm/kasan/report.c:482)
[ 117.635201][ T1165] kasan_report (mm/kasan/report.c:595)
[ 117.635207][ T1165] nvme_fc_fcpio_done (./drivers/nvme/host/nvme.h:473 drivers/nvme/host/fc.c:2063)
[ 117.635215][ T1165] fcloop_call_host_done (drivers/nvme/target/fcloop.c:607)
[ 117.635219][ T1165] process_scheduled_works (kernel/workqueue.c:3314 kernel/workqueue.c:3397)
[ 117.635232][ T1165] worker_thread (kernel/workqueue.c:3478)
[ 117.635248][ T1165] kthread (kernel/kthread.c:436)
[ 117.635258][ T1165] ret_from_fork (arch/x86/kernel/process.c:158)
[ 117.635297][ T1165] ret_from_fork_asm (arch/x86/entry/entry_64.S:245)
[ 117.635301][ T1165] </TASK>
[ 117.635302][ T1165]
[ 117.644920][ T1165] Freed by task 8162 on cpu 1 at 117.604613s:
[ 117.645351][ T1165] kasan_save_track (mm/kasan/common.c:57 mm/kasan/common.c:78)
[ 117.645683][ T1165] kasan_save_free_info (mm/kasan/generic.c:584)
[ 117.646041][ T1165] __kasan_slab_free (mm/kasan/common.c:253 mm/kasan/common.c:285)
[ 117.646377][ T1165] kfree (./include/linux/kasan.h:235 mm/slub.c:2689 mm/slub.c:6251 mm/slub.c:6566)
[ 117.646664][ T1165] nvme_free_ctrl (drivers/nvme/host/core.c:5102)
[ 117.646997][ T1165] device_release (drivers/base/core.c:2562)
[ 117.647344][ T1165] kobject_put (lib/kobject.c:689 lib/kobject.c:720 ./include/linux/kref.h:65 lib/kobject.c:737)
[ 117.648052][ T1165] nvme_sysfs_delete (drivers/nvme/host/sysfs.c:401)
[ 117.648392][ T1165] kernfs_fop_write_iter (fs/kernfs/file.c:352)
[ 117.648769][ T1165] vfs_write (fs/read_write.c:595 fs/read_write.c:688)
[ 117.649088][ T1165] ksys_write (fs/read_write.c:740)
[ 117.649390][ T1165] do_syscall_64 (arch/x86/entry/syscall_64.c:63 arch/x86/entry/syscall_64.c:94)
[ 117.649737][ T1165] entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
[ 117.650124][ T1165]
[ 117.650282][ T1165] The buggy address belongs to the object at ffff8881269fc000
[ 117.650282][ T1165] which belongs to the cache kmalloc-4k of size 4096
[ 117.651226][ T1165] The buggy address is located 1012 bytes inside of
[ 117.651226][ T1165] freed 4096-byte region [ffff8881269fc000, ffff8881269fd000)



Best,
Shuangpeng