Skip to contentSkip to conversation

nvmet: prevent double-free after metadata SGL allocation failure

PATCH In review Avi Weiss 2 participants 2 messages Oct 22

Subsystems (2)
lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

PATCH 1/1 nvmet: prevent double-free after metadata SGL allocation failure

If metadata SGL allocation fails, nvmet_req_alloc_sgls() frees req->sg without clearing it. The RDMA error completion path later frees the same scatterlist again.

Use nvmet_req_free_sgls() instead so that the scatterlist pointers and counts are cleared before response cleanup.

Fixes c6e3f13398123 ("nvmet: add metadata support for block devices")
---
 drivers/nvme/target/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/core.c +1 -1
index 07a74c2e1f58..8032924e657f 100644
@@ -1359,7 +1359,7 @@ int nvmet_req_alloc_sgls(struct nvmet_req *req)
 
 	return 0;
 out_free:
-	sgl_free(req->sg);
+	nvmet_req_free_sgls(req);
 out:
 	return -ENOMEM;
 }

base-commit: a804c5742bff224d4cb4d25dd383554d598be32b

Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 6 lines · Avi Weiss

If metadata SGL allocation fails, nvmet_req_alloc_sgls() frees req->sg without clearing it. The RDMA error completion path later frees the same scatterlist again.

Use nvmet_req_free_sgls() instead so that the scatterlist pointers and counts are cleared before response cleanup.

Looks good, applied to nvme-7.4.