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 v7 5/6] ata: libata-scsi: probe additional LUNs for multi-LUN ATAPI devices
Date: Thu, 11 Jun 2026 03:01:15 +0000 [thread overview]
Message-ID: <20260611030115.77A1A1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260611024356.2769320-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]` in `ata_scsi_scan_host()` and re-fetching it inside `ata_scsi_assign_ofnode()`, potentially leading to a NULL pointer dereference.
--
commit 67ae5925dcb0647224ec016d88000305f0e5c2f2
Author: Phil Pemberton <philpem@philpem.me.uk>
ata: libata-scsi: probe additional LUNs for multi-LUN ATAPI devices
This commit probes additional LUNs for ATAPI devices with the BLIST_FORCELUN
flag by triggering a sequential LUN scan. Non-responding LUNs are silently
skipped. It also attempts to fix a TOCTOU window by calling
ata_scsi_assign_ofnode() before releasing the scsi_device reference.
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> index 2e3b5fd41d05f..64cb2860a67b1 100644
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
[ ... ]
> @@ -4754,13 +4755,27 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync)
[ ... ]
> + 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 holding the scsi_device reference
actually prevent the TOCTOU race here?
While this patch holds the scsi_device_put() until after the call to
ata_scsi_assign_ofnode(), a concurrent sysfs hot-unplug can trigger
scsi_remove_device(). This unconditionally calls ata_scsi_sdev_destroy(),
which safely acquires ap->lock and sets dev->sdev[0] = NULL, regardless of
the scsi_device refcount.
If dev->sdev[0] is cleared right after the unprotected if (dev->sdev[0])
check, the re-fetch inside ata_scsi_assign_ofnode() will return NULL:
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;
...
}
This would lead to a kernel panic when dereferencing sdev.
Could the local sdev pointer be passed directly to ata_scsi_assign_ofnode()
instead of re-fetching it from dev->sdev[0]?
> + scsi_device_put(sdev);
> }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260611024356.2769320-1-philpem@philpem.me.uk?part=5
parent reply other threads:[~2026-06-11 3:01 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20260611024356.2769320-6-philpem@philpem.me.uk>]
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=20260611030115.77A1A1F00893@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