From: sashiko-bot@kernel.org
To: "Phil Pemberton" <philpem@philpem.me.uk>
Cc: dlemoal@kernel.org, cassel@kernel.org, linux-ide@vger.kernel.org
Subject: Re: [PATCH v5 5/6] ata: libata-scsi: probe additional LUNs for multi-LUN ATAPI devices
Date: Thu, 14 May 2026 02:33:54 +0000 [thread overview]
Message-ID: <20260514023355.57E36C19425@smtp.kernel.org> (raw)
In-Reply-To: <20260512202728.299414-6-philpem@philpem.me.uk>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Moving scsi_device_put(sdev) before ata_scsi_assign_ofnode(dev, ap) introduces a TOCTOU race condition that can result in a Use-After-Free or NULL pointer dereference.
--
commit cc077598d05a5231fc7b5c24f7dca060535cfe72
Author: Phil Pemberton <philpem@philpem.me.uk>
ata: libata-scsi: probe additional LUNs for multi-LUN ATAPI devices
This commit updates libata-scsi to check the BLIST_FORCELUN flag after LUN 0
is added for an ATAPI device. If set, it temporarily bumps dev->nr_luns to
the host's max_lun and triggers a sequential SCSI scan to probe additional
LUNs.
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
[ ... ]
> @@ -4745,12 +4746,30 @@ 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)) {
[ ... ]
> + if (dev->class == ATA_DEV_ATAPI &&
> + sdev->sdev_bflags & BLIST_FORCELUN) {
> + dev->nr_luns = ap->scsi_host->max_lun;
> + scsi_scan_target(
> + &ap->scsi_host->shost_gendev,
> + channel, id, SCAN_WILD_CARD,
> + SCSI_SCAN_RESCAN);
> + }
> scsi_device_put(sdev);
> - } else {
> - dev->sdev[0] = NULL;
> }
> +
> + if (dev->sdev[0])
> + ata_scsi_assign_ofnode(dev, ap);
Can this sequence cause a use-after-free or a NULL pointer dereference?
By moving ata_scsi_assign_ofnode() outside of the !IS_ERR(sdev) block and
after scsi_device_put(), the local reference to sdev is dropped before it
is accessed.
Because ata_scsi_scan_host() does not hold shost->scan_mutex, a concurrent
device removal via sysfs could execute as soon as the local reference is
dropped.
If scsi_remove_device() asynchronously clears dev->sdev[0] and frees the
sdev structure:
CPU1
ata_scsi_scan_host()
scsi_device_put(sdev);
CPU2
scsi_remove_device()
dev->sdev[0] = NULL;
// sdev is freed
CPU1
if (dev->sdev[0])
ata_scsi_assign_ofnode(dev, ap);
Could CPU1 evaluate the if statement before the pointer is cleared, but
execute ata_scsi_assign_ofnode() after it is freed, resulting in a write
to freed memory?
Alternatively, if it reads dev->sdev[0] after the pointer is cleared,
could this result in a NULL pointer dereference?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260512202728.299414-1-philpem@philpem.me.uk?part=5
next prev parent reply other threads:[~2026-05-14 2:33 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 20:27 [PATCH v5 0/6] ata: libata-scsi: multi-LUN ATAPI device support Phil Pemberton
2026-05-12 20:27 ` [PATCH v5 1/6] ata: libata-scsi: add atapi_max_lun module parameter Phil Pemberton
2026-05-14 0:12 ` sashiko-bot
2026-05-12 20:27 ` [PATCH v5 2/6] ata: libata-scsi: convert dev->sdev to per-LUN array Phil Pemberton
2026-05-13 13:07 ` Hannes Reinecke
2026-05-14 0:36 ` sashiko-bot
2026-05-12 20:27 ` [PATCH v5 3/6] ata: libata-scsi: route non-zero LUN commands for multi-LUN ATAPI Phil Pemberton
2026-05-13 13:11 ` Hannes Reinecke
2026-05-14 1:12 ` sashiko-bot
2026-05-12 20:27 ` [PATCH v5 4/6] scsi: add BLIST_NO_LUN_1F blacklist flag Phil Pemberton
2026-05-14 1:26 ` sashiko-bot
2026-05-12 20:27 ` [PATCH v5 5/6] ata: libata-scsi: probe additional LUNs for multi-LUN ATAPI devices Phil Pemberton
2026-05-13 13:12 ` Hannes Reinecke
2026-05-14 2:33 ` sashiko-bot [this message]
2026-05-12 20:27 ` [PATCH v5 6/6] scsi: scsi_devinfo: add COMPAQ PD-1 multi-LUN ATAPI device quirk Phil Pemberton
2026-05-14 2:48 ` 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=20260514023355.57E36C19425@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=cassel@kernel.org \
--cc=dlemoal@kernel.org \
--cc=linux-ide@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