All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "John Garry" <john.g.garry@oracle.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v4 13/28] scsi-multipath: introduce scsi_device head structure
Date: Thu, 23 Jul 2026 10:16:56 +0000	[thread overview]
Message-ID: <20260723101656.C50091F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260723093627.2327456-14-john.g.garry@oracle.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] `scsi_mpath_find_head()` prematurely aborts list search on dying heads, leading to split multipath topologies.
- [High] Double removal in `scsi_mpath_remove_device()` triggers a NULL pointer dereference.
- [High] Premature teardown of `scsi_mpath_head` causes a Use-After-Free on inflight bios.
- [Medium] The sysfs attribute `vpd_id` is exposed to userspace before it is initialized.
--

--- Patch [13]: [PATCH v4 13/28] scsi-multipath: introduce scsi_device head structure ---
commit 11c848a95f46ee71e21d42eee402d581f96c8055
Author: John Garry <john.garry@linux.dev>

scsi-multipath: introduce scsi_device head structure

Introduce a scsi_device head structure - scsi_mpath_head - to manage
multipathing for a scsi_device. This is similar to nvme_ns_head structure.

> diff --git a/drivers/scsi/scsi_multipath.c b/drivers/scsi/scsi_multipath.c
> index b9b58a3641aa2..609f8009e4ac3 100644
> --- a/drivers/scsi/scsi_multipath.c
> +++ b/drivers/scsi/scsi_multipath.c

[ ... ]

> @@ -89,6 +141,71 @@ static int scsi_multipath_sdev_init(struct scsi_device *sdev)
> +static struct scsi_mpath_head *scsi_mpath_alloc_head(void)
> +{

[ ... ]

> +	ret = device_add(&scsi_mpath_head->dev);
> +	if (ret) {
> +		put_device(&scsi_mpath_head->dev);
> +		return NULL;
> +	}
> +

[Severity: Medium]
Will calling device_add() here expose an uninitialized vpd_id string to
userspace when the uevent is fired?

The vpd_id is only populated later in scsi_mpath_dev_alloc() via strscpy().
Could a concurrently executing udev rule read an empty string before the
string has been properly set?

> +	return scsi_mpath_head;
> +
> +out_uninit_head:
> +	mpath_head_uninit(&scsi_mpath_head->mpath_head);
> +out_free:
> +	kfree(scsi_mpath_head);
> +	return NULL;
> +}
> +
> +static struct scsi_mpath_head *scsi_mpath_find_head(
> +			struct scsi_mpath_device *scsi_mpath_dev)
> +{
> +	struct scsi_mpath_head *scsi_mpath_head;
> +
> +	list_for_each_entry(scsi_mpath_head, &scsi_mpath_heads_list, entry) {
> +		if (strncmp(scsi_mpath_head->vpd_id,
> +			scsi_mpath_dev->device_id_str,
> +			SCSI_MPATH_DEVICE_ID_LEN) == 0) {
> +			if (scsi_mpath_get_head(scsi_mpath_head))
> +				return NULL;

[Severity: High]
If scsi_mpath_get_head() fails (for example, if the head is dying), does
returning NULL here prematurely abort the list search? Should this be a
continue statement so we don't skip over a valid head further down the
list?

> +			return scsi_mpath_head;
> +		}
> +	}
> +
> +	return NULL;
> +}

[ ... ]

> @@ -133,13 +290,47 @@ void scsi_mpath_dev_release(struct scsi_device *sdev)
> +void scsi_mpath_remove_device(struct scsi_mpath_device *scsi_mpath_dev)
> +{
> +	struct scsi_mpath_head *scsi_mpath_head = scsi_mpath_dev->scsi_mpath_head;
> +
> +	ida_free(&scsi_mpath_head->ida, scsi_mpath_dev->index);
> +
> +	scsi_mpath_remove_head(scsi_mpath_dev);
> +}
> +
>  void scsi_mpath_dev_release(struct scsi_device *sdev)
>  {
>  	struct scsi_mpath_device *scsi_mpath_dev = sdev->scsi_mpath_dev;
>  
> +	if (scsi_mpath_dev)
> +		scsi_mpath_remove_device(scsi_mpath_dev);

[Severity: High]
Is it possible for this to trigger a NULL pointer dereference if the
multipath device has already been detached?

In __scsi_remove_device(), we call scsi_mpath_remove_device() which sets
scsi_mpath_dev->scsi_mpath_head = NULL:

__scsi_remove_device()
    scsi_mpath_remove_device(sdev->scsi_mpath_dev)
        scsi_mpath_remove_head()
            scsi_mpath_dev->scsi_mpath_head = NULL;

When the device release callback runs later, it will call
scsi_mpath_remove_device() again because scsi_mpath_dev is still non-NULL,
leading to a crash when dereferencing scsi_mpath_head.

>  	scsi_multipath_sdev_uninit(sdev);
>  }

> diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
> index 2f80d703ce640..d6bbaf424bd4a 100644
> --- a/drivers/scsi/scsi_sysfs.c
> +++ b/drivers/scsi/scsi_sysfs.c
> @@ -1501,6 +1501,9 @@ void __scsi_remove_device(struct scsi_device *sdev)
>  	} else
>  		put_device(&sdev->sdev_dev);
>  
> +	if (sdev->scsi_mpath_dev)
> +		scsi_mpath_remove_device(sdev->scsi_mpath_dev);
> +

[Severity: High]
Could tearing down the multipath head here trigger a use-after-free for
inflight bios?

If this is the last path, the scsi_mpath_head could be unregistered and
freed before the request queue is drained in blk_mq_destroy_queue() later
in this function. When an inflight bio completes, its end_io callback might
try to access the freed head.

Should the multipath head removal happen after the queue is drained?

>  	/*
>  	 * Stop accepting new requests and wait until all queuecommand() and
>  	 * scsi_run_queue() invocations have finished before tearing down the

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260723093627.2327456-1-john.g.garry@oracle.com?part=13

  reply	other threads:[~2026-07-23 10:16 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 [this message]
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
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=20260723101656.C50091F000E9@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.