From: Naman Jain <namjain@linux.microsoft.com>
To: Yuho Choi <oss.patchbox@gmail.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Michael Kelley <mhklinux@outlook.com>,
Emerson Busson <emersonbusson@gmail.com>,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] uio_hv_generic: Close the channel on remove if it is still open
Date: Mon, 30 Nov 2026 14:03:15 +0530 [thread overview]
Message-ID: <5bb09f89-0301-45a6-80c2-7f04e787cb74@linux.microsoft.com> (raw)
In-Reply-To: <20261129184024.1092604-2-oss.patchbox@gmail.com>
On 11/30/2026 12:08 AM, Yuho Choi wrote:
> hv_uio_release() closes the VMBus channel when the last file is closed,
> and hv_uio_remove() then frees the ring buffer. But once
> uio_unregister_device() has run, the uio core no longer calls
> ->release() for files that are still open. If the device is unbound
> while a process has /dev/uioX open, the channel is never closed:
>
> - the host keeps the channel open and the ring GPADL established;
> - hv_uio_channel_cb() stays installed, and dereferences a NULL drvdata
> the next time the host signals the channel;
> - after the driver is bound again, opening the device fails, since
> vmbus_connect_ring() finds the channel still open.
>
> hv_uio_remove() also frees the ring in that case. In most VMs the pages
> happen to be leaked instead, because ringbuffer_gpadlhandle.decrypted is
> still set. A channel with a confidential ring buffer never sets it, so
> there the pages go back to the allocator while the GPADL still covers
> them. The same happens when vmbus_disconnect_ring() fails in
> hv_uio_release().
>
> Close the channel in hv_uio_remove() if it is still open, and hold a
> reference to the uio device until then, as hv_uio_channel_cb() uses it.
> A process may still have the ring mapped, and uio maps it with
> remap_pfn_range(), which takes no page references, so keep the ring
> memory in that case. Keep it too when closing the channel failed in
> hv_uio_release(), as vmbus_close() does, and warn when the ring is
> leaked.
>
> Fixes: cdfa835c6e5e ("uio_hv_generic: defer opening vmbus until first use")
> Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
<snip>
> }
> @@ -385,15 +389,35 @@ static void
> hv_uio_remove(struct hv_device *dev)
> {
> struct hv_uio_private_data *pdata = hv_get_drvdata(dev);
> + struct device *uio_dev;
>
> if (!pdata)
> return;
>
> hv_remove_ring_sysfs(dev->channel);
> +
> + /* hv_uio_channel_cb() may use it until the channel is closed */
> + uio_dev = get_device(&pdata->info.uio_dev->dev);
> uio_unregister_device(&pdata->info);
> +
> + /*
> + * The uio core does not call hv_uio_release() for files that are
> + * still open after the device is unregistered, so close the channel
> + * here. A process may still have the ring mapped, so keep it.
> + */
> + if (atomic_read(&pdata->refcnt)) {
> + vmbus_disconnect_ring(dev->channel);
This can free a subchannel's ring pages while an application still
has them mapped. The sysfs removal above only unmaps the primary
ring. The application can still access the subchannel pages after
they've been freed, even if the kernel has allocated them for
something else.
Can we remove each subchannel's ring file before freeing its pages?
You may also want to check Sashiko's comments on this patch.
Regards,
Naman
prev parent reply other threads:[~2026-11-30 8:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 18:38 Yuho Choi
2026-11-29 18:59 ` Greg Kroah-Hartman
2026-11-29 23:25 ` Yuho Choi
2026-11-30 6:36 ` Greg Kroah-Hartman
2026-11-30 8:33 ` Naman Jain [this message]
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=5bb09f89-0301-45a6-80c2-7f04e787cb74@linux.microsoft.com \
--to=namjain@linux.microsoft.com \
--cc=decui@microsoft.com \
--cc=emersonbusson@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=haiyangz@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhklinux@outlook.com \
--cc=oss.patchbox@gmail.com \
--cc=wei.liu@kernel.org \
/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
all inboxes | Powered by JetHome®