* Re: [PATCH v7 5/6] ata: libata-scsi: probe additional LUNs for multi-LUN ATAPI devices
[not found] <20260611024356.2769320-6-philpem@philpem.me.uk>
@ 2026-06-11 3:01 ` sashiko-bot
0 siblings, 0 replies; only message in thread
From: sashiko-bot @ 2026-06-11 3:01 UTC (permalink / raw)
To: Phil Pemberton; +Cc: dlemoal, cassel, linux-ide, linux-scsi
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
^ permalink raw reply [flat|nested] only message in thread