>Submitter-Id: net
>Originator: Scott Blomenkamp <[email protected]>
>Synopsis: xen_grant_table_remove() panics if the remote domain still has
the frame mapped
>Severity: serious
>Priority: medium
>Category: kernel
>Class: sw-bug
>Release: 8.0
>Environment:
System : OpenBSD 8.0
https://www.google.com/url?q=http://GENERIC.MP&source=gmail&ust=1795678536487000&sa=E
#84, stock kernel, unmodified install
Architecture: OpenBSD.amd64
Machine : Xen 4.20 HVM guest (xl, Debian dom0), 2 vCPUs, two vifs
>Description:
xen_grant_table_remove() spins about 10 times, then panics if the
remote domain still maps the frame:

panic: grant table reference 4371 is held by domain 0:
frame 0x3f371 flags 0x9
xen_grant_table_remove() at xen_grant_table_remove+0x16f
xen_bus_dmamap_unload() at xen_bus_dmamap_unload+0x73
xnf_tx_ring_destroy() at xnf_tx_ring_destroy+0x141
xnf_detach() at xnf_detach+0x7d
config_detach() at config_detach+0x166
xen_hotplug() at xen_hotplug+0x1a5
taskq_thread() at taskq_thread+0x129

The entry's GTF_reading and GTF_writing bits are under the peer's
control, so a slow, buggy or hostile backend that keeps a page
mapped past the frontend's teardown can panic the guest. Linux
and FreeBSD defer the release in this state: they keep the page,
retry, and leak it in the end rather than panic. In setups that
isolate the network backend in its own VM (Qubes OS's sys-net),
that backend is the component expected to be compromised.

Related, seen in the same tests: when the guest's last vif is
detached, the toolstack removes the whole device/vif directory,
xen_hotplug()'s XS_LIST on it fails and the function returns
early, so xnf0 is never detached and stays attached to a backend
that is gone. With a second vif left, the detach runs (and
panics as above).

A related case with no deliberate hold, xbf(4) on a routine
disk detach, is reported separately ("xbf(4) ignores the
backend's Closing state ...").
>How-To-Repeat:
1. Start the guest with two vifs:
vif = [ "bridge=xenbr0,mac=00:16:3e:0b:5d:80",
"bridge=xenbr0,mac=00:16:3e:0b:5d:81" ]
2. In dom0, map xnf1's transmit ring grant and hold it, e.g. with
libxengnttab: xengnttab_map_grant_ref(h, domid, ref, PROT_READ)
where ref = xenstore-read
/local/domain/<domid>/device/vif/1/tx-ring-ref, then sleep.
3. In dom0: xl network-detach <guest> 1
The guest panics about 10 s later, in its xenwatch thread. The
panic and trace are attached; dmesg available.
>Fix:
None attached. Deferring the release as Linux and FreeBSD do (a
lab variant that kept the page and retried logged "domain 0
holds 2 pages, deferring release" and freed them once dom0
unmapped).

Disclosure: I found and analysed this with the help of an AI
assistant (Anthropic's Claude), in a lab on Xen 4.20. The panic and
trace above are from a real run with the stock 8.0 kernel. No
AI-written code is attached.
panic: grant table reference 4371 is held by domain 0: frame 0x3f371 flags 0x9
Stopped at      db_enter+0x14:  popq    %rbp
    TID    PID    UID     PRFLAGS     PFLAGS  CPU  COMMAND
  27436  16556    115    0x100012          0    0  slaacd
*330021  62877      0     0x14000      0x200    1  xenwatch
db_enter() at db_enter+0x14
panic(ffffffff8266a7f0) at panic+0xd5
xen_grant_table_remove(ffff800000100140,113) at xen_grant_table_remove+0x16f
xen_bus_dmamap_unload(ffffffff82adfaf0,ffff8000000d4980) at xen_bus_dmamap_unlo
ad+0x73
xnf_tx_ring_destroy(ffff80000017d000) at xnf_tx_ring_destroy+0x141
xnf_detach(ffff80000017d000,0) at xnf_detach+0x7d
config_detach(ffff80000017d000,0) at config_detach+0x166
xen_hotplug(ffff80000002ff00) at xen_hotplug+0x1a5
taskq_thread(ffff8000000e1800) at taskq_thread+0x129
end trace frame: 0x0, count: 6
https://www.openbsd.org/ddb.html describes the minimum info required in bug
reports.  Insufficient info makes it difficult to find and fix bugs.

Reply via email to