From: sashiko-bot@kernel.org
To: "Phil Pemberton" <philpem@philpem.me.uk>
Cc: dlemoal@kernel.org, cassel@kernel.org, linux-ide@vger.kernel.org,
linux-scsi@vger.kernel.org
Subject: Re: [PATCH v8 5/6] ata: libata-scsi: probe additional LUNs for multi-LUN ATAPI devices
Date: Fri, 31 Jul 2026 22:10:27 +0000 [thread overview]
Message-ID: <20260731221027.B79171F00AC4@smtp.kernel.org> (raw)
In-Reply-To: <20260731213503.2379771-6-philpem@philpem.me.uk>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] A Time-of-Check to Time-of-Use (TOCTOU) race condition exists between checking `dev->sdev[0]` and dereferencing it inside `ata_scsi_assign_ofnode()`, potentially leading to a NULL pointer dereference.
--
--- Patch [5]: [PATCH v8 5/6] ata: libata-scsi: probe additional LUNs for multi-LUN ATAPI devices ---
commit 26698e8a692fea36d598b32f39fd7513b22c4cf9
Author: Phil Pemberton <philpem@philpem.me.uk>
ata: libata-scsi: probe additional LUNs for multi-LUN ATAPI devices
This commit checks the BLIST_FORCELUN flag after LUN 0 is added for an ATAPI
device. If set, it triggers a sequential LUN scan for that target using
scsi_scan_target() to probe additional LUNs. It also moves the call to
ata_scsi_assign_ofnode() before scsi_device_put() to hold the device reference.
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> index 0b1e4842860c1..5bbb3169bea70 100644
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
[ ... ]
> @@ -5281,13 +5282,27 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync)
>
> sdev = __scsi_add_device(ap->scsi_host, channel, id, 0,
> NULL);
> - if (!IS_ERR(sdev)) {
> - dev->sdev[0] = sdev;
> - ata_scsi_assign_ofnode(dev, ap);
> - scsi_device_put(sdev);
> - } else {
> + if (IS_ERR(sdev)) {
> dev->sdev[0] = NULL;
> + continue;
> }
> +
> + /*
> + * For multi-LUN ATAPI (BLIST_FORCELUN), trigger a
> + * sequential scan for this target. pdt_1f_for_no_lun,
> + * set during LUN 0 configure, ensures non-responding
> + * LUNs are silently skipped; dev->sdev[] is populated
> + * by ata_scsi_dev_config() during the scan.
> + */
> + if (dev->class == ATA_DEV_ATAPI &&
> + sdev->sdev_bflags & BLIST_FORCELUN &&
> + !WARN_ON_ONCE(ap->scsi_host->max_lun > ATAPI_MAX_LUN))
> + scsi_scan_target(&ap->scsi_host->shost_gendev,
> + channel, id, SCAN_WILD_CARD,
> + SCSI_SCAN_RESCAN);
> + if (dev->sdev[0])
> + ata_scsi_assign_ofnode(dev, ap);
[Severity: High]
This is a pre-existing issue, but does this check leave a race condition where
concurrent device removals can cause a NULL pointer dereference?
In ata_scsi_scan_host(), the lockless if (dev->sdev[0]) check is evaluated
after releasing shost->scan_mutex (which was temporarily held by the preceding
scsi_scan_target and __scsi_add_device calls).
Concurrently, a hot-unplug event can trigger ata_scsi_remove_dev() on a
workqueue, which takes the scan_mutex and sets dev->sdev[0] = NULL.
If this concurrent removal occurs exactly after the check but before
ata_scsi_assign_ofnode() re-reads dev->sdev[0]:
drivers/ata/libata-scsi.c:ata_scsi_assign_ofnode() {
struct scsi_device *sdev = ata_dev_scsi_device(dev, 0);
...
sdev->sdev_gendev.of_node = child;
}
Can sdev be NULL when it is unconditionally dereferenced? Would it be safer
to pass the safely refcounted local sdev directly to ata_scsi_assign_ofnode()?
> + scsi_device_put(sdev);
> }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260731213503.2379771-1-philpem@philpem.me.uk?part=5
next prev parent reply other threads:[~2026-07-31 22:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 21:34 [PATCH v8 0/6] libata-scsi: multi-LUN ATAPI device support Phil Pemberton
2026-07-31 21:34 ` [PATCH v8 1/6] ata: libata-scsi: add atapi_max_lun module parameter Phil Pemberton
2026-07-31 21:34 ` [PATCH v8 2/6] ata: libata-scsi: convert dev->sdev to per-LUN array Phil Pemberton
2026-07-31 22:07 ` sashiko-bot
2026-07-31 21:35 ` [PATCH v8 3/6] ata: libata-scsi: route non-zero LUN commands for multi-LUN ATAPI Phil Pemberton
2026-07-31 22:07 ` sashiko-bot
2026-07-31 21:35 ` [PATCH v8 4/6] scsi: add BLIST_NO_LUN_1F blacklist flag Phil Pemberton
2026-07-31 22:04 ` sashiko-bot
2026-07-31 21:35 ` [PATCH v8 5/6] ata: libata-scsi: probe additional LUNs for multi-LUN ATAPI devices Phil Pemberton
2026-07-31 22:10 ` sashiko-bot [this message]
2026-07-31 21:35 ` [PATCH v8 6/6] scsi: scsi_devinfo: add COMPAQ PD-1 multi-LUN ATAPI device quirk Phil Pemberton
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=20260731221027.B79171F00AC4@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox