Skip to content

Commit 6a02a61

Browse files
bvanasscheChristoph Hellwig
authored andcommitted
nvmet: fix a use-after-free
Fix the following use-after-free complaint triggered by blktests nvme/004: BUG: KASAN: user-memory-access in blk_mq_complete_request_remote+0xac/0x350 Read of size 4 at addr 0000607bd1835943 by task kworker/13:1/460 Workqueue: nvmet-wq nvme_loop_execute_work [nvme_loop] Call Trace: show_stack+0x52/0x58 dump_stack_lvl+0x49/0x5e print_report.cold+0x36/0x1e2 kasan_report+0xb9/0xf0 __asan_load4+0x6b/0x80 blk_mq_complete_request_remote+0xac/0x350 nvme_loop_queue_response+0x1df/0x275 [nvme_loop] __nvmet_req_complete+0x132/0x4f0 [nvmet] nvmet_req_complete+0x15/0x40 [nvmet] nvmet_execute_io_connect+0x18a/0x1f0 [nvmet] nvme_loop_execute_work+0x20/0x30 [nvme_loop] process_one_work+0x56e/0xa70 worker_thread+0x2d1/0x640 kthread+0x183/0x1c0 ret_from_fork+0x1f/0x30 Cc: [email protected] Fixes: a07b497 ("nvmet: add a generic NVMe target") Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 748008e commit 6a02a61

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/nvme/target/core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ static void nvmet_set_error(struct nvmet_req *req, u16 status)
735735

736736
static void __nvmet_req_complete(struct nvmet_req *req, u16 status)
737737
{
738+
struct nvmet_ns *ns = req->ns;
739+
738740
if (!req->sq->sqhd_disabled)
739741
nvmet_update_sq_head(req);
740742
req->cqe->sq_id = cpu_to_le16(req->sq->qid);
@@ -745,9 +747,9 @@ static void __nvmet_req_complete(struct nvmet_req *req, u16 status)
745747

746748
trace_nvmet_req_complete(req);
747749

748-
if (req->ns)
749-
nvmet_put_namespace(req->ns);
750750
req->ops->queue_response(req);
751+
if (ns)
752+
nvmet_put_namespace(ns);
751753
}
752754

753755
void nvmet_req_complete(struct nvmet_req *req, u16 status)

0 commit comments

Comments
 (0)