nvme: avoid double free special payload
PATCH 1/1 nvme: avoid double free special payload
From: Chunguang Xu <[email protected]>
Now we may double free spacial payload for some requests, such as discard. This will corrupt the memory and lead to kernel crash. Now we will free special payload before retry it. If we disconnect device before reconnect success, then we will fail request by nvme_fail_nonready_command(), as a result we will double free special payload. Here try to fix it, we may can clear RQF_SPECIAL_LOAD bit after we cleanup command. This will not broken following clean logic of blkmq, as nvme request will not be partial complete.
--- drivers/nvme/host/core.c | 1 + 1 file changed, 1 insertion(+)
drivers/nvme/host/core.c +1 -0
@@ -998,6 +998,7 @@ void nvme_cleanup_cmd(struct request *req)clear_bit_unlock (0 , &ctrl->discard_page_busy); else kfree(bvec_virt(&req->special_vec)); + req->rq_flags &= ~RQF_SPECIAL_PAYLOAD ; } }EXPORT_SYMBOL_GPL (nvme_cleanup_cmd);
Signature · 1 line
2.25.1
Looks reasonable.
Quoted 29 lines · brookxu.cn
From: Chunguang Xu <[email protected]>
Now we may double free spacial payload for some requests, such as discard. This will corrupt the memory and lead to kernel crash. Now we will free special payload before retry it. If we disconnect device before reconnect success, then we will fail request by
nvme_fail_nonready_command(), as a result we will double free special payload. Here try to fix it, we may can clearRQF_SPECIAL_LOADbit after we cleanup command. This will not broken following clean logic of blkmq, as nvme request will not be partial complete.Fixes 16686f3a6c3c ("nvme: move common call to nvme_cleanup_cmd to core layer")Signed-off-by Chunguang Xu <[email protected]>--- drivers/nvme/host/core.c | 1 + 1 file changed, 1 insertion(+)drivers/nvme/host/core.c +1
-0@@ -998,6 +998,7 @@ void nvme_cleanup_cmd(struct request *req)clear_bit_unlock (0 , &ctrl->discard_page_busy); else kfree(bvec_virt(&req->special_vec)); + req->rq_flags &= ~RQF_SPECIAL_PAYLOAD ; } }EXPORT_SYMBOL_GPL (nvme_cleanup_cmd);
Max Gurtovoy
Reviewed-byhi,
Quoted 18 lines · Sagi Grimberg
Looks reasonable.
Reviewed-by Sagi Grimberg <[email protected]>Quoted 12 lines · brookxu.cn
From: Chunguang Xu <[email protected]>
Now we may double free spacial payload for some requests, such as discard. This will corrupt the memory and lead to kernel crash. Now we will free special payload before retry it. If we disconnect device before reconnect success, then we will fail request by
nvme_fail_nonready_command(), as a result we will double free special payload. Here try to fix it, we may can clearRQF_SPECIAL_LOADbit after we cleanup command. This will not broken following clean logic of blkmq, as nvme request will not be partial complete.Fixes 16686f3a6c3c ("nvme: move common call to nvme_cleanup_cmd to core layer")
I'm not sure that this commit caused the bug. The nvme_cleanup_cmd() was called in this path also before this commit.
Quoted 1 line
Quoted 1 line
Signed-off-by Chunguang Xu <[email protected]>
The fix looks fine to me, but the commit message can be improved a bit to be more clear about the scenario.
Quoted 17 lines
Quoted 16 lines
---
drivers/nvme/host/core.c| 1 +1 file changed, 1 insertion(+)drivers/nvme/host/core.c +0
-0@@ -998,6 +998,7 @@ void nvme_cleanup_cmd(struct request *req) clear_bit_unlock(0, &ctrl->discard_page_busy);else kfree(bvec_virt(&req->special_vec)); +
req->rq_flags&= ~RQF_SPECIAL_PAYLOAD; }
}
EXPORT_SYMBOL_GPL(nvme_cleanup_cmd);
Keith Busch
maintainerQuoted 13 lines · Max Gurtovoy
Quoted 12 lines · Sagi Grimberg
Quoted 11 lines · brookxu.cn
From: Chunguang Xu <[email protected]>
Now we may double free spacial payload for some requests, such as discard. This will corrupt the memory and lead to kernel crash. Now we will free special payload before retry it. If we disconnect device before reconnect success, then we will fail request by
nvme_fail_nonready_command(), as a result we will double free special payload. Here try to fix it, we may can clearRQF_SPECIAL_LOADbit after we cleanup command. This will not broken following clean logic of blkmq, as nvme request will not be partial complete.
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Fixes 16686f3a6c3c ("nvme: move common call to nvme_cleanup_cmd tocore layer")
I'm not sure that this commit caused the bug. The
nvme_cleanup_cmd()was called in this path also before this commit.Quoted 1 line
Quoted 1 line
Signed-off-by Chunguang Xu <[email protected]>The fix looks fine to me, but the commit message can be improved a bit to be more clear about the scenario.
Yeah, that's a difficult read. I modified the commit message and applied to nvme-6.10. Thanks!