Skip to contentSkip to conversation

advansys: fix host resource leak in EISA probe error path

PATCH In review Guangshuo Li 3 participants 6 messages Apr 16 – Apr 17

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 advansys: fix host resource leak in EISA probe error path

A manual code audit found that advansys_eisa_probe() frees saved Scsi_Host objects directly in its error path.

Those hosts have already been successfully initialized by advansys_board_found(), so freeing them directly bypasses the normal teardown path and leaks host resources such as IRQs, DMA or MMIO resources, and the Scsi_Host release path.

Fix this by releasing the saved hosts with advansys_release() and dropping their corresponding I/O regions before freeing the probe data.

Fixes d361db483241 ("[SCSI] advansys: Sort out irq number mess")
---
 drivers/scsi/advansys.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/scsi/advansys.c +11 -3
index fcf059bf41e8..022a8190ae31 100644
@@ -11373,9 +11373,17 @@ static int advansys_eisa_probe(struct device *dev)
 	return 0;
 
  free_data:
-	kfree(data->host[0]);
-	kfree(data->host[1]);
-	kfree(data);
+	for (i = 0; i < 2; i++) {
+		struct Scsi_Host *shost = data->host[i];
+		int ioport;
+
+		if (!shost)
+			continue;
+
+		ioport = shost->io_port;
+		advansys_release(shost);
+		release_region(ioport, ASC_IOADR_GAP);
+	}
  fail:
 	return err;
 }
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 2 lines · Guangshuo Li

A manual code audit found that advansys_eisa_probe() frees saved Scsi_Host objects directly in its error path.

I've been told all your patches are AI slop, I'm not reviewing this.

#2 lore raw

Hi Matthew,

Quoted 4 lines · Matthew Wilcox
Quoted 2 lines · Guangshuo Li

A manual code audit found that advansys_eisa_probe() frees saved Scsi_Host objects directly in its error path.

I understand the concern. This issue was found through my own manual review of the error handling path in advansys_eisa_probe().

Specifically, I first compared the error handling path in advansys_eisa_probe() with the normal cleanup path in advansys_eisa_remove(), and noticed that they release saved Scsi_Host objects differently.

In advansys_eisa_remove(), each saved host is released through advansys_release(shost). Following that path shows that advansys_release() eventually releases the SCSI host through scsi_host_put(), which drops the embedded device reference and invokes the SCSI host release callback, scsi_host_dev_release(), when the reference count reaches zero.

That release callback does more than just kfree(shost). It also releases resources associated with the Scsi_Host, such as the host IDA index, shost_data, and other host-side state managed by the SCSI core.

However, the free_data path in advansys_eisa_probe() frees the saved data->host[] entries directly with kfree(). My concern is that this bypasses the scsi_host_put() / scsi_host_dev_release() path and may therefore leak resources associated with the initialized SCSI host.

That is why the patch changes the error path to release saved hosts through advansys_release(shost) instead of directly freeing the saved host pointers.

I also noticed that I accidentally removed the final kfree(data) while preparing the patch. That was an unintended editing mistake, and if the proposed cleanup approach is acceptable, I will fix it in v2.

Quoted 1 line

I've been told all your patches are AI slop, I'm not reviewing this.

If possible, could you please share what your assessment is based on?

Also, if there is any technical issue with this patch, I would appreciate it if you could point it out concretely. I’m happy to revise the patch if there is something incorrect in the analysis or in the fix itself.

Thanks,
Guangshuo

maintainer
#3 lore raw
In reply to Guangshuo Li
Quoted 33 lines · Guangshuo Li

A manual code audit found that advansys_eisa_probe() frees saved Scsi_Host objects directly in its error path.

Those hosts have already been successfully initialized by advansys_board_found(), so freeing them directly bypasses the normal teardown path and leaks host resources such as IRQs, DMA or MMIO resources, and the Scsi_Host release path.

Fix this by releasing the saved hosts with advansys_release() and dropping their corresponding I/O regions before freeing the probe data.

Fixes d361db483241 ("[SCSI] advansys: Sort out irq number mess")
---
  drivers/scsi/advansys.c | 14 +++++++++++---
  1 file changed, 11 insertions(+), 3 deletions(-)
drivers/scsi/advansys.c +4 -3
index fcf059bf41e8..022a8190ae31 100644
@@ -11373,9 +11373,17 @@ static int advansys_eisa_probe(struct device *dev)
  	return 0;
 
   free_data:
-	kfree(data->host[0]);
-	kfree(data->host[1]);
-	kfree(data);
+	for (i = 0; i < 2; i++) {
+		struct Scsi_Host *shost = data->host[i];
+		int ioport;
+

drivers/scsi/advansys.c static int advansys_eisa_probe(struct device *dev) · line 11389

Quoted 10 lines
drivers/scsi/advansys.c +7 -0
+		if (!shost)
+			continue;
+
+		ioport = shost->io_port;
+		advansys_release(shost);
+		release_region(ioport, ASC_IOADR_GAP);
+	}
   fail:
  	return err;
  }

You must be kidding ... EISA is died over a decade ago.

If you _really_ are concerned about this please remove EISA support completely from the driver.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                  Kernel Storage Architect
[email protected]                               +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
#4 lore raw

Hi Hannes,

Thanks for the feedback.

Quoted 7 lines · Hannes Reinecke

You must be kidding ... EISA is died over a decade ago.

If you _really_ are concerned about this please remove EISA support completely from the driver.

I agree that EISA is obsolete, and I understand that this path is unlikely to matter on modern systems. My intent was simply to clean up an inconsistency I noticed while reviewing the existing error handling code.

If maintaining the EISA path is not worthwhile, I’m fine with dropping this patch. I can also take a look at what removing the EISA support would involve.

Thanks,
Guangshuo

maintainer
#5 lore raw
Quoted 13 lines · Guangshuo Li

Hi Hannes,

Thanks for the feedback.

Quoted 7 lines · Hannes Reinecke

You must be kidding ... EISA is died over a decade ago.

If you _really_ are concerned about this please remove EISA support completely from the driver.

Quoted 9 lines

I agree that EISA is obsolete, and I understand that this path is unlikely to matter on modern systems. My intent was simply to clean up an inconsistency I noticed while reviewing the existing error handling code.

If maintaining the EISA path is not worthwhile, I’m fine with dropping this patch. I can also take a look at what removing the EISA support would involve.

Please, drop the patch, and rather invest time to check how to drop EISA support. Fixing issues for code paths which are never exercised is a bit pointless.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                  Kernel Storage Architect
[email protected]                               +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich