All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Emerson Busson" <emersonbusson@gmail.com>
Cc: linux-hyperv@vger.kernel.org
Subject: Re: [PATCH v2 10/14] hv: vmbus: pin buffer pages across UIO mmap to close the reclaim race
Date: Thu, 08 Oct 2026 19:09:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-164501@kernel.org> (raw)
In-Reply-To: <20261007190752.336426-11-emersonbusson@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] hv: vmbus_buffer_pin_pages UAF race on subchannel ringbuffers
--

commit 69d0c6246e4ab3d36e972718b31a04ff08d2eee9
Author: Emerson Busson <emersonbusson@gmail.com>
Subject: hv: vmbus: pin buffer pages across UIO mmap to close the reclaim race

This commit pins buffer pages across UIO mmap to prevent a race condition 
with the reclaim worker. It adds vmbus_buffer_pin_pages() and 
vmbus_buffer_unpin_pages() to safely take references on the pages. The sysfs 
ring mmap wrapper is adjusted to handle the new pin lifecycle.

> diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
> index 7eb9ea814ef45..2793ca1b7f320 100644
> --- a/drivers/hv/channel.c
> +++ b/drivers/hv/channel.c
[ ... ]
> @@ -1145,6 +1145,98 @@ void vmbus_release_buffer(struct vmbus_buffer *buffer)
>  }
>  EXPORT_SYMBOL_GPL(vmbus_release_buffer);
>  
> +/**
> + * vmbus_buffer_pin_pages - snapshot a buffer's pages and hold references
[ ... ]
> +int vmbus_buffer_pin_pages(struct vmbus_buffer *buffer,
> +			   struct vmbus_buffer_pin *pin)
> +{
> +	struct vmbus_buffer_retained *owner;
> +	u32 i;
> +
> +	/*
> +	 * The owner and page array are published and cleared under
> +	 * vmbus_buffer_owners_lock (see vmbus_release_buffer()). Reading
> +	 * either outside that lock lets a concurrent release free the array
> +	 * while this loop still walks it.
> +	 */
> +	mutex_lock(&vmbus_buffer_owners_lock);

[Severity: High]
Does this code still have a use-after-free race for subchannel ringbuffers?

In vmbus_release_buffer(), if buffer->owner is NULL, the buffer is freed 
and zeroed without acquiring vmbus_buffer_owners_lock. Subchannel 
ringbuffers do not have an owner, so their release bypasses this lock.

If a concurrent mmap() is called on a subchannel's sysfs ring file during 
device removal, this function will acquire the lock and start walking 
buffer->pages while vmbus_release_buffer() concurrently zeroes and frees 
it without the lock, causing a crash.

> +	owner = buffer->owner;
> +	if (!buffer->pages || !buffer->page_cnt) {
> +		mutex_unlock(&vmbus_buffer_owners_lock);
> +		return -ENODEV;
> +	}
[ ... ]
> diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
> index b40e80e19c6c6..91cb25d019be9 100644
> --- a/drivers/uio/uio_hv_generic.c
> +++ b/drivers/uio/uio_hv_generic.c
[ ... ]
> @@ -372,12 +637,20 @@ static void
>  hv_uio_remove(struct hv_device *dev)
>  {
>  	struct hv_uio_private_data *pdata = hv_get_drvdata(dev);
> +	int ret;
>  
>  	if (!pdata)
>  		return;
>  
>  	hv_remove_ring_sysfs(dev->channel);

[Severity: High]
Does this code leave subchannel sysfs files active and mapped?

hv_remove_ring_sysfs() is only called on the primary channel, which leaves 
any subchannel ring sysfs files active. 

> +	/* Keep event notification alive until channel callbacks are stopped. */
> +	get_device(&pdata->info.uio_dev->dev);
>  	uio_unregister_device(&pdata->info);
> +	/* unregister prevents the eventual fd close from calling .release. */
> +	ret = hv_uio_disconnect_if_open(dev->channel, vmbus_disconnect_ring);

vmbus_disconnect_ring() iterates over the subchannels and frees their 
ringbuffers directly. Because the subchannel sysfs ring files are still 
active, userspace can call mmap() concurrently on them. This triggers the 
lockless vmbus_release_buffer() vs vmbus_buffer_pin_pages() race described 
above.

Could hv_remove_ring_sysfs() be invoked on all subchannels before their 
ringbuffers are freed?

> +	if (ret)
> +		dev_err(&dev->device, "channel disconnect failed: %d\n", ret);
> +	put_device(&pdata->info.uio_dev->dev);
>  	hv_uio_cleanup(dev, pdata);
>  
>  	vmbus_free_ring(dev->channel);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261007190752.336426-1-emersonbusson@gmail.com?part=10

  parent reply	other threads:[~2026-10-08 19:09 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07 19:07 [PATCH v2 0/14] hv: vmbus: make rings and host-visible buffers survive buddy fragmentation Emerson Busson
2026-10-07 19:07 ` [PATCH v2 01/14] hv: vmbus: convert ring backing through the chunk allocator Emerson Busson
2026-10-07 19:07 ` [PATCH v2 02/14] hv: vmbus: validate chunk buffer allocation and cleanup Emerson Busson
2026-10-08 21:17   ` kernel test robot
2026-10-07 19:07 ` [PATCH v2 03/14] uio: hv_generic: describe buffers for owned allocation Emerson Busson
2026-10-07 19:07 ` [PATCH v2 04/14] hv: vmbus: add KUnit tests for GPADL post failure injection Emerson Busson
2026-10-07 19:07 ` [PATCH v2 05/14] hv: vmbus: add KUnit test for order-zero allocation fallback Emerson Busson
2026-10-07 19:07 ` [PATCH v2 06/14] hv: vmbus: cover all shared-page policy combinations Emerson Busson
2026-10-07 19:07 ` [PATCH v2 07/14] hv: vmbus: distinguish host rescind from local channel unload Emerson Busson
2026-10-07 19:07 ` [PATCH v2 08/14] hv: vmbus: retain backing until ownership and references clear Emerson Busson
2026-10-08 19:09   ` sashiko-bot
2026-10-07 19:07 ` [PATCH v2 09/14] hv: use owned VMBus buffers in NetVSC and UIO Emerson Busson
2026-10-08 19:09   ` sashiko-bot
2026-10-07 19:07 ` [PATCH v2 10/14] hv: vmbus: pin buffer pages across UIO mmap to close the reclaim race Emerson Busson
2026-10-08 16:49   ` kernel test robot
2026-10-08 17:51     ` Nathan Chancellor
2026-10-08 17:02   ` kernel test robot
2026-10-08 19:09   ` sashiko-bot [this message]
2026-10-07 19:07 ` [PATCH v2 11/14] hv: vmbus: vmalloc requestor metadata Emerson Busson
2026-10-08 19:09   ` sashiko-bot
2026-10-07 19:07 ` [PATCH v2 12/14] hv: netvsc: allocate RNDIS request descriptors with kvzalloc_obj() Emerson Busson
2026-10-08 19:09   ` sashiko-bot
2026-10-07 19:07 ` [PATCH v2 13/14] hv: netvsc: handle a NULL request address on empty completions Emerson Busson
2026-10-08 19:09   ` sashiko-bot
2026-10-07 19:07 ` [PATCH v2 14/14] hv: netvsc: use kvzalloc for device state Emerson Busson
2026-10-08 19:09   ` sashiko-bot
2026-10-08 16:55 ` [PATCH v2 0/14] hv: vmbus: make rings and host-visible buffers survive buddy fragmentation Easwar Hariharan
2026-10-13 17:52 ` Michael Kelley

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=sashiko-outbox-164501@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=emersonbusson@gmail.com \
    --cc=linux-hyperv@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.