From: Paolo Abeni <pabeni@redhat.com>
To: Chad Aldreda <ca@modelmiser.com>,
Richard Cochran <richardcochran@gmail.com>,
David Woodhouse <dwmw2@infradead.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>,
Shuangpeng Bai <shuangpeng.kernel@gmail.com>,
netdev@vger.kernel.org, stable@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v3] ptp: vmclock: keep the device state until the last file is closed
Date: Wed, 25 Nov 2026 15:52:39 +0100 [thread overview]
Message-ID: <af9b6e7d-6972-4881-9403-c8af22b449fe@redhat.com> (raw)
In-Reply-To: <20261119061517.1142436-2-ca@modelmiser.com>
On 11/19/26 07:15, Chad Aldreda wrote:
> vmclock_probe() allocates struct vmclock_state with devm_kzalloc_obj()
> and maps the shared page with devm_memremap(), so both are released
> when the driver is unbound, but an open /dev/vmclockN keeps using them
> through its file state. After an unbind, read() runs on the freed
> struct and reads through the released mapping, and a poll() in
> progress sleeps on a wait queue in the freed struct. KASAN reports a
> slab-use-after-free in vmclock_miscdev_read(). In testing, the same
> read() faulted on the unmapped page once the device had been bound
> again.
>
> Allocate the state with kzalloc_obj() and map the page with memremap(),
> and release both on the last reference: open() takes a reference and
> release() drops it, and a devm action drops the device's own reference
> after vmclock_remove() has called misc_deregister(). misc_open() calls
> open() with misc_mtx held, and misc_deregister() takes misc_mtx, so
> open() always runs while the device's reference is held.
>
> vmclock_remove() now marks the device as removed and wakes every waiter
> on the wait queue. A read() or mmap() on a file that is still open fails
> with -ENODEV once it sees the mark. On a device that supports
> notifications, poll() returns EPOLLHUP | EPOLLERR, including a poll()
> that was already waiting; it tests the mark after poll_wait(), so it
> cannot miss the wake-up. The wake-up uses wake_up_interruptible_all(),
> because no later notification will reach a waiter that the remove-time
> wake-up skips, such as a second epoll instance that registered the file
> with EPOLLEXCLUSIVE. Without notifications poll() already returns
> POLLHUP.
>
> Separately from the report below, the bug was also found by a
> Coccinelle script that reports device nodes in devm-allocated memory,
> posted at
> https://lore.kernel.org/r/20261106193517.3267013-2-ca@modelmiser.com,
> and reproduced in QEMU 10.2.4 with -device vmclock. There is no access
> to EC2 hardware with this device, so the fix has only been tested in
> QEMU. QEMU's device has no notifications, so the poll() path was tested
> with a local change that lets poll() wait without them.
>
> Fixes: 205032724226 ("ptp: Add support for the AMZNC10C 'vmclock' device")
> Reported-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
> Closes: https://lore.kernel.org/all/178144969601.60470.14493569608271069160@gmail.com/
> Cc: stable@vger.kernel.org # 7.0+
> Signed-off-by: Chad Aldreda <ca@modelmiser.com>
Applied, thanks!
Paolo
prev parent reply other threads:[~2026-11-25 14:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 6:15 Chad Aldreda
2026-11-24 19:44 ` David Woodhouse
2026-11-25 11:38 ` Paolo Abeni
2026-11-25 15:01 ` David Woodhouse
2026-11-25 14:52 ` Paolo Abeni [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=af9b6e7d-6972-4881-9403-c8af22b449fe@redhat.com \
--to=pabeni@redhat.com \
--cc=andrew+netdev@lunn.ch \
--cc=ca@modelmiser.com \
--cc=davem@davemloft.net \
--cc=dwmw2@infradead.org \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@gmail.com \
--cc=shuangpeng.kernel@gmail.com \
--cc=stable@vger.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®