[PATCH 5.10.y] nvme: avoid double free special payload

Cliff Liu donghua.liu at windriver.com
Tue Apr 8 00:18:07 PDT 2025


From: Chunguang Xu <chunguang.xu at shopee.com>

[ Upstream commit e5d574ab37f5f2e7937405613d9b1a724811e5ad ]

If a discard request needs to be retried, and that retry may fail before
a new special payload is added, a double free will result. Clear the
RQF_SPECIAL_LOAD when the request is cleaned.

Signed-off-by: Chunguang Xu <chunguang.xu at shopee.com>
Reviewed-by: Sagi Grimberg <sagi at grimberg.me>
Reviewed-by: Max Gurtovoy <mgurtovoy at nvidia.com>
Signed-off-by: Keith Busch <kbusch at kernel.org>
[Minor context change fixed]
Signed-off-by: Cliff Liu <donghua.liu at windriver.com>
Signed-off-by: He Zhe <Zhe.He at windriver.com>
---
Verified the build test.
---
 drivers/nvme/host/core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 019a6dbdcbc2..7d6aab68446e 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -852,6 +852,7 @@ void nvme_cleanup_cmd(struct request *req)
 			clear_bit_unlock(0, &ns->ctrl->discard_page_busy);
 		else
 			kfree(page_address(page) + req->special_vec.bv_offset);
+		req->rq_flags &= ~RQF_SPECIAL_PAYLOAD;
 	}
 }
 EXPORT_SYMBOL_GPL(nvme_cleanup_cmd);
-- 
2.34.1




More information about the Linux-nvme mailing list