summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiang HongHui <jiang_hh2019@163.com>2026-07-29 19:02:06 +0800
committerKeith Busch <kbusch@kernel.org>2026-08-10 12:00:29 -0700
commitba98d6796d12258e837ece065d2ecb59d76ce4ff (patch)
tree8b6af2f4bfff91f1d3e9f4e0f63c0a0fb0c32a96
parent58202950e39c127d593ec4f0624d8b8985a285b1 (diff)
nvmet-fc: fix invalid free in LS IOD error path
nvmet_fc_alloc_ls_iodlist() advances iod while initializing the LS IOD array. If an rqstbuf allocation or response buffer DMA mapping fails, the unwind loop decrements iod past the start of the array. The final kfree(iod) therefore frees an address before the allocated object. This can be reproduced with nvme-fcloop and failslab by setting fail-nth to 6 before creating a target port. KASAN reports: BUG: KASAN: invalid-free in nvmet_fc_register_targetport Free of addr ffff88816cf8ff48 by task nvmet_fail_nth/9552 Free the original allocation base stored in tgtport->iod instead. With this fix applied, the same sysfs write with fail-nth=6 returns -ENOMEM without any KASAN report. Fixes: c53432030d86 ("nvme-fabrics: Add target support for FC transport") Cc: stable@vger.kernel.org Reviewed-by: Maurizio Lombardi <mlombard@redhat.com> Assisted-by: Codex:gpt-5 Signed-off-by: Jiang HongHui <jiang_hh2019@163.com> Signed-off-by: Keith Busch <kbusch@kernel.org>
-rw-r--r--drivers/nvme/target/fc.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index d161707559ce..1b557775e033 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -566,7 +566,7 @@ out_fail:
list_del(&iod->ls_rcv_list);
}
- kfree(iod);
+ kfree(tgtport->iod);
return -EFAULT;
}