Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Damien Le Moal" <dlemoal@kernel.org>
Cc: cassel@kernel.org, "Alexander Gordeev" <agordeev@linux.ibm.com>,
	linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	dlemoal@kernel.org, linux-ide@vger.kernel.org,
	linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 22/40] scsi: myrX: use 16-bits defined sense codes
Date: Fri, 04 Sep 2026 01:53:17 +0000	[thread overview]
Message-ID: <20260904015318.5A6431F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260904002644.157668-23-dlemoal@kernel.org>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Missing error check for negative return value from scsi_dma_map(), leading to corrupted command submission.
- [High] DMA mapping resource leak on memory allocation failure.
- [High] The REQUEST_SENSE command handler fails to call scsi_done(), leading to a command timeout hang.
--

commit 3f2ef162e5ea4ec979ec96283f2b6fa4f8798741
Author: Damien Le Moal <dlemoal@kernel.org>
Subject: scsi: myrX: use 16-bits defined sense codes

This commit refactors the Mylex RAID controller driver to use
scsi_set_sense() and 16-bit sense codes from include/scsi/scsi_sense.h
instead of hard-coded values. This improves code clarity without any
intended functional changes.

> diff --git a/drivers/scsi/myrb.c b/drivers/scsi/myrb.c
> index 3678b66310ed0..e7d796add9864 100644
> --- a/drivers/scsi/myrb.c
> +++ b/drivers/scsi/myrb.c
[ ... ]
> @@ -1472,15 +1474,15 @@ static enum scsi_qc_status myrb_ldev_queuecommand(struct Scsi_Host *shost,
>  	case READ_CAPACITY:
>  		if ((scmd->cmnd[1] & 1) ||
>  		    (scmd->cmnd[8] & 1)) {
> -			/* Illegal request, invalid field in CDB */
> -			scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
> +			scsi_set_sense(scmd, 0, ILLEGAL_REQUEST,
> +				       INVALID_FIELD_IN_CDB);
>  			scsi_done(scmd);
>  			return 0;
>  		}

[Severity: High]
This isn't a bug introduced by this patch, but does the REQUEST_SENSE command
handler fail to call scsi_done() here?

In myrb_ldev_queuecommand():
	case REQUEST_SENSE:
		myrb_request_sense(cb, scmd);
		scmd->result = (DID_OK << 16);
		return 0;

It seems this returns success to the block layer without invoking the
scsi_done() completion callback. Any explicit REQUEST_SENSE command sent to
the device could hang indefinitely until the block layer timeout triggers
SCSI error recovery.

[ ... ]
> @@ -1544,8 +1546,8 @@ static enum scsi_qc_status myrb_ldev_queuecommand(struct Scsi_Host *shost,
>  		block_cnt = get_unaligned_be32(&scmd->cmnd[6]);
>  		break;
>  	default:
> -		/* Illegal request, invalid opcode */
> -		scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x20, 0);
> +		scsi_set_sense(scmd, 0, ILLEGAL_REQUEST,
> +			       INVALID_COMMAND_OP_CODE);
>  		scsi_done(scmd);
>  		return 0;
>  	}

[Severity: Critical]
This is a pre-existing issue, but is there a missing error check for a
negative return value from scsi_dma_map()?

Later in myrb_ldev_queuecommand():
	nsge = scsi_dma_map(scmd);
	if (nsge == 1) {
		...
	} else {
		struct myrb_sge *hw_sgl;
		...

If scsi_dma_map() fails and returns a negative error code (e.g. -ENOMEM),
the return value is stored in nsge. Since nsge < 0, the driver falls
through to the else block (as nsge != 1). The negative value is used as the
sg_count in hardware submission (which is an 8-bit unsigned integer,
converting to 244). The loop to initialize the hardware SG list is skipped,
and the command is submitted to the controller with an uninitialized or
partially initialized DMA mapping and a large sg_count. Can this cause the
hardware to read random garbage from memory and perform DMA transfers to
arbitrary physical addresses, leading to memory corruption or IOMMU faults?

[Severity: High]
This is also a pre-existing issue, but does this code leak the DMA mapping
if the memory allocation fails?

A few lines down in the same else block:
	} else {
		struct myrb_sge *hw_sgl;
		dma_addr_t hw_sgl_addr;
		int i;

		hw_sgl = dma_pool_alloc(cb->sg_pool, GFP_ATOMIC, &hw_sgl_addr);
		if (!hw_sgl)
			return SCSI_MLQUEUE_HOST_BUSY;

If dma_pool_alloc() fails, it returns SCSI_MLQUEUE_HOST_BUSY to have the
midlayer retry the command, but it seems to return without calling
scsi_dma_unmap(scmd). Under memory pressure, could this leak DMA mappings
repeatedly until the system hangs or crashes from IOMMU/bounce buffer
exhaustion?

> diff --git a/drivers/scsi/myrs.c b/drivers/scsi/myrs.c
> index afd68225221a6..1192b01fab8ec 100644
> --- a/drivers/scsi/myrs.c
> +++ b/drivers/scsi/myrs.c
[ ... ]
> @@ -1603,7 +1607,8 @@ static enum scsi_qc_status myrs_queuecommand(struct Scsi_Host *shost,
>  
>  	switch (scmd->cmnd[0]) {
>  	case REPORT_LUNS:
> -		scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x20, 0x0);
> +		scsi_set_sense(scmd, 0, ILLEGAL_REQUEST,
> +			       INVALID_COMMAND_OP_CODE);
>  		scsi_done(scmd);
>  		return 0;

[Severity: Critical]
This is a pre-existing issue, but is there a missing error check for a
negative return value from scsi_dma_map() here as well?

Later in myrs_queuecommand():
	nsge = scsi_dma_map(scmd);
	if (nsge == 1) {
		...
	} else {
		struct myrs_sge *hw_sgl;
		...

If scsi_dma_map() fails and returns a negative error code (like -ENOMEM),
nsge < 0 falls through to the else block. The negative value is used
as the sg_count in hardware submission, and the command is submitted
with an uninitialized or partially initialized DMA mapping. Can this cause
memory corruption or IOMMU faults?

[Severity: High]
This is a pre-existing issue, but does this code leak the DMA mapping
if the memory allocation fails?

Further down in myrs_queuecommand():
		if (nsge > 2) {
			hw_sgl = dma_pool_alloc(cs->sg_pool, GFP_ATOMIC,
						&hw_sgl_addr);
			if (WARN_ON(!hw_sgl)) {
				if (cmd_blk->dcdb) {
					dma_pool_free(cs->dcdb_pool,
						      cmd_blk->dcdb,
						      cmd_blk->dcdb_dma);
					cmd_blk->dcdb = NULL;
					cmd_blk->dcdb_dma = 0;
				}
				dma_pool_free(cs->sense_pool,
					      cmd_blk->sense,
					      cmd_blk->sense_addr);
				cmd_blk->sense = NULL;
				cmd_blk->sense_addr = 0;
				return SCSI_MLQUEUE_HOST_BUSY;
			}

When dma_pool_alloc() fails, it cleans up some allocations and returns
SCSI_MLQUEUE_HOST_BUSY. However, it seems to return without calling
scsi_dma_unmap(scmd) to unmap the memory mapped a few lines above.
Under memory pressure, could this leak DMA mappings repeatedly until
the system hangs or crashes from IOMMU/bounce buffer exhaustion?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260904002644.157668-1-dlemoal@kernel.org?part=22

  reply	other threads:[~2026-09-04  1:53 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04  0:26 [PATCH v3 00/40] Use defined 16-bits ASC/ASCQ combinations Damien Le Moal
2026-09-04  0:26 ` [PATCH v3 01/40] scsi: define all additional sense codes and their qualifiers Damien Le Moal
2026-09-04  0:38   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 02/40] scsi: constants: use defined sense codes Damien Le Moal
2026-09-04  0:36   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 03/40] scsi: constants: rename internal struct field names Damien Le Moal
2026-09-04  0:38   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 04/40] scsi: rename sense field of struct scsi_failure Damien Le Moal
2026-09-04  0:43   ` sashiko-bot
2026-09-04 10:08   ` Johannes Thumshirn
2026-09-04  0:26 ` [PATCH v3 05/40] scsi: prepare for using 16-bits defined sense codes Damien Le Moal
2026-09-04  0:45   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 06/40] scsi: use struct scsi_sense_hdr to log sense keys and codes Damien Le Moal
2026-09-04  0:48   ` sashiko-bot
2026-09-04 10:11   ` Johannes Thumshirn
2026-09-04  0:26 ` [PATCH v3 07/40] scsi: core: use 16-bits defined sense codes Damien Le Moal
2026-09-04  0:53   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 08/40] scsi: sd: " Damien Le Moal
2026-09-04  1:04   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 09/40] scsi: sr: " Damien Le Moal
2026-09-04  1:02   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 10/40] scsi: ses: " Damien Le Moal
2026-09-04  1:06   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 11/40] scsi: ch: " Damien Le Moal
2026-09-04  1:09   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 12/40] scsi: st: " Damien Le Moal
2026-09-04  1:11   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 13/40] scsi: device_handlers: hp_sw: " Damien Le Moal
2026-09-04  1:13   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 14/40] scsi: device_handlers: rdac: " Damien Le Moal
2026-09-04  1:15   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 15/40] scsi: device_handlers: emc: " Damien Le Moal
2026-09-04  1:20   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 16/40] scsi: device_handlers: alua: " Damien Le Moal
2026-09-04  1:27   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 17/40] scsi: mpt3sas: " Damien Le Moal
2026-09-04  1:26   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 18/40] scsi: mpi3mr: " Damien Le Moal
2026-09-04  1:32   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 19/40] scsi: 3w-xxxx: " Damien Le Moal
2026-09-04  1:33   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 20/40] scsi: leapraid: " Damien Le Moal
2026-09-04  1:39   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 21/40] scsi: megaraid: " Damien Le Moal
2026-09-04  1:42   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 22/40] scsi: myrX: " Damien Le Moal
2026-09-04  1:53   ` sashiko-bot [this message]
2026-09-04  0:26 ` [PATCH v3 23/40] scsi: smartpqi: " Damien Le Moal
2026-09-04  1:48   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 24/40] scsi: qla2xxx: " Damien Le Moal
2026-09-04  1:52   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 25/40] scsi: ps3rom: " Damien Le Moal
2026-09-04  2:00   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 26/40] scsi: lpfc: " Damien Le Moal
2026-09-04  2:00   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 27/40] scsi: stex: " Damien Le Moal
2026-09-04  2:08   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 28/40] scsi: mvumi: " Damien Le Moal
2026-09-04  2:12   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 29/40] scsi: libiscsi: " Damien Le Moal
2026-09-04  2:12   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 30/40] scsi: ibmvscsi_tgt: " Damien Le Moal
2026-09-04  2:20   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 31/40] scsi: scsi_debug: " Damien Le Moal
2026-09-04  2:23   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 32/40] scsi: hpsa: " Damien Le Moal
2026-09-04  2:27   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 33/40] scsi: storvsc: " Damien Le Moal
2026-09-04  2:41   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 34/40] target: " Damien Le Moal
2026-09-04  2:37   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 35/40] usb: storage: " Damien Le Moal
2026-09-04  2:43   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 36/40] cdrom: " Damien Le Moal
2026-09-04  2:46   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 37/40] ata: libata: " Damien Le Moal
2026-09-04  2:49   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 38/40] s390: scsi: " Damien Le Moal
2026-09-04  2:50   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 39/40] scsi: cleanup scsi_proto.h Damien Le Moal
2026-09-04  2:56   ` sashiko-bot
2026-09-04  0:26 ` [PATCH v3 40/40] scsi: remove scsi_build_sense() and scsi_build_sense_buffer() Damien Le Moal
2026-09-04  2:53   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260904015318.5A6431F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox