Skip to contentSkip to conversation

scsi: leapraid: Fix init_cmd_priv error handling

PATCH Applied Dongdong Hao 2 participants 2 messages Nov 4 – Nov 9

Subsystems (2)
lore
Share & tools
lore

Dongdong Hao

author maintainer
#0 lore raw

PATCH v2 1/1 scsi: leapraid: Fix init_cmd_priv error handling

leapraid_init_cmd_priv() ignores the return value of leapraid_internal_init_cmd_priv() and always returns success. If dma_pool_alloc() fails, io_tracker->chain remains NULL, but the SCSI midlayer considers the command successfully initialized.

A subsequent I/O requiring more than LEAPRAID_SGL_INLINE_THRESHOLD DMA-mapped scatter-gather entries dereferences the NULL chain buffer while building the chained SGL, causing a kernel crash.

Return the result of leapraid_internal_init_cmd_priv() so that allocation failures propagate to the SCSI midlayer and abort initialization of the affected request.

Changes in v2:
- Inline scsi_cmd_priv(scmd) and drop the io_tracker local variable.

---
 drivers/scsi/leapraid/leapraid_os.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/scsi/leapraid/leapraid_os.c +2 -8
index da597eb99377..749e50366dbc 100644
@@ -935,22 +935,16 @@ static int leapraid_init_cmd_priv(struct Scsi_Host *shost,
 				  struct scsi_cmnd *scmd)
 {
 	struct leapraid_adapter *adapter = shost_priv(shost);
-	struct leapraid_io_req_tracker *io_tracker;
 
-	io_tracker = scsi_cmd_priv(scmd);
-	leapraid_internal_init_cmd_priv(adapter, io_tracker);
-
-	return 0;
+	return leapraid_internal_init_cmd_priv(adapter, scsi_cmd_priv(scmd));
 }
 
 static int leapraid_exit_cmd_priv(struct Scsi_Host *shost,
 				  struct scsi_cmnd *scmd)
 {
 	struct leapraid_adapter *adapter = shost_priv(shost);
-	struct leapraid_io_req_tracker *io_tracker;
 
-	io_tracker = scsi_cmd_priv(scmd);
-	leapraid_internal_exit_cmd_priv(adapter, io_tracker);
+	leapraid_internal_exit_cmd_priv(adapter, scsi_cmd_priv(scmd));
 
 	return 0;
 }
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 10 lines · Dongdong Hao

leapraid_init_cmd_priv() ignores the return value of leapraid_internal_init_cmd_priv() and always returns success. If dma_pool_alloc() fails, io_tracker->chain remains NULL, but the SCSI midlayer considers the command successfully initialized.

A subsequent I/O requiring more than LEAPRAID_SGL_INLINE_THRESHOLD DMA-mapped scatter-gather entries dereferences the NULL chain buffer while building the chained SGL, causing a kernel crash.

[...]

Applied to 7.4/scsi-fixes, thanks!

[1/1] scsi: leapraid: Fix init_cmd_priv error handling

      https://git.kernel.org/mkp/scsi/c/04feb5fd2c23
Signature · 1 line
Martin K. Petersen