Article View: muc.lists.freebsd.bugs
Article #534[Bug 300890] xen/gntdev: the event-channel handle stored for UNMAP_NOTIFY_SEND_EVENT can be freed by the evtchn device before gn...
From: 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
Technical Details
Message-ID:
<bug-300890-227@https.bugs.freebsd.org/bugzilla/>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news.tcpreset.net!newsfeed.bofh.team!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!news.tcpreset.net!newsfeed.bofh.team!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail From: bugzilla-noreply@freebsd.org Newsgroups: muc.lists.freebsd.bugs Subject: [Bug 300890] 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) Date: Thu, 19 Nov 2026 05:50:05 +0000 Organization: Newsgate at muc.de e.V. Approved: news-admin@muc.de Distribution: world Message-ID: <bug-300890-227@https.bugs.freebsd.org/bugzilla/> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2"; logging-data="7650"; mail-complaints-to="news-admin@muc.de" X-Original-To: bugs@mlmmj.nyi.freebsd.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795067405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yjdrVS8d6J6rDkEKFi2QLM4onZHJ3LyobaKMrN8qik8=; b=oS+qjxv+psIWd6vZnCjI/DTxncKNeQSM21S0rhjJvNuYAHYNTj/V5kZAeiuDowux451jha 8Kd/qeq9cOChCYDMRxenoBQmdqO85nBajzk/R7taF47bJHTld8v4waZOg1KPlpT+TS0bSf D9MUj9Z6B5pLYZZui1We2twyO0JlPnZB07s4W3DsclQn7iMxaXfwi18qXzrwYiLYEXjDbG noGsnUCmFPt9Xk5AdqgRnW4HNtwGgFhTl2Lt9DakIX8u7qv9dFN5Nl7JoVgKHcR/zfouun jBvkSKpFtUexW23ldgfc+D1L0c7qtTtGDPXjrTifhoL8Tw30Q1okHmBfv8FfnA== X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f Auto-Submitted: auto-generated Precedence: list X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes