From: sashiko-bot@kernel.org
To: "John Garry" <john.g.garry@oracle.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v4 25/28] scsi: sd: support multipath disk
Date: Thu, 23 Jul 2026 10:47:34 +0000 [thread overview]
Message-ID: <20260723104735.40A5C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260723093627.2327456-26-john.g.garry@oracle.com>
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
New issues:
- [High] Unconditional sd_mpath_put_disk() in sd_mpath_remove() destroys the multipath disk structure while delayed removal is pending, causing a use-after-free.
- [High] Uncanceled delayed work accesses freed mpath_head after sd_mpath_fail_probe unconditionally deletes the device.
- [High] Concurrent execution of sd_mpath_remove_head and sd_mpath_probe creates a race condition that incorrectly deletes a newly allocated gendisk.
- [Medium] Missing put_device() in sd_probe() error path for sd_mpath_add_disk() failure leaks sdkp and its parent's reference.
- [Medium] Error paths in sd_mpath_probe() call kfree() on a device object after device_initialize(), leaking kobject internals.
Pre-existing issues:
- [High] If sd_large_pool_create() fails, sd_probe() jumps to out_free_index bypassing device unregistration and freeing active sysfs device memory (sdkp).
--
--- Patch [25]: [PATCH v4 25/28] scsi: sd: support multipath disk ---
commit 7776d470d97b7568b27daa7f4e53e7184172c0bc
Author: John Garry <john.garry@linux.dev>
scsi: sd: support multipath disk
This commit adds support to attach a multipath disk. It allocates a
gendisk per path and marks them as hidden while keeping a global list of
sd_mpath_disks for matching scsi_devices.
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 36c745cbb2619..d5a37b1b312c3 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -4035,13 +4139,258 @@ static const struct attribute_group sd_mpath_disk_attr_group = {
[ ... ]
> +static int sd_mpath_probe(struct scsi_disk *sdkp)
> +{
[ ... ]
> + sd_mpath_disk->scsi_mpath_head = scsi_mpath_head;
> + device_initialize(&sd_mpath_disk->dev);
> + sd_mpath_disk->dev.class = &sd_mpath_disk_class;
[ ... ]
> + error = mpath_alloc_head_disk(mpath_head, &lim,
> + dev_to_node(dma_dev));
> + if (error)
> + goto out_free_disk;
[ ... ]
> +out_free_disk:
> + kfree(sd_mpath_disk);
[Severity: Medium]
Is it safe to call kfree() directly on the device object here?
Since device_initialize() was already called on sd_mpath_disk->dev,
shouldn't we use put_device() to prevent leaking resources allocated by
the kobject core?
[ ... ]
> +static void sd_mpath_remove(struct scsi_disk *sdkp)
> +{
[ ... ]
> + mutex_lock(&sd_mpath_disks_lock);
> + sd_mpath_disk->disk_count--;
> + if (!sd_mpath_disk->disk_count && mpath_can_remove_head(mpath_head)) {
> + list_del_init(&sd_mpath_disk->entry);
> + remove = true;
> + }
> + mutex_unlock(&sd_mpath_disks_lock);
> + mpath_remove_sysfs_link(mpath_device);
> + mpath_device->disk = NULL;
> +
> + if (remove) {
> + device_del(&sd_mpath_disk->dev);
> + mpath_remove_disk(mpath_head);
> + }
> + sd_mpath_put_disk(sd_mpath_disk);
> +}
[Severity: High]
Does this sequence risk a use-after-free if delayed removal is pending?
If mpath_can_remove_head() returns false, the object remains on the
global list and is not fully removed, but we unconditionally drop the
reference via sd_mpath_put_disk() at the end. This could free the object
while it is still globally accessible.
[ ... ]
> +static void sd_mpath_remove_head(struct scsi_mpath_head *scsi_mpath_head)
> +{
[ ... ]
> + list_del_init(&sd_mpath_disk->entry);
> + mutex_unlock(&sd_mpath_disks_lock);
> +
> + device_del(&sd_mpath_disk->dev);
> + mpath_remove_disk(mpath_head);
> + sd_mpath_put_disk(sd_mpath_disk);
> +}
[Severity: High]
Could dropping the mutex here race with a concurrent sd_mpath_probe()?
We drop sd_mpath_disks_lock before calling mpath_remove_disk(mpath_head).
If a new probe allocates a new disk and overwrites mpath_head->disk
in that window, mpath_remove_disk() might delete the newly allocated
gendisk instead of the old one being removed.
[ ... ]
> +static void sd_mpath_fail_probe(struct scsi_disk *sdkp)
> +{
[ ... ]
> + mutex_lock(&sd_mpath_disks_lock);
> + sd_mpath_disk->disk_count--;
> + if (!sd_mpath_disk->disk_count) {
> + list_del_init(&sd_mpath_disk->entry);
> + remove = true;
> + }
> + mutex_unlock(&sd_mpath_disks_lock);
> + mpath_device->disk = NULL;
> +
> + if (remove) {
> + device_del(&sd_mpath_disk->dev);
> + mpath_remove_disk(mpath_head);
> + }
> + sd_mpath_put_disk(sd_mpath_disk);
> +}
[Severity: High]
What happens if there is pending delayed work on mpath_head->remove_work
when we hit this error path? If a previous removal queued the work,
and a subsequent failed probe triggers this code, we delete and free the
head without canceling the delayed work. Will the workqueue then trigger
a use-after-free on the freed mpath_head?
[ ... ]
> @@ -4158,11 +4515,18 @@ static int sd_probe(struct scsi_device *sdp)
> sd_revalidate_disk(gd);
> if (sdp->sector_size > PAGE_SIZE) {
> if (sd_large_pool_create()) {
> + sd_mpath_fail_probe(sdkp);
> error = -ENOMEM;
> goto out_free_index;
> }
> }
[Severity: High]
This is a pre-existing issue, but can this lead to a use-after-free in
sysfs? At this point, device_add() has already succeeded. Bypassing
device_del() or device_unregister() and jumping directly to
out_free_index (which frees sdkp) leaves the device linked in the sysfs
hierarchy.
[ ... ]
> @@ -4184,6 +4549,19 @@ static int sd_probe(struct scsi_device *sdp)
> goto out;
> }
>
> + if (sdp->scsi_mpath_dev) {
> + error = sd_mpath_add_disk(sdkp);
> + if (error) {
> + sd_mpath_fail_probe(sdkp);
> + device_del(&sdkp->disk_dev);
> + del_gendisk(sdkp->disk);
> +
> + put_disk(sdkp->disk);
> + if (sdp->sector_size > PAGE_SIZE)
> + sd_large_pool_destroy();
> + goto out;
> + }
> + }
[Severity: Medium]
Are we leaking the scsi_disk structure and its parent reference here?
We call device_del(&sdkp->disk_dev), but we don't call put_device()
to drop the base reference acquired during device_initialize().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260723093627.2327456-1-john.g.garry@oracle.com?part=25
next prev parent reply other threads:[~2026-07-23 10:47 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 9:35 [PATCH v4 00/28] Native SCSI Multipath support John Garry
2026-07-23 9:35 ` [PATCH v4 01/28] libmultipath: Add initial framework John Garry
2026-07-23 9:50 ` sashiko-bot
2026-07-23 10:19 ` John Garry
2026-07-23 9:36 ` [PATCH v4 02/28] libmultipath: Add basic gendisk support John Garry
2026-07-23 9:57 ` sashiko-bot
2026-07-23 10:34 ` John Garry
2026-07-23 9:36 ` [PATCH v4 03/28] libmultipath: Add path selection support John Garry
2026-07-23 9:55 ` sashiko-bot
2026-07-23 10:28 ` John Garry
2026-07-23 9:36 ` [PATCH v4 04/28] libmultipath: Add bio handling John Garry
2026-07-23 9:36 ` [PATCH v4 05/28] libmultipath: Add support for mpath_device management John Garry
2026-07-23 9:58 ` sashiko-bot
2026-07-23 10:36 ` John Garry
2026-07-23 9:36 ` [PATCH v4 06/28] libmultipath: Add delayed removal support John Garry
2026-07-23 9:57 ` sashiko-bot
2026-07-23 10:33 ` John Garry
2026-07-23 9:36 ` [PATCH v4 07/28] libmultipath: Add sysfs helpers John Garry
2026-07-23 10:05 ` sashiko-bot
2026-07-23 10:37 ` John Garry
2026-07-23 9:36 ` [PATCH v4 08/28] libmultipath: Add mpath_bdev_report_zones() John Garry
2026-07-23 10:15 ` sashiko-bot
2026-07-23 10:39 ` John Garry
2026-07-23 9:36 ` [PATCH v4 09/28] libmultipath: Add support for block device IOCTL John Garry
2026-07-23 10:09 ` sashiko-bot
2026-07-23 10:38 ` John Garry
2026-07-23 9:36 ` [PATCH v4 10/28] libmultipath: Add mpath_bdev_getgeo() John Garry
2026-07-23 9:36 ` [PATCH v4 11/28] libmultipath: Add mpath_bdev_get_unique_id() John Garry
2026-07-23 9:36 ` [PATCH v4 12/28] scsi-multipath: introduce basic SCSI device support John Garry
2026-07-23 10:14 ` sashiko-bot
2026-07-23 9:36 ` [PATCH v4 13/28] scsi-multipath: introduce scsi_device head structure John Garry
2026-07-23 10:16 ` sashiko-bot
2026-07-23 10:47 ` John Garry
2026-07-23 9:36 ` [PATCH v4 14/28] scsi-multipath: provide sysfs link from to scsi_device John Garry
2026-07-23 9:36 ` [PATCH v4 15/28] scsi-multipath: support iopolicy John Garry
2026-07-23 10:20 ` sashiko-bot
2026-07-23 10:51 ` John Garry
2026-07-23 9:36 ` [PATCH v4 16/28] scsi-multipath: clone each bio John Garry
2026-07-23 10:27 ` sashiko-bot
2026-07-23 10:55 ` John Garry
2026-07-23 9:36 ` [PATCH v4 17/28] scsi-multipath: clear path when device is blocked John Garry
2026-07-23 10:33 ` sashiko-bot
2026-07-23 11:01 ` John Garry
2026-07-23 9:36 ` [PATCH v4 18/28] scsi-multipath: revalidate paths upon device unblock John Garry
2026-07-23 10:39 ` sashiko-bot
2026-07-23 11:15 ` John Garry
2026-07-23 9:36 ` [PATCH v4 19/28] scsi-multipath: failover handling John Garry
2026-07-23 10:36 ` sashiko-bot
2026-07-23 11:03 ` John Garry
2026-07-23 9:36 ` [PATCH v4 20/28] scsi-multipath: provide callbacks for path state John Garry
2026-07-23 10:36 ` sashiko-bot
2026-07-23 11:05 ` John Garry
2026-07-23 9:36 ` [PATCH v4 21/28] scsi-multipath: add scsi_mpath_{start,end}_request() John Garry
2026-07-23 10:32 ` sashiko-bot
2026-07-23 10:57 ` John Garry
2026-07-23 9:36 ` [PATCH v4 22/28] scsi-multipath: add delayed disk removal support John Garry
2026-07-23 10:39 ` sashiko-bot
2026-07-23 11:21 ` John Garry
2026-07-23 9:36 ` [PATCH v4 23/28] scsi: sd: add multipath disk class John Garry
2026-07-23 10:39 ` sashiko-bot
2026-07-23 11:21 ` John Garry
2026-07-23 9:36 ` [PATCH v4 24/28] scsi: sd: add multipath disk attr groups John Garry
2026-07-23 10:47 ` sashiko-bot
2026-07-23 11:22 ` John Garry
2026-07-23 9:36 ` [PATCH v4 25/28] scsi: sd: support multipath disk John Garry
2026-07-23 10:47 ` sashiko-bot [this message]
2026-07-23 11:27 ` John Garry
2026-07-23 16:52 ` John Garry
2026-07-23 9:36 ` [PATCH v4 26/28] scsi: sd: add mpath_dev file John Garry
2026-07-23 11:07 ` sashiko-bot
2026-07-23 11:30 ` John Garry
2026-07-23 9:36 ` [PATCH v4 27/28] scsi: sd: add mpath_numa_nodes dev attribute John Garry
2026-07-23 10:52 ` sashiko-bot
2026-07-23 11:30 ` John Garry
2026-07-23 9:36 ` [PATCH v4 28/28] scsi: sd: add mpath_queue_depth " John Garry
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=20260723104735.40A5C1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=john.g.garry@oracle.com \
--cc=linux-scsi@vger.kernel.org \
--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.