From: sashiko-bot@kernel.org
To: "Phil Pemberton" <philpem@philpem.me.uk>
Cc: linux-ide@vger.kernel.org, dlemoal@kernel.org,
linux-scsi@vger.kernel.org, cassel@kernel.org
Subject: Re: [PATCH v7 3/6] ata: libata-scsi: route non-zero LUN commands for multi-LUN ATAPI
Date: Thu, 11 Jun 2026 02:58:07 +0000 [thread overview]
Message-ID: <20260611025807.9FF511F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260611024356.2769320-4-philpem@philpem.me.uk>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] LUN validation incorrectly checks the host's max_lun instead of the device's LUN limit, breaking SAS HBAs and introducing a kernel panic vector.
- [High] Unconditionally clearing bits 7:5 of CDB byte 1 destroys command-specific parameters for standard MMC commands, breaking Blu-ray decryption.
- [High] Error handling routines for ATAPI do not propagate the non-zero LUN, causing atapi_eh_request_sense() to incorrectly fetch sense data for LUN 0.
--
commit 0fa4117328a093e17803a117416e6ddc64dee46b
Author: Phil Pemberton <philpem@philpem.me.uk>
ata: libata-scsi: route non-zero LUN commands for multi-LUN ATAPI
This patch modifies __ata_scsi_find_dev() to allow non-zero LUNs for ATAPI
devices and updates atapi_xlat() to encode the LUN into CDB byte 1 as
expected by older SCSI-2 era devices.
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> index b65358955cf17..2e3b5fd41d05f 100644
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
[ ... ]
> @@ -2958,6 +2958,20 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc)
> memset(qc->cdb, 0, dev->cdb_len);
> memcpy(qc->cdb, scmd->cmnd, scmd->cmd_len);
>
> + /*
> + * SCSI-2 CDB LUN encoding: bits 7:5 of byte 1 (3-bit field).
> + * Always clear those bits; only set them for non-zero LUNs.
> + */
> + qc->cdb[1] = qc->cdb[1] & 0x1f;
[Severity: High]
Could this unconditional masking cause a regression by destroying
command-specific parameters for standard MMC commands?
Modern ATAPI/MMC devices reuse these bits for essential parameters since they
no longer rely on LUN addressing inside the CDB. For example, the REPORT KEY
command (0xA4) relies on bits 7:6 of byte 1 for the Key Class. Clearing
these bits forces the Key Class to 0 (DVD CSS), which breaks Blu-ray AACS
decryption tools for SATA/ATAPI optical drives.
> + if (unlikely(scmd->device->lun)) {
> + if (WARN_ON_ONCE(scmd->device->host->max_lun > ATAPI_MAX_LUN ||
> + scmd->device->lun >= scmd->device->host->max_lun)) {
[Severity: High]
Does this check incorrectly validate against the host max_lun instead of the
device LUN limit?
On SAS HBAs (like mpt3sas), host->max_lun is legitimately set to very large
values (e.g., 16895). Because 16895 > 8 (ATAPI_MAX_LUN), any command sent to
a non-zero LUN on an ATAPI device attached to such an HBA will trigger this
WARN_ON_ONCE and fail with DID_ERROR.
On systems with panic_on_warn enabled, this will cause a kernel panic when a
multi-LUN ATAPI device is scanned.
[Severity: High]
Is there a missing update for error handling routines to propagate the
non-zero LUN, leading to a regression in sense data retrieval?
While this patch routes non-zero LUN commands by mutating CDB byte 1 in
atapi_xlat(), it appears this routing is missing from error handling. When a
command fails, ata_eh_analyze_tf() calls atapi_eh_request_sense().
In drivers/ata/libata-eh.c:atapi_eh_request_sense():
u8 cdb[ATAPI_CDB_LEN] =
{ REQUEST_SENSE, 0, 0, 0, SCSI_SENSE_BUFFERSIZE, 0 };
This constructs a hardcoded REQUEST_SENSE CDB with byte 1 explicitly set to
0. If an I/O error occurs on LUN 1, the kernel will fetch the sense data
for LUN 0 instead.
This could cause the SCSI midlayer to receive incorrect error status,
potentially masking legitimate I/O errors and leading to infinite retry
loops.
> + scmd->result = DID_ERROR << 16;
> + return 1;
> + }
> + qc->cdb[1] |= (u8)scmd->device->lun << 5;
> + }
> +
> qc->complete_fn = atapi_qc_complete;
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260611024356.2769320-1-philpem@philpem.me.uk?part=3
next prev parent reply other threads:[~2026-06-11 2:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 2:43 [PATCH v7 0/6] libata-scsi: multi-LUN ATAPI device support Phil Pemberton
2026-06-11 2:43 ` [PATCH v7 1/6] ata: libata-scsi: add atapi_max_lun module parameter Phil Pemberton
2026-06-11 2:43 ` [PATCH v7 2/6] ata: libata-scsi: convert dev->sdev to per-LUN array Phil Pemberton
2026-06-11 3:01 ` sashiko-bot
2026-06-11 6:21 ` Hannes Reinecke
2026-06-11 2:43 ` [PATCH v7 3/6] ata: libata-scsi: route non-zero LUN commands for multi-LUN ATAPI Phil Pemberton
2026-06-11 2:58 ` sashiko-bot [this message]
2026-06-11 2:43 ` [PATCH v7 4/6] scsi: add BLIST_NO_LUN_1F blacklist flag Phil Pemberton
2026-06-11 2:59 ` sashiko-bot
2026-06-11 2:43 ` [PATCH v7 5/6] ata: libata-scsi: probe additional LUNs for multi-LUN ATAPI devices Phil Pemberton
2026-06-11 3:01 ` sashiko-bot
2026-06-11 2:43 ` [PATCH v7 6/6] scsi: scsi_devinfo: add COMPAQ PD-1 multi-LUN ATAPI device quirk Phil Pemberton
2026-06-11 2:52 ` sashiko-bot
2026-06-11 6:22 ` Hannes Reinecke
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=20260611025807.9FF511F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=cassel@kernel.org \
--cc=dlemoal@kernel.org \
--cc=linux-ide@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=philpem@philpem.me.uk \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.