Skip to contentSkip to conversation

scsi: hpsa: Fix possible memory leak in hpsa_init_one()

PATCH Applied Yuan Can 3 participants 4 messages Nov 22, 2022 – Dec 1, 2022

Subsystems (2)
lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 1/1 scsi: hpsa: Fix possible memory leak in hpsa_init_one()

The hpda_alloc_ctlr_info() allocates h and its field reply_map, however in hpsa_init_one(), if alloc_percpu() failed, the hpsa_init_one() jumps to clean1 directly, which frees h and leaks the h->reply_map.
Fix by calling hpda_free_ctlr_info() to release h->replay_map and h instead free h directly.

Fixes 8b834bff1b73 ("scsi: hpsa: fix selection of reply queue")
---
 drivers/scsi/hpsa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/hpsa.c +1 -1
index f8e832b1bc46..e5cbc97a5ea4 100644
@@ -8925,7 +8925,7 @@ static int hpsa_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		destroy_workqueue(h->monitor_ctlr_wq);
 		h->monitor_ctlr_wq = NULL;
 	}
-	kfree(h);
+	hpda_free_ctlr_info(h);
 	return rc;
 }
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Yuan Can

The hpda_alloc_ctlr_info() allocates h and its field reply_map, however in hpsa_init_one(), if alloc_percpu() failed, the hpsa_init_one() jumps to clean1 directly, which frees h and leaks the h->reply_map.
Fix by calling hpda_free_ctlr_info() to release h->replay_map and h instead free h directly.

Fixes 8b834bff1b73 ("scsi: hpsa: fix selection of reply queue")
---
 drivers/scsi/hpsa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/hpsa.c +0 -0
index f8e832b1bc46..e5cbc97a5ea4 100644

drivers/scsi/hpsa.c static int hpsa_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 8928

Quoted 5 lines
drivers/scsi/hpsa.c +1 -1
@@ -8925,7 +8925,7 @@ static int hpsa_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		destroy_workqueue(h->monitor_ctlr_wq);
 		h->monitor_ctlr_wq = NULL;
 	}
-	kfree(h);
+	hpda_free_ctlr_info(h);

Thanks,
Ming

#2 lore raw
In reply to Yuan Can

Yuan,

Quoted 5 lines

The hpda_alloc_ctlr_info() allocates h and its field reply_map, however in hpsa_init_one(), if alloc_percpu() failed, the hpsa_init_one() jumps to clean1 directly, which frees h and leaks the h->reply_map. Fix by calling hpda_free_ctlr_info() to release h->replay_map and h instead free h directly.

Applied to 6.2/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#3 lore raw
In reply to Yuan Can
Quoted 8 lines · Yuan Can

The hpda_alloc_ctlr_info() allocates h and its field reply_map, however in hpsa_init_one(), if alloc_percpu() failed, the hpsa_init_one() jumps to clean1 directly, which frees h and leaks the h->reply_map.
Fix by calling hpda_free_ctlr_info() to release h->replay_map and h instead free h directly.

[...]

Applied to 6.2/scsi-queue, thanks!

[1/1] scsi: hpsa: Fix possible memory leak in hpsa_init_one()

      https://git.kernel.org/mkp/scsi/c/9c9ff300e0de
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering