From: sashiko-bot@kernel.org
To: "John Garry" <john.g.garry@oracle.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v4 19/28] scsi-multipath: failover handling
Date: Thu, 23 Jul 2026 10:36:19 +0000 [thread overview]
Message-ID: <20260723103620.816C81F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260723093627.2327456-20-john.g.garry@oracle.com>
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Missing bi_next clearing in bio_list_add_clone() leads to corrupted bio requeue list.
- [High] Releasing the SCSI device via scsi_device_put() causes a module reference count underflow due to mismatched API usage.
- [High] Uninitialized mpath_device->mpath_head leads to a guaranteed NULL pointer dereference during failover.
- [High] The scsi_mpath_clone_end_io handler dereferences mpath_head after it has been freed during path device removal.
- [High] Missing cancel_work_sync() allows requeue_work to execute after scsi_mpath_head is freed.
--
--- Patch [19]: [PATCH v4 19/28] scsi-multipath: failover handling ---
commit e8daaaa500b47bda767344af0f467a56fa0a6095
Author: John Garry <john.garry@linux.dev>
scsi-multipath: failover handling
Failover occurs when the scsi_cmnd has failed and it is discovered that the
target scsi_device has transport down. For a scsi command which suffers
failover, requeue the master bio of each bio attached to its request.
> diff --git a/drivers/scsi/scsi_multipath.c b/drivers/scsi/scsi_multipath.c
> index b896d28a7dd9a..a482b6ede21aa 100644
> --- a/drivers/scsi/scsi_multipath.c
> +++ b/drivers/scsi/scsi_multipath.c
> @@ -248,11 +248,53 @@ void scsi_mpath_dev_clear_path(struct scsi_mpath_device *scsi_mpath_dev)
> mpath_synchronize(mpath_head);
> }
>
> +static inline void bio_list_add_clone(struct bio_list *bl,
> + struct bio *clone)
> +{
> + struct bio *master_bio = clone->bi_private;
> +
> + if (bl->tail)
> + bl->tail->bi_next = master_bio;
> + else
> + bl->head = master_bio;
> + bl->tail = master_bio;
[Severity: High]
Since master_bio is appended to the tail of the bio_list, shouldn't its
bi_next pointer be explicitly cleared to null to properly terminate the
singly-linked list?
When mpath_requeue_work() later iterates through the list, couldn't this
cause it to follow a stale bi_next pointer past the end of the list?
> + bio_put(clone);
> +}
> +
> static void scsi_mpath_clone_end_io(struct bio *clone)
> {
> struct bio *master_bio = clone->bi_private;
>
> master_bio->bi_status = clone->bi_status;
> +
> + if (clone->bi_status && blk_path_error(clone->bi_status)) {
> + struct block_device *bi_bdev = clone->bi_bdev;
> + struct request_queue *q = bi_bdev->bd_queue;
> + struct scsi_device *sdev = scsi_device_from_queue(q);
> + struct scsi_mpath_device *scsi_mpath_dev;
> + struct mpath_device *mpath_device;
> + struct mpath_head *mpath_head;
> + unsigned long flags;
> +
> + if (!sdev) {
> + master_bio->bi_status = clone->bi_status;
> + goto end_bio;
> + }
> +
> + scsi_mpath_dev = sdev->scsi_mpath_dev;
> + mpath_device = &scsi_mpath_dev->mpath_device;
> + mpath_head = mpath_device->mpath_head;
[Severity: High]
Is mpath_device->mpath_head guaranteed to be initialized here?
If scsi_mpath_dev_alloc() initializes scsi_mpath_dev with kzalloc but never
assigns this pointer, wouldn't this cause a null pointer dereference when
accessing requeue_lock below?
[Severity: High]
Could an in-flight I/O completion racing with path removal extract a freed
mpath_head here?
If scsi_mpath_remove_device() drops the reference to scsi_mpath_head and
frees it, but sdev->scsi_mpath_dev remains valid, it seems this could lead
to a use-after-free when accessing its requeue_lock.
> +
> + spin_lock_irqsave(&mpath_head->requeue_lock, flags);
> + bio_list_add_clone(&mpath_head->requeue_list, clone);
> + spin_unlock_irqrestore(&mpath_head->requeue_lock, flags);
> +
> + mpath_schedule_requeue_work(mpath_head);
[Severity: High]
When we schedule this requeue work, is there a corresponding cancel_work_sync()
during cleanup?
Looking at scsi_mpath_head_release(), it frees scsi_mpath_head without
cancelling or flushing mpath_head->requeue_work. Could this allow a
use-after-free if the background worker runs after the head is freed?
> + scsi_device_put(sdev);
[Severity: High]
Will this cause a module reference count underflow?
scsi_device_from_queue() only acquires a device reference via get_device(),
but scsi_device_put() drops both the device and module reference. Should
this use put_device(&sdev->sdev_gendev) instead?
> + return;
> + }
> +
> +end_bio:
> bio_put(clone);
> bio_endio(master_bio);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260723093627.2327456-1-john.g.garry@oracle.com?part=19
next prev parent reply other threads:[~2026-07-23 10:36 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 [this message]
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=20260723103620.816C81F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox