Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: a07b4970f464 ("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>

authored by

Damien Le Moal and committed by
Christoph Hellwig
6173a77b 8e19b87c

+3 -1
+3 -1
drivers/nvme/target/core.c
··· 756 756 757 757 void nvmet_req_complete(struct nvmet_req *req, u16 status) 758 758 { 759 + struct nvmet_sq *sq = req->sq; 760 + 759 761 __nvmet_req_complete(req, status); 760 - percpu_ref_put(&req->sq->ref); 762 + percpu_ref_put(&sq->ref); 761 763 } 762 764 EXPORT_SYMBOL_GPL(nvmet_req_complete); 763 765