[PATCH] scsi: qla2xxx: Fix improper freeing of purex item

Zilin Guan posted 1 patch 2 months, 3 weeks ago
drivers/scsi/qla2xxx/qla_nvme.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] scsi: qla2xxx: Fix improper freeing of purex item
Posted by Zilin Guan 2 months, 3 weeks ago
In qla2xxx_process_purls_iocb(), an item is allocated via
qla27xx_copy_multiple_pkt(), which internally calls
qla24xx_alloc_purex_item().

The qla24xx_alloc_purex_item() function may return a pre-allocated item
from a per-adapter pool for small allocations, instead of dynamically
allocating memory with kzalloc().

An error handling path in qla2xxx_process_purls_iocb() incorrectly uses
kfree() to release the item. If the item was from the pre-allocated pool,
calling kfree() on it is a bug that can lead to memory corruption.

Fix this by using the correct deallocation function,
qla24xx_free_purex_item(), which properly handles both dynamically
allocated and pre-allocated items.

Fixes: 875386b988578 ("scsi: qla2xxx: Add Unsolicited LS Request and Response Support for NVMe")
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
 drivers/scsi/qla2xxx/qla_nvme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
index 316594aa40cc..42eb65a62f1f 100644
--- a/drivers/scsi/qla2xxx/qla_nvme.c
+++ b/drivers/scsi/qla2xxx/qla_nvme.c
@@ -1292,7 +1292,7 @@ void qla2xxx_process_purls_iocb(void **pkt, struct rsp_que **rsp)
 		a.reason = FCNVME_RJT_RC_LOGIC;
 		a.explanation = FCNVME_RJT_EXP_NONE;
 		xmt_reject = true;
-		kfree(item);
+		qla24xx_free_purex_item(item);
 		goto out;
 	}
 
-- 
2.34.1
Re: [PATCH] scsi: qla2xxx: Fix improper freeing of purex item
Posted by Martin K. Petersen 2 months, 1 week ago
On Thu, 13 Nov 2025 15:12:46 +0000, Zilin Guan wrote:

> In qla2xxx_process_purls_iocb(), an item is allocated via
> qla27xx_copy_multiple_pkt(), which internally calls
> qla24xx_alloc_purex_item().
> 
> The qla24xx_alloc_purex_item() function may return a pre-allocated item
> from a per-adapter pool for small allocations, instead of dynamically
> allocating memory with kzalloc().
> 
> [...]

Applied to 6.19/scsi-queue, thanks!

[1/1] scsi: qla2xxx: Fix improper freeing of purex item
      https://git.kernel.org/mkp/scsi/c/78b1a242fe61

-- 
Martin K. Petersen
Re: [PATCH] scsi: qla2xxx: Fix improper freeing of purex item
Posted by Martin K. Petersen 2 months, 2 weeks ago
Zilin,

> In qla2xxx_process_purls_iocb(), an item is allocated via
> qla27xx_copy_multiple_pkt(), which internally calls
> qla24xx_alloc_purex_item().

Applied to 6.19/scsi-staging, thanks!

-- 
Martin K. Petersen
Re: [PATCH] scsi: qla2xxx: Fix improper freeing of purex item
Posted by himanshu Madhani 2 months, 3 weeks ago

> On Nov 13, 2025, at 7:12 AM, Zilin Guan <zilin@seu.edu.cn> wrote:
> 
> In qla2xxx_process_purls_iocb(), an item is allocated via
> qla27xx_copy_multiple_pkt(), which internally calls
> qla24xx_alloc_purex_item().
> 
> The qla24xx_alloc_purex_item() function may return a pre-allocated item
> from a per-adapter pool for small allocations, instead of dynamically
> allocating memory with kzalloc().
> 
> An error handling path in qla2xxx_process_purls_iocb() incorrectly uses
> kfree() to release the item. If the item was from the pre-allocated pool,
> calling kfree() on it is a bug that can lead to memory corruption.
> 
> Fix this by using the correct deallocation function,
> qla24xx_free_purex_item(), which properly handles both dynamically
> allocated and pre-allocated items.
> 
> Fixes: 875386b988578 ("scsi: qla2xxx: Add Unsolicited LS Request and Response Support for NVMe")
> Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
> ---
> drivers/scsi/qla2xxx/qla_nvme.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
> index 316594aa40cc..42eb65a62f1f 100644
> --- a/drivers/scsi/qla2xxx/qla_nvme.c
> +++ b/drivers/scsi/qla2xxx/qla_nvme.c
> @@ -1292,7 +1292,7 @@ void qla2xxx_process_purls_iocb(void **pkt, struct rsp_que **rsp)
> a.reason = FCNVME_RJT_RC_LOGIC;
> a.explanation = FCNVME_RJT_EXP_NONE;
> xmt_reject = true;
> - kfree(item);
> + qla24xx_free_purex_item(item);
> goto out;
> }
> 
> -- 
> 2.34.1
> 
> 
Looks Good. 

Reviewed-by: Himanshu Madhani <hmadhani2024@gmail.com <mailto:hmadhani2024@gmail.com>>