scsi: leapraid: Fix init_cmd_priv error handling
Subsystems (2)
Dongdong Hao
maintainerPATCH 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
@@ -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
Quoted 10 lines · Dongdong Hao
leapraid_init_cmd_priv()ignores the return value ofleapraid_internal_init_cmd_priv()and always returns success. Ifdma_pool_alloc()fails,io_tracker->chainremains NULL, but the SCSI midlayer considers the command successfully initialized.A subsequent I/O requiring more than
LEAPRAID_SGL_INLINE_THRESHOLDDMA-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