Thread View: muc.lists.freebsd.bugs
3 messages
3 total messages
Started by bugzilla-noreply
Thu, 19 Nov 2026 05:50
[Bug 300890] xen/gntdev: the event-channel handle stored for UNMAP_NOTIFY_SEND_EVENT can be freed by the evtchn device before gn...
Author: bugzilla-noreply
Date: Thu, 19 Nov 2026 05:50
Date: Thu, 19 Nov 2026 05:50
75 lines
5091 bytes
5091 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300890
Bug ID: 300890
Summary: xen/gntdev: the event-channel handle stored for
UNMAP_NOTIFY_SEND_EVENT can be freed by the evtchn
device before gntdev uses it (use after free)
Product: Base System
Version: 15.1-RELEASE
Hardware: amd64
OS: Any
Status: New
Severity: Affects Some People
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: sablomenkamp@gmail.com
Environment: FreeBSD 15.1-RELEASE amd64 as a PVH domU on Xen 4.20.5-pre (Debian
13 dom0), and as an HVM domU on Qubes OS 4.3 (Xen 4.19). Found while running
Xen's libxenvchan and the Qubes OS qrexec agent. Still present in main 5151bc2
(line numbers below are from that commit).
copy_notify_helper() takes a handle with xen_intr_get_evtchn_from_port() and
keeps it in notify_data until notify() runs at unmap time. notify() then calls
xen_intr_signal() and xen_intr_unbind() on it (sys/dev/xen/gntdev/gntdev.c,
lines 838-839; the field is declared at line 222).
The port belongs to another file, the user's /dev/xen/evtchn. When that user
closes the port first, as libxenvchan does on teardown, the evtchn device
unbinds it and the interrupt source the stored handle points to is released.
gntdev's later signal and unbind then touch freed memory.
How it showed: a page fault in evtchn_interrupt under qrexec load, after the
heap overflow in the previous report was fixed.
What I tested: store only the port number, and at notify time look the port up
again with xen_intr_get_evtchn_from_port(); if it is gone, skip the event,
otherwise signal it and drop the reference at once. With this change and the
fixes for the other three reports, a kernel ran 1,800 qrexec calls without a
panic; kernels with only some of the fixes panicked within the first few
hundred calls. That change demonstrates the cause; it is not a proposal for the
final fix. If the port was closed and reused by someone else in between, the
event goes to the new owner. Linux's gntdev avoids that by taking a reference
that the evtchn device honours (evtchn_get/evtchn_put), so the port cannot be
closed while a notify is pending; an upstream fix should probably do the same.
This was noticed in 2016 when unmap notifications were added
(https://reviews.freebsd.org/D7293): no reference-taking mechanism for event
channels was found then, and requiring that the port not be freed before the
notify is sent was considered. The current code keeps a handle instead, which
does not stop the evtchn device from freeing the source.
The test change is available if wanted.
Disclosure: found and analysed with an AI assistant (Claude). The reproduction,
the test runs and the results are from my own machines.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300890] xen/gntdev: the event-channel handle stored for UNMAP_NOTIFY_SEND_EVENT can be freed by the evtchn device before gn...
Author: bugzilla-noreply
Date: Thu, 19 Nov 2026 15:56
Date: Thu, 19 Nov 2026 15:56
29 lines
3334 bytes
3334 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300890
Roger Pau Monné <royger@freebsd.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|New |In Progress
Assignee|xen@FreeBSD.org |bugs@FreeBSD.org
--- Comment #1 from Roger Pau Monné <royger@freebsd.org> ---
(In reply to Scott Blomenkamp from comment #0)
Thanks for all the reports. I've got fixes lined up for all of them now.
This one is slightly more complex: there's already a refcount, the issue is
that the owner of the event channel (evtchn_dev) unbinds and frees the
interrupt handler data. Since there's still a reference taken by gntdev, the
event is not freed or masked, so the event channel triggering at that point
leads to the stale handler being executed and triggering a use-after free of
any associated data. See: https://reviews.freebsd.org/D61758
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300890] xen/gntdev: the event-channel handle stored for UNMAP_NOTIFY_SEND_EVENT can be freed by the evtchn device before gn...
Author: bugzilla-noreply
Date: Tue, 24 Nov 2026 09:47
Date: Tue, 24 Nov 2026 09:47
36 lines
3466 bytes
3466 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300890 --- Comment #2 from Scott Blomenkamp <sablomenkamp@gmail.com> --- (In reply to Roger Pau Monné from comment #1) Tested D61758 (Diff 1, posted Nov 19) as part of your series D61755, D61756, D61757, D61758 and D61760, applied in that order to main 97fd69b0b884. Setup: ThinkPad T480, Qubes OS 4.3.2 (Xen 4.19.6). FreeBSD guest, HVM with a stub domain, 2 vCPUs. Kernel GENERIC (INVARIANTS, WITNESS) plus DEBUG_MEMGUARD with vm.memguard.desc=gntdev. None of my own gntdev or xen_intr patches. Result: 1,800 qrexec calls into the guest, 8 at a time, all succeeded: no panic, no WITNESS or INVARIANTS report, and the new KASSERT in xen_intr_put_evtchn() never fired. As a check I also built a second kernel with the same base and options but without D61758 (D61755, D61756, D61757 and D61760 only). On it, the first outgoing qrexec call from the guest panicked with "Invalid event channel port" in evtchn_filter(), from the upcall handler. With D61758 applied that panic doesn't happen. Testing was done with an AI assistant (Claude); the runs and results are from my own machines. -- You are receiving this mail because: You are the assignee for the bug. -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads