Skip to contentSkip to conversation

scsi: leapraid: Fix init_cmd_priv error handling

PATCH Superseded Dongdong Hao 2 participants 3 messages Nov 4

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Dongdong Hao

author maintainer
#0 lore raw

PATCH 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.

---
 drivers/scsi/leapraid/leapraid_os.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/leapraid/leapraid_os.c +1 -2
index da597eb99377..0f3219c4f438 100644
@@ -938,9 +938,8 @@ static int leapraid_init_cmd_priv(struct Scsi_Host *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, io_tracker);
 }
 
 static int leapraid_exit_cmd_priv(struct Scsi_Host *shost,
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 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.

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.

---
 drivers/scsi/leapraid/leapraid_os.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/leapraid/leapraid_os.c +0 -0
index da597eb99377..0f3219c4f438 100644

drivers/scsi/leapraid/leapraid_os.c static int leapraid_init_cmd_priv(struct Scsi_Host *shost, · line 942

Quoted 7 lines
drivers/scsi/leapraid/leapraid_os.c +1 -2
@@ -938,9 +938,8 @@ static int leapraid_init_cmd_priv(struct Scsi_Host *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, io_tracker);
	return leapraid_internal_init_cmd_priv(adapter, scsi_cmd_priv(scmd));

and you can remove the io_tracker local variable.

With that,

Note: when I sent out the SCSI ASC/ASCQ series rework, Sashiko had comments about pre-existing issues in the leapraid driver. See:

https://sashiko.dev/#/message/20260831021810.235281F000E9%40smtp.kernel.org

You may want to check that.

Signature · 2 lines
Damien Le Moal
Western Digital Research
author maintainer
#2 lore raw
Quoted 34 lines · Damien Le Moal
Quoted 23 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.

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.

---
 drivers/scsi/leapraid/leapraid_os.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/leapraid/leapraid_os.c +0 -0
index da597eb99377..0f3219c4f438 100644

drivers/scsi/leapraid/leapraid_os.c static int leapraid_init_cmd_priv(struct Scsi_Host *shost, · line 942

Quoted 7 lines
drivers/scsi/leapraid/leapraid_os.c +1 -2
@@ -938,9 +938,8 @@ static int leapraid_init_cmd_priv(struct Scsi_Host *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, io_tracker);
	return leapraid_internal_init_cmd_priv(adapter, scsi_cmd_priv(scmd));
Quoted 6 lines

and you can remove the io_tracker local variable.

With that,

Thanks, v2 is on the way.

Quoted 7 lines

Note: when I sent out the SCSI ASC/ASCQ series rework, Sashiko had comments about pre-existing issues in the leapraid driver. See:

https://sashiko.dev/#/message/20260831021810.235281F000E9%40smtp.kernel.org

You may want to check that.

As for the SCSI ASC/ASCQ series, we checked the report, but both scsi_build_sense() and scsi_set_sense() already set scmd->result to SAM_STAT_CHECK_CONDITION, so it looks like a false positive.