Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: John Garry <john.garry@linux.dev>
To: sashiko-reviews@lists.linux.dev, John Garry <john.g.garry@oracle.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v8 18/27] scsi-multipath: failover handling
Date: Mon, 7 Sep 2026 13:13:56 +0100	[thread overview]
Message-ID: <6cdf70ce-aba6-4377-bdaf-2efddae55fd1@linux.dev> (raw)
In-Reply-To: <20260907120233.8A50C1F00A3A@smtp.kernel.org>

On 9/7/26 13:02, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [High] Missing cancellation of `requeue_work` during `scsi_mpath_head` destruction leads to Use-After-Free.
> - [Low] The custom `bio_list_add_master()` function is an unnecessary and unsafe reinvention of `bio_list_add()`.
> --
> 
> commit 9189539f81df33ce64a7c19420baf37ebf587b37
> Author: John Garry <john.garry@linux.dev>
> 
> scsi-multipath: failover handling
> 
> This patch implements failover handling for SCSI commands when the target
> device's transport is down. It requeues the master bio of each attached
> bio when a failover occurs, using scsi_mpath_clone_end_io() to handle
> the failover process.
> 
>> diff --git a/drivers/scsi/scsi_multipath.c b/drivers/scsi/scsi_multipath.c
>> index 456351fee4b98..12200664ed676 100644
>> --- a/drivers/scsi/scsi_multipath.c
>> +++ b/drivers/scsi/scsi_multipath.c
>> @@ -256,10 +256,34 @@ void scsi_mpath_dev_clear_path(struct scsi_mpath_device *scsi_mpath_dev)
>>                  mpath_synchronize(mpath_head);
>>   }
>>   
>> +static inline void bio_list_add_master(struct bio_list *bl,
>> +				struct bio *master_bio)
>> +{
>> +	if (bl->tail)
>> +		bl->tail->bi_next = master_bio;
>> +	else
>> +		bl->head = master_bio;
>> +	bl->tail = master_bio;
>> +}
> 
> [Severity: Low]
> Is it necessary to use this custom list insertion function instead of the
> standard bio_list_add()?
 > > This custom bio_list_add_master() function mimics bio_list_add() 
but omits
> the master_bio->bi_next = NULL assignment. While master_bio->bi_next is
> structurally guaranteed to be NULL in the block layer at this point,
> reinventing bio_list_add() without its safety guarantees seems to add
> unnecessary complexity and a theoretical risk of singly-linked list
> corruption.

As mentioned, The NULLify of master_bio->bi_next is unneeded. But I 
suppose we can use bio_list_add() - I can do it later

> 
>> +
>>   static void scsi_mpath_clone_end_io(struct bio *clone)
>>   {
>>   	struct bio *master_bio = clone->bi_private;
>>   
>> +	if (clone->bi_status && blk_path_error(clone->bi_status)) {
>> +		struct mpath_head *mpath_head =
>> +				master_bio->bi_bdev->bd_disk->private_data;
>> +		unsigned long flags;
>> +
>> +		spin_lock_irqsave(&mpath_head->requeue_lock, flags);
>> +		bio_list_add_master(&mpath_head->requeue_list, master_bio);
>> +		spin_unlock_irqrestore(&mpath_head->requeue_lock, flags);
>> +		bio_put(clone);
>> +
>> +		mpath_schedule_requeue_work(mpath_head);
> 
> [Severity: High]
> Can scheduling this requeue work lead to a use-after-free during device
> destruction?
> 
> While the I/O failover path here is protected for disk devices because
> del_gendisk() blocks until the bio completes, non-disk SCSI devices
> (like tape drives) do not create an mpath disk. 

We don't support them.

> If an ALUA state change
> event triggers scsi_mpath_revalidate_paths(), requeue_work can be scheduled.
> 
> If the device is hot-removed, scsi_mpath_head_release() frees the
> scsi_mpath_head structure without calling
> cancel_work_sync(&mpath_head->requeue_work):
> 
> drivers/scsi/scsi_multipath.c:scsi_mpath_head_release() {
>      ...
>      mpath_head_uninit(mpath_head);
>      kfree(scsi_mpath_head);
> }
> 
> If asynchronous mpath_requeue_work() executes after the structure is freed,
> it could access the freed mpath_head structure and cause a kernel panic.
> 
>> +		return;
>> +	}
>> +
>>   	master_bio->bi_status = clone->bi_status;
>>   	bio_put(clone);
>>   	bio_endio(master_bio);
>>
> 


  reply	other threads:[~2026-09-07 12:13 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07 10:49 [PATCH v8 00/27] Native SCSI Multipath support John Garry
2026-09-07 10:49 ` [PATCH v8 01/27] libmultipath: Add initial framework John Garry
2026-09-07 10:49 ` [PATCH v8 02/27] libmultipath: Add basic gendisk support John Garry
2026-09-07 10:49 ` [PATCH v8 03/27] libmultipath: Add path selection support John Garry
2026-09-07 11:09   ` sashiko-bot
2026-09-07 12:00     ` John Garry
2026-09-07 10:49 ` [PATCH v8 04/27] libmultipath: Add bio handling John Garry
2026-09-07 10:49 ` [PATCH v8 05/27] libmultipath: Add support for mpath_device management John Garry
2026-09-07 10:50 ` [PATCH v8 06/27] libmultipath: Add delayed removal support John Garry
2026-09-07 11:23   ` sashiko-bot
2026-09-07 12:01     ` John Garry
2026-09-07 10:50 ` [PATCH v8 07/27] libmultipath: Add sysfs helpers John Garry
2026-09-07 10:50 ` [PATCH v8 08/27] libmultipath: Add support for block device IOCTL John Garry
2026-09-07 10:50 ` [PATCH v8 09/27] libmultipath: Add mpath_bdev_getgeo() John Garry
2026-09-07 10:50 ` [PATCH v8 10/27] libmultipath: Add mpath_bdev_get_unique_id() John Garry
2026-09-07 10:50 ` [PATCH v8 11/27] scsi-multipath: introduce basic SCSI device support John Garry
2026-09-07 11:33   ` sashiko-bot
2026-09-07 12:06     ` John Garry
2026-09-07 10:50 ` [PATCH v8 12/27] scsi-multipath: introduce scsi_device head structure John Garry
2026-09-07 10:50 ` [PATCH v8 13/27] scsi-multipath: provide sysfs link from to scsi_device John Garry
2026-09-07 10:50 ` [PATCH v8 14/27] scsi-multipath: support iopolicy John Garry
2026-09-07 10:50 ` [PATCH v8 15/27] scsi-multipath: clone each bio John Garry
2026-09-07 11:45   ` sashiko-bot
2026-09-07 12:08     ` John Garry
2026-09-07 10:50 ` [PATCH v8 16/27] scsi-multipath: clear path when device is blocked John Garry
2026-09-07 11:49   ` sashiko-bot
2026-09-07 12:08     ` John Garry
2026-09-07 10:50 ` [PATCH v8 17/27] scsi-multipath: revalidate paths upon device unblock John Garry
2026-09-07 11:56   ` sashiko-bot
2026-09-07 12:10     ` John Garry
2026-09-07 10:50 ` [PATCH v8 18/27] scsi-multipath: failover handling John Garry
2026-09-07 12:02   ` sashiko-bot
2026-09-07 12:13     ` John Garry [this message]
2026-09-07 10:50 ` [PATCH v8 19/27] scsi-multipath: provide callbacks for path state John Garry
2026-09-07 12:03   ` sashiko-bot
2026-09-07 12:14     ` John Garry
2026-09-07 10:50 ` [PATCH v8 20/27] scsi-multipath: add scsi_mpath_{start,end}_request() John Garry
2026-09-07 12:09   ` sashiko-bot
2026-09-07 12:22     ` John Garry
2026-09-07 10:50 ` [PATCH v8 21/27] scsi-multipath: add delayed disk removal support John Garry
2026-09-07 10:50 ` [PATCH v8 22/27] scsi: sd: add multipath disk class John Garry
2026-09-07 10:50 ` [PATCH v8 23/27] scsi: sd: add multipath disk attr groups John Garry
2026-09-07 10:50 ` [PATCH v8 24/27] scsi: sd: support multipath disk John Garry
2026-09-07 12:25   ` sashiko-bot
2026-09-07 12:34     ` John Garry
2026-09-07 10:50 ` [PATCH v8 25/27] scsi: sd: add mpath_dev file John Garry
2026-09-07 10:50 ` [PATCH v8 26/27] scsi: sd: add mpath_numa_nodes dev attribute John Garry
2026-09-07 10:50 ` [PATCH v8 27/27] 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=6cdf70ce-aba6-4377-bdaf-2efddae55fd1@linux.dev \
    --to=john.garry@linux.dev \
    --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