From: David Woodhouse <dwmw2@infradead.org>
To: Paolo Abeni <pabeni@redhat.com>, Chad Aldreda <ca@modelmiser.com>,
Richard Cochran <richardcochran@gmail.com>,
Wen Gu <guwen@linux.alibaba.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 15:01:16 +0000 [thread overview]
Message-ID: <a724a94bef81dec39150a2d24201194e98ecc096.camel@infradead.org> (raw)
In-Reply-To: <fdc005b9-e48a-4550-b66b-0f58db82babe@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3604 bytes --]
On Wed, 2026-11-25 at 12:38 +0100, Paolo Abeni wrote:
> 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?
I think
https://lore.kernel.org/netdev/20251127083610.6b66a728@kernel.org/ is
the key answer to that.
The latest update (which I'm suggesting I should dust off) is at
https://lore.kernel.org/all/14969e704fb8e70deb549b2e1c8670f6756a8da7.camel@infradead.org/
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6179 bytes --]
next prev parent reply other threads:[~2026-11-25 15:01 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 [this message]
2026-11-25 14:52 ` Paolo Abeni
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=a724a94bef81dec39150a2d24201194e98ecc096.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=andrew+netdev@lunn.ch \
--cc=ca@modelmiser.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=guwen@linux.alibaba.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--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®