Skip to content

Commit 4000120

Browse files
Damien Le Moalmozzaru
authored andcommitted
nvmet: avoid potential UAF in nvmet_req_complete()
[ Upstream commit 6173a77b7e9d3e202bdb9897b23f2a8afe7bf286 ] 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 <damien.lemoal@opensource.wdc.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 3bb657f commit 4000120

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
@@ -405,8 +405,10 @@ static void __nvmet_req_complete(struct nvmet_req *req, u16 status)
405405

406406
void nvmet_req_complete(struct nvmet_req *req, u16 status)
407407
{
408+
struct nvmet_sq *sq = req->sq;
409+
408410
__nvmet_req_complete(req, status);
409-
percpu_ref_put(&req->sq->ref);
411+
percpu_ref_put(&sq->ref);
410412
}
411413
EXPORT_SYMBOL_GPL(nvmet_req_complete);
412414

0 commit comments

Comments
 (0)