From: Paolo Abeni <pabeni@redhat.com>
To: David Woodhouse <dwmw2@infradead.org>,
Chad Aldreda <ca@modelmiser.com>,
Richard Cochran <richardcochran@gmail.com>
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 12:38:57 +0100 [thread overview]
Message-ID: <fdc005b9-e48a-4550-b66b-0f58db82babe@redhat.com> (raw)
In-Reply-To: <1f77fa9014f8dfafb2be9cf15a66c5541880656a.camel@infradead.org>
On 11/24/26 20:44, David Woodhouse wrote:
> On Thu, 2026-11-19 at 06:15 +0000, 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>
>
> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk>
>
> We did have a plan to pull the PHC-only drivers out into drivers/phc
> and leave only the *real* PTP in drivers/ptp. I kind of stalled on that
> because I wasn't sure I had consensus especially from Richard and the
> net maintainers. Shall I revive that and repost it?
I'm sorry but that conversation is way of my context window. Do you have a
pointer to the prior discussion? why such separation would be useful?
/P
prev parent reply other threads:[~2026-11-25 11:39 UTC|newest]
Thread overview: 3+ 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 [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=fdc005b9-e48a-4550-b66b-0f58db82babe@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®