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 15/28] scsi-multipath: support iopolicy
Date: Thu, 23 Jul 2026 10:20:36 +0000	[thread overview]
Message-ID: <20260723102046.35B431F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260723093627.2327456-16-john.g.garry@oracle.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] Use-after-free on requeue_work during device teardown after sysfs store.
- [Low] Data race on global iopolicy module parameter.

Pre-existing issues:
- [High] TOCTOU race exposing uninitialized sysfs attributes to userspace.
--

--- Patch [15]: [PATCH v4 15/28] scsi-multipath: support iopolicy ---
commit d1b32244eafe032033fe9c1b3cb04bb7a990a08a
Author: John Garry <john.g.garry@oracle.com>

scsi-multipath: support iopolicy

This commit adds support for configuring the multipath I/O policy. It
introduces a new iopolicy member to the scsi_mpath_head structure and adds a
module parameter to set the default policy.

> diff --git a/drivers/scsi/scsi_multipath.c b/drivers/scsi/scsi_multipath.c
> index 59d1c0b2d3441..6228ff4be4ff7 100644
> --- a/drivers/scsi/scsi_multipath.c
> +++ b/drivers/scsi/scsi_multipath.c
> @@ -61,6 +61,23 @@ static const struct kernel_param_ops multipath_param_ops = {
>  module_param_cb(multipath, &multipath_param_ops, &scsi_multipath, 0444);
>  MODULE_PARM_DESC(multipath, "turn on native multipath support, options: on, off, always");
>  
> +static enum mpath_iopolicy_e iopolicy = MPATH_IOPOLICY_NUMA;
> +
> +static int scsi_mpath_set_iopolicy_param(const char *val, const struct kernel_param *kp)
> +{
> +	return mpath_set_iopolicy(val, &iopolicy);
> +}

[Severity: Low]
Does this introduce a data race on the global module parameter?

The global iopolicy variable is updated locklessly here, and read locklessly
when assigning it later in scsi_mpath_alloc_head(). Should this use
READ_ONCE() and WRITE_ONCE() to prevent KCSAN warnings and ensure proper
concurrency hygiene?

> +
> +static int scsi_mpath_get_iopolicy_param(char *buf, const struct kernel_param *kp)
> +{
> +	return mpath_get_iopolicy(buf, iopolicy);
> +}
> +
> +module_param_call(multipath_iopolicy, scsi_mpath_set_iopolicy_param,
> +		scsi_mpath_get_iopolicy_param, &iopolicy, 0644);
> +MODULE_PARM_DESC(multipath_iopolicy,
> +	"Default multipath I/O policy; 'numa' (default), 'round-robin' or 'queue-depth'");
> +

[ ... ]

> @@ -96,8 +113,36 @@ static ssize_t scsi_mpath_device_vpd_id_show(struct device *dev,
>  }
>  static DEVICE_ATTR(vpd_id, S_IRUGO, scsi_mpath_device_vpd_id_show, NULL);
>  
> +static ssize_t scsi_mpath_device_iopolicy_store(struct device *dev,
> +		struct device_attribute *attr, const char *buf, size_t count)
> +{
> +	struct scsi_mpath_head *scsi_mpath_head =
> +		container_of(dev, struct scsi_mpath_head, dev);
> +	struct mpath_head *mpath_head = &scsi_mpath_head->mpath_head;
> +
> +	if (!mpath_iopolicy_store(&scsi_mpath_head->iopolicy, buf))
> +		return -EINVAL;
> +
> +	mpath_clear_paths(mpath_head);
> +	mpath_schedule_requeue_work(mpath_head);

[Severity: High]
Can mpath_schedule_requeue_work() trigger a use-after-free during device
teardown?

If a sysfs write occurs concurrently with device removal, the asynchronous
requeue work is scheduled here. The teardown path in scsi_mpath_head_release()
frees the scsi_mpath_head structure without calling cancel_work_sync() to
cancel this pending work.

Could the workqueue access freed memory when it executes the queued function?

> +	return count;
> +}
> +
> +static ssize_t scsi_mpath_device_iopolicy_show(struct device *dev,
> +		struct device_attribute *attr, char *buf)
> +{

[ ... ]

> @@ -201,6 +246,8 @@ static struct scsi_mpath_head *scsi_mpath_alloc_head(void)
>  	if (mpath_head_init(&scsi_mpath_head->mpath_head))
>  		goto out_free;
>  	scsi_mpath_head->mpath_head.mpdt = &smpdt;
> +	scsi_mpath_head->iopolicy = iopolicy;
> +	scsi_mpath_head->mpath_head.iopolicy = &scsi_mpath_head->iopolicy;
>  
>  	scsi_mpath_head->index = ida_alloc(&scsi_multipath_dev_ida, GFP_KERNEL);
>  	if (scsi_mpath_head->index < 0)

[Severity: High]
This is a pre-existing issue, but does this allocation path contain a race
condition exposing uninitialized sysfs attributes to userspace?

Later in scsi_mpath_alloc_head(), device_add() is called which registers the
device and fires a KOBJ_ADD uevent. However, the caller scsi_mpath_dev_alloc()
only populates the scsi_mpath_head->vpd_id data after scsi_mpath_alloc_head()
returns.

Could userspace udev rules react to the new device and read an empty vpd_id
string before it is fully initialized?

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

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