Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: leapraid: Fix init_cmd_priv error handling
@ 2026-11-04  3:18 Dongdong Hao
  2026-11-04  6:49 ` Damien Le Moal
  0 siblings, 1 reply; 3+ messages in thread
From: Dongdong Hao @ 2026-11-04  3:18 UTC (permalink / raw)
  To: James.Bottomley, martin.petersen
  Cc: dlemoal, hare, hare, doubled, yjzhang, kezijie, jzzhang, baikefan,
	linux-scsi

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.

Signed-off-by: Dongdong Hao <doubled@leap-io-kernel.com>
---
 drivers/scsi/leapraid/leapraid_os.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/leapraid/leapraid_os.c b/drivers/scsi/leapraid/leapraid_os.c
index da597eb99377..0f3219c4f438 100644
--- a/drivers/scsi/leapraid/leapraid_os.c
+++ b/drivers/scsi/leapraid/leapraid_os.c
@@ -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,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: leapraid: Fix init_cmd_priv error handling
  2026-11-04  3:18 [PATCH] scsi: leapraid: Fix init_cmd_priv error handling Dongdong Hao
@ 2026-11-04  6:49 ` Damien Le Moal
  2026-11-04  8:31   ` Hao Dongdong
  0 siblings, 1 reply; 3+ messages in thread
From: Damien Le Moal @ 2026-11-04  6:49 UTC (permalink / raw)
  To: Dongdong Hao, James.Bottomley, martin.petersen
  Cc: hare, hare, yjzhang, kezijie, jzzhang, baikefan, linux-scsi

On 11/4/26 12:18, Dongdong Hao wrote:
> 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.
> 
> Signed-off-by: Dongdong Hao <doubled@leap-io-kernel.com>
> ---
>  drivers/scsi/leapraid/leapraid_os.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/leapraid/leapraid_os.c b/drivers/scsi/leapraid/leapraid_os.c
> index da597eb99377..0f3219c4f438 100644
> --- a/drivers/scsi/leapraid/leapraid_os.c
> +++ b/drivers/scsi/leapraid/leapraid_os.c
> @@ -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,

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>

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.


-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: leapraid: Fix init_cmd_priv error handling
  2026-11-04  6:49 ` Damien Le Moal
@ 2026-11-04  8:31   ` Hao Dongdong
  0 siblings, 0 replies; 3+ messages in thread
From: Hao Dongdong @ 2026-11-04  8:31 UTC (permalink / raw)
  To: Damien Le Moal, James.Bottomley, martin.petersen
  Cc: hare, hare, yjzhang, kezijie, jzzhang, baikefan, linux-scsi

在 2026/11/4 14:49, Damien Le Moal 写道:
> On 11/4/26 12:18, Dongdong Hao wrote:
>> 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.
>>
>> Signed-off-by: Dongdong Hao <doubled@leap-io-kernel.com>
>> ---
>>  drivers/scsi/leapraid/leapraid_os.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/drivers/scsi/leapraid/leapraid_os.c b/drivers/scsi/leapraid/leapraid_os.c
>> index da597eb99377..0f3219c4f438 100644
>> --- a/drivers/scsi/leapraid/leapraid_os.c
>> +++ b/drivers/scsi/leapraid/leapraid_os.c
>> @@ -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,
> 
> Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
> 

Thanks, v2 is on the way.

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-04  8:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04  3:18 [PATCH] scsi: leapraid: Fix init_cmd_priv error handling Dongdong Hao
2026-11-04  6:49 ` Damien Le Moal
2026-11-04  8:31   ` Hao Dongdong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox