nvmet: Avoid potential UAF in nvmet_req_complete()
Subsystems (2)
PATCH v2 1/1 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.
---
Changes from v1:
* Added Fixes tag and cc stable
drivers/nvme/target/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvme/target/core.c +3 -1
@@ -756,8 +756,10 @@ static void __nvmet_req_complete(struct nvmet_req *req, u16 status)void nvmet_req_complete (struct nvmet_req *req,u16 status) { +struct nvmet_sq *sq = req->sq; +__nvmet_req_complete (req, status); -percpu_ref_put (&req->sq->ref); +percpu_ref_put (&sq->ref); }EXPORT_SYMBOL_GPL (nvmet_req_complete);
Signature · 1 line
2.39.2
Quoted 5 lines · Damien Le Moal
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 innvmet_req_complete().
Quoted 9 lines
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 <[email protected]>---
Looks good.
-ck
Sagi Grimberg
maintainerHey Damien,
Quoted 4 lines
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 innvmet_req_complete().
Can you point me to which transport frees the request?
Quoted 32 lines
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 <[email protected]>---
Changes from v1:
* Added Fixes tag and cc stabledrivers/nvme/target/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/nvme/target/core.c +3
-1@@ -756,8 +756,10 @@ static void __nvmet_req_complete(struct nvmet_req *req, u16 status)void nvmet_req_complete (struct nvmet_req *req,u16 status) { +struct nvmet_sq *sq = req->sq; +__nvmet_req_complete (req, status); -percpu_ref_put (&req->sq->ref); +percpu_ref_put (&sq->ref); }EXPORT_SYMBOL_GPL (nvmet_req_complete);
Quoted 8 lines · Sagi Grimberg
Hey Damien,
Quoted 4 lines
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 innvmet_req_complete().Can you point me to which transport frees the request?
My prototype PCIe endpoint nvme function driver, not upstream yet.
The endpoint board keeps randomly crashing without this patch and not freeing the request (embedded in a struct) in the ->queue_response() operation would require *a lot* more code.
Quoted 33 lines
Quoted 33 lines
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 <[email protected]>---
Changes from v1:
* Added Fixes tag and cc stabledrivers/nvme/target/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/nvme/target/core.c +3
-1@@ -756,8 +756,10 @@ static void __nvmet_req_complete(struct nvmet_req *req, u16 status)void nvmet_req_complete (struct nvmet_req *req,u16 status) { +struct nvmet_sq *sq = req->sq; +__nvmet_req_complete (req, status); -percpu_ref_put (&req->sq->ref); +percpu_ref_put (&sq->ref); }EXPORT_SYMBOL_GPL (nvmet_req_complete);
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 8 lines
Quoted 8 lines
Hey Damien,
Quoted 4 lines
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 innvmet_req_complete().
Quoted 7 lines
Quoted 1 line
Can you point me to which transport frees the request?
My prototype PCIe endpoint nvme function driver, not upstream yet.
The endpoint board keeps randomly crashing without this patch and not freeing the request (embedded in a struct) in the ->queue_response() operation would require *a lot* more code.
Got it,
Thanks,
applied to nvme-6.3.