Skip to content

Commit 6173a77

Browse files
Damien Le MoalChristoph Hellwig
authored andcommitted
nvmet: avoid potential UAF in nvmet_req_complete()
An nvme target ->queue_response() operation implementation may free the request passed as argument. Such implementation potentially could result in a use after free of the request pointer when percpu_ref_put() is called in nvmet_req_complete(). Avoid such problem by using a local variable to save the sq pointer before calling __nvmet_req_complete(), thus avoiding dereferencing the req pointer after that function call. Fixes: a07b497 ("nvmet: add a generic NVMe target") Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 8e19b87 commit 6173a77

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/nvme/target/core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,10 @@ static void __nvmet_req_complete(struct nvmet_req *req, u16 status)
756756

757757
void nvmet_req_complete(struct nvmet_req *req, u16 status)
758758
{
759+
struct nvmet_sq *sq = req->sq;
760+
759761
__nvmet_req_complete(req, status);
760-
percpu_ref_put(&req->sq->ref);
762+
percpu_ref_put(&sq->ref);
761763
}
762764
EXPORT_SYMBOL_GPL(nvmet_req_complete);
763765

0 commit comments

Comments
 (0)