Skip to content

Commit 1a8f007

Browse files
Forget-Glowgregkh
authored andcommitted
nvmet-fc: fix invalid free in LS IOD error path
commit ba98d67 upstream. 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: c534320 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 447b668 commit 1a8f007

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • drivers/nvme/target

drivers/nvme/target/fc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ nvmet_fc_alloc_ls_iodlist(struct nvmet_fc_tgtport *tgtport)
571571
list_del(&iod->ls_rcv_list);
572572
}
573573

574-
kfree(iod);
574+
kfree(tgtport->iod);
575575

576576
return -EFAULT;
577577
}

0 commit comments

Comments
 (0)