* [PATCH v1 01/21] hw/xen: Fix partial request header handling in emulated XenStore
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 10:57 ` Paul Durrant
2026-11-30 13:17 ` Alex Bennée
2026-11-24 23:22 ` [PATCH v1 02/21] i386/xen: Don't resample GSI when per-vCPU upcall vector is in use David Woodhouse
` (19 subsequent siblings)
20 siblings, 2 replies; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
When a XenStore request header is only partially received, QEMU copies
XENSTORE_HEADER_SIZE bytes instead of only the remaining header bytes.
Fix the length calculation to copy only the missing part of the header.
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/3644
Fixes: f3341e7b915 ("hw/xen: Add basic ring handling to xenstore")
Fixes: CVE-2026-61403
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/i386/kvm/xen_xenstore.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c
index 0dc0edf3bfd..7d6d6d5cbb7 100644
--- a/hw/i386/kvm/xen_xenstore.c
+++ b/hw/i386/kvm/xen_xenstore.c
@@ -1218,7 +1218,7 @@ static unsigned int get_req(XenXenstoreState *s)
if (s->req_offset < XENSTORE_HEADER_SIZE) {
void *ptr = s->req_data + s->req_offset;
- unsigned int len = XENSTORE_HEADER_SIZE;
+ unsigned int len = XENSTORE_HEADER_SIZE - s->req_offset;
unsigned int copylen = copy_from_ring(s, ptr, len);
copied += copylen;
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 01/21] hw/xen: Fix partial request header handling in emulated XenStore
2026-11-24 23:22 ` [PATCH v1 01/21] hw/xen: Fix partial request header handling in emulated XenStore David Woodhouse
@ 2026-11-25 10:57 ` Paul Durrant
2026-11-30 13:17 ` Alex Bennée
1 sibling, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 10:57 UTC (permalink / raw)
To: kvm
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> When a XenStore request header is only partially received, QEMU copies
> XENSTORE_HEADER_SIZE bytes instead of only the remaining header bytes.
>
> Fix the length calculation to copy only the missing part of the header.
>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/3644
> Fixes: f3341e7b915 ("hw/xen: Add basic ring handling to xenstore")
> Fixes: CVE-2026-61403
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/i386/kvm/xen_xenstore.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread* Re: [PATCH v1 01/21] hw/xen: Fix partial request header handling in emulated XenStore
2026-11-24 23:22 ` [PATCH v1 01/21] hw/xen: Fix partial request header handling in emulated XenStore David Woodhouse
2026-11-25 10:57 ` Paul Durrant
@ 2026-11-30 13:17 ` Alex Bennée
1 sibling, 0 replies; 51+ messages in thread
From: Alex Bennée @ 2026-11-30 13:17 UTC (permalink / raw)
To: David Woodhouse
Cc: qemu-devel, xen-devel, kvm, Paolo Bonzini, Peter Maydell,
Paul Durrant, Stefano Stabellini, Anthony PERARD,
Edgar E . Iglesias, Michael S . Tsirkin, Richard Henderson,
Marcelo Tosatti, Marc-André Lureau, Jason Wang, Hui Peng,
Mark Syms, Feifan Qian, David Woodhouse
David Woodhouse <dwmw2@infradead.org> writes:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> When a XenStore request header is only partially received, QEMU copies
> XENSTORE_HEADER_SIZE bytes instead of only the remaining header bytes.
>
> Fix the length calculation to copy only the missing part of the header.
>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/3644
Should be Resolves:
> Fixes: f3341e7b915 ("hw/xen: Add basic ring handling to xenstore")
> Fixes: CVE-2026-61403
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/i386/kvm/xen_xenstore.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c
> index 0dc0edf3bfd..7d6d6d5cbb7 100644
> --- a/hw/i386/kvm/xen_xenstore.c
> +++ b/hw/i386/kvm/xen_xenstore.c
> @@ -1218,7 +1218,7 @@ static unsigned int get_req(XenXenstoreState *s)
>
> if (s->req_offset < XENSTORE_HEADER_SIZE) {
> void *ptr = s->req_data + s->req_offset;
> - unsigned int len = XENSTORE_HEADER_SIZE;
> + unsigned int len = XENSTORE_HEADER_SIZE - s->req_offset;
> unsigned int copylen = copy_from_ring(s, ptr, len);
>
> copied += copylen;
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 02/21] i386/xen: Don't resample GSI when per-vCPU upcall vector is in use
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
2026-11-24 23:22 ` [PATCH v1 01/21] hw/xen: Fix partial request header handling in emulated XenStore David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 10:58 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 03/21] i386/xen: Free Xen vCPU timers when a vCPU is destroyed David Woodhouse
` (18 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
The callback_via GSI (or PCI INTx) and the per-vCPU upcall vector are
mutually exclusive delivery mechanisms for Xen event channel upcalls.
Xen itself will never assert the callback GSI for a vCPU which has a
per-vCPU upcall vector configured.
When the interrupt is acked, QEMU's resampling logic reasserts the
GSI if evtchn_upcall_pending is still set. If the guest has configured
a per-vCPU upcall vector, events are delivered through that vector and
the GSI is unexpected; a guest which receives both the vector upcall
and a spurious GSI interrupt for the same event can crash. This was
observed in production with Windows guests on a different VMM which
implements the same resampling logic.
If a per-vCPU upcall vector is configured, don't resample the GSI;
just deassert it.
Fixes: ddf0fd9ae1fd ("hw/xen: Support HVM_PARAM_CALLBACK_TYPE_GSI callback")
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
target/i386/kvm/xen-emu.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c
index 29364a92797..7337561b159 100644
--- a/target/i386/kvm/xen-emu.c
+++ b/target/i386/kvm/xen-emu.c
@@ -435,6 +435,13 @@ void kvm_xen_maybe_deassert_callback(CPUState *cs)
return;
}
+ if (env->xen_vcpu_callback_vector) {
+ BQL_LOCK_GUARD();
+ env->xen_callback_asserted = false;
+ xen_evtchn_set_callback_level(0);
+ return;
+ }
+
/* If the evtchn_upcall_pending flag is cleared, turn the GSI off. */
if (!vi->evtchn_upcall_pending) {
bql_lock();
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 02/21] i386/xen: Don't resample GSI when per-vCPU upcall vector is in use
2026-11-24 23:22 ` [PATCH v1 02/21] i386/xen: Don't resample GSI when per-vCPU upcall vector is in use David Woodhouse
@ 2026-11-25 10:58 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 10:58 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> The callback_via GSI (or PCI INTx) and the per-vCPU upcall vector are
> mutually exclusive delivery mechanisms for Xen event channel upcalls.
> Xen itself will never assert the callback GSI for a vCPU which has a
> per-vCPU upcall vector configured.
>
> When the interrupt is acked, QEMU's resampling logic reasserts the
> GSI if evtchn_upcall_pending is still set. If the guest has configured
> a per-vCPU upcall vector, events are delivered through that vector and
> the GSI is unexpected; a guest which receives both the vector upcall
> and a spurious GSI interrupt for the same event can crash. This was
> observed in production with Windows guests on a different VMM which
> implements the same resampling logic.
>
> If a per-vCPU upcall vector is configured, don't resample the GSI;
> just deassert it.
>
> Fixes: ddf0fd9ae1fd ("hw/xen: Support HVM_PARAM_CALLBACK_TYPE_GSI callback")
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> target/i386/kvm/xen-emu.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 03/21] i386/xen: Free Xen vCPU timers when a vCPU is destroyed
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
2026-11-24 23:22 ` [PATCH v1 01/21] hw/xen: Fix partial request header handling in emulated XenStore David Woodhouse
2026-11-24 23:22 ` [PATCH v1 02/21] i386/xen: Don't resample GSI when per-vCPU upcall vector is in use David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:00 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 04/21] hw/xen: Publish backend features before setting state to InitWait David Woodhouse
` (17 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
kvm_xen_init_vcpu() allocates the per-vCPU timers with the CPUState as
callback opaque, and nothing freed them on vCPU destruction. So a guest
could arm the periodic timer for a vCPU (VCPUOP_set_periodic_timer
always reaches QEMU; the kernel doesn't handle it) and eject that vCPU
via ACPI hotplug, leaving the armed timer pointing at a freed X86CPU.
Free both timers in kvm_xen_destroy_vcpu(), called from
kvm_arch_destroy_vcpu(). That runs under the BQL, as do the timer
callbacks, so it cannot race an in-flight callback. It *can* race a
timer hypercall from another vCPU — hypercalls don't take the BQL,
which is why xen_timers_lock exists — so clear the pointers under that
lock and have the periodic timer paths return -ENOENT when the timer is
gone, as for a nonexistent vCPU. The singleshot ops act only on the
calling vCPU, so cannot race its destruction.
Also move the timer_del() in do_set_periodic_timer() inside the lock,
where it should have been all along.
Fixes: CVE-2026-123069
Fixes: b746a779264f ("i386/xen: handle PV timer hypercalls")
Reported-by: MyeonghunPak <https://gitlab.com/mhun512>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4098
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
target/i386/kvm/kvm.c | 6 ++++++
target/i386/kvm/xen-emu.c | 36 ++++++++++++++++++++++++++++++++++--
target/i386/kvm/xen-emu.h | 1 +
3 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 76528f1123f..302621f30af 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -2556,6 +2556,12 @@ int kvm_arch_destroy_vcpu(CPUState *cs)
X86CPU *cpu = X86_CPU(cs);
CPUX86State *env = &cpu->env;
+#ifdef CONFIG_XEN_EMU
+ if (cs->kvm_state->xen_version) {
+ kvm_xen_destroy_vcpu(cs);
+ }
+#endif
+
g_free(env->xsave_buf);
g_free(cpu->kvm_msr_buf);
diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c
index 7337561b159..67d1379e024 100644
--- a/target/i386/kvm/xen-emu.c
+++ b/target/i386/kvm/xen-emu.c
@@ -276,6 +276,28 @@ int kvm_xen_init_vcpu(CPUState *cs)
return 0;
}
+void kvm_xen_destroy_vcpu(CPUState *cs)
+{
+ CPUX86State *env = &X86_CPU(cs)->env;
+
+ /*
+ * This runs on the vCPU's own thread with the BQL held, and the
+ * timer callbacks run from the main loop thread also with the BQL
+ * held, so freeing the timers cannot race against an in-flight
+ * callback. It *can* race against a Xen hypercall from another
+ * vCPU targeting this one (hypercalls are handled without the
+ * BQL), so clear the pointers under xen_timers_lock to let those
+ * paths observe the vCPU's demise.
+ */
+ QEMU_LOCK_GUARD(&env->xen_timers_lock);
+
+ timer_free(env->xen_singleshot_timer);
+ env->xen_singleshot_timer = NULL;
+
+ timer_free(env->xen_periodic_timer);
+ env->xen_periodic_timer = NULL;
+}
+
uint32_t kvm_xen_get_caps(void)
{
return kvm_state->xen_caps;
@@ -1079,10 +1101,15 @@ static int do_set_periodic_timer(CPUState *target, uint64_t period_ns)
CPUX86State *tenv = &X86_CPU(target)->env;
int64_t qemu_now;
- timer_del(tenv->xen_periodic_timer);
-
qemu_mutex_lock(&tenv->xen_timers_lock);
+ if (!tenv->xen_periodic_timer) {
+ qemu_mutex_unlock(&tenv->xen_timers_lock);
+ return -ENOENT;
+ }
+
+ timer_del(tenv->xen_periodic_timer);
+
qemu_now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
timer_mod_ns(tenv->xen_periodic_timer, qemu_now + period_ns);
tenv->xen_periodic_timer_period = period_ns;
@@ -1120,6 +1147,11 @@ static int vcpuop_stop_periodic_timer(CPUState *target)
qemu_mutex_lock(&tenv->xen_timers_lock);
+ if (!tenv->xen_periodic_timer) {
+ qemu_mutex_unlock(&tenv->xen_timers_lock);
+ return -ENOENT;
+ }
+
timer_del(tenv->xen_periodic_timer);
tenv->xen_periodic_timer_period = 0;
diff --git a/target/i386/kvm/xen-emu.h b/target/i386/kvm/xen-emu.h
index fe85e0b1958..467b9f088ae 100644
--- a/target/i386/kvm/xen-emu.h
+++ b/target/i386/kvm/xen-emu.h
@@ -25,6 +25,7 @@
int kvm_xen_init(KVMState *s, uint32_t hypercall_msr);
int kvm_xen_init_vcpu(CPUState *cs);
+void kvm_xen_destroy_vcpu(CPUState *cs);
int kvm_xen_handle_exit(X86CPU *cpu, struct kvm_xen_exit *exit);
int kvm_put_xen_state(CPUState *cs);
int kvm_get_xen_state(CPUState *cs);
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 03/21] i386/xen: Free Xen vCPU timers when a vCPU is destroyed
2026-11-24 23:22 ` [PATCH v1 03/21] i386/xen: Free Xen vCPU timers when a vCPU is destroyed David Woodhouse
@ 2026-11-25 11:00 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:00 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> kvm_xen_init_vcpu() allocates the per-vCPU timers with the CPUState as
> callback opaque, and nothing freed them on vCPU destruction. So a guest
> could arm the periodic timer for a vCPU (VCPUOP_set_periodic_timer
> always reaches QEMU; the kernel doesn't handle it) and eject that vCPU
> via ACPI hotplug, leaving the armed timer pointing at a freed X86CPU.
>
> Free both timers in kvm_xen_destroy_vcpu(), called from
> kvm_arch_destroy_vcpu(). That runs under the BQL, as do the timer
> callbacks, so it cannot race an in-flight callback. It *can* race a
> timer hypercall from another vCPU — hypercalls don't take the BQL,
> which is why xen_timers_lock exists — so clear the pointers under that
> lock and have the periodic timer paths return -ENOENT when the timer is
> gone, as for a nonexistent vCPU. The singleshot ops act only on the
> calling vCPU, so cannot race its destruction.
>
> Also move the timer_del() in do_set_periodic_timer() inside the lock,
> where it should have been all along.
>
> Fixes: CVE-2026-123069
> Fixes: b746a779264f ("i386/xen: handle PV timer hypercalls")
> Reported-by: MyeonghunPak <https://gitlab.com/mhun512>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4098
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> target/i386/kvm/kvm.c | 6 ++++++
> target/i386/kvm/xen-emu.c | 36 ++++++++++++++++++++++++++++++++++--
> target/i386/kvm/xen-emu.h | 1 +
> 3 files changed, 41 insertions(+), 2 deletions(-)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 04/21] hw/xen: Publish backend features before setting state to InitWait
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (2 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 03/21] i386/xen: Free Xen vCPU timers when a vCPU is destroyed David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:05 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 05/21] hw/i386/kvm/xen_gnttab: Fix error handling in xen_be_gnttab_map_refs() David Woodhouse
` (16 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
The XenbusStateInitWait transition tells the frontend that the
backend's parameters are readable, but xen_device_realize() set it
before calling the implementation's realize method — which is what
writes the feature nodes ('max-ring-page-order' et al. for xen-block,
'feature-rx-copy' for xen-net).
Linux blkfront reads 'max-ring-page-order' with xenbus_read_unsigned():
no wait, no retry, default 0. Lose the race and it silently negotiates
a single-page ring — 32 request slots instead of 256. A device
hot-plugged into a running guest loses essentially every time; at boot
the frontend doesn't come looking until long after realize finished.
Netfront reads its feature nodes the same way.
Commit 240cc11369fc ("hw/xen: Avoid crash when backend watch fires too
early") introduced this by moving the realize call after the block of
code which both populates the initial xenstore nodes *and* sets
InitWait. The crash it fixed was real — xen-block's realize processes
watch events via blkconf_geometry()'s aio_poll(), and the handlers fell
over when the nodes didn't yet exist — but only the node population
needed to come first.
So keep the node population and the 'online' write before realize, and
move only the InitWait transition after it. A watch event during
realize now finds the frontend in Initialising and no backend 'state'
node, which the handlers tolerate; none of the three realize
implementations reads the backend state. Verified against the original
2023 crash reproducer as well as the ring-order negotiation.
Fixes: 240cc11369fc ("hw/xen: Avoid crash when backend watch fires too early")
Reported-by: Mark Syms <mark.syms@citrix.com>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/xen/xen-bus.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c
index 17bbbe2ea71..b75ce7f0957 100644
--- a/hw/xen/xen-bus.c
+++ b/hw/xen/xen-bus.c
@@ -1082,7 +1082,6 @@ static void xen_device_realize(DeviceState *dev, Error **errp)
xen_device_backend_printf(xendev, "hotplug-status", "connected");
xen_device_backend_set_online(xendev, true);
- xen_device_backend_set_state(xendev, XenbusStateInitWait);
if (!xen_device_frontend_exists(xendev)) {
xen_device_frontend_printf(xendev, "backend", "%s",
@@ -1093,6 +1092,19 @@ static void xen_device_realize(DeviceState *dev, Error **errp)
xen_device_frontend_set_state(xendev, XenbusStateInitialising, true);
}
+ /*
+ * The implementation's realize method may write feature nodes to
+ * the backend area (e.g. 'max-ring-page-order' for xen-block,
+ * 'feature-rx-copy' for xen-net). It must be called after the
+ * backend and frontend areas are populated, because it can invoke
+ * aio_poll() (e.g. through blkconf_geometry()) and thus process
+ * watch events which need to read the 'state' nodes. But it must
+ * be called *before* the backend state is set to InitWait below,
+ * because InitWait is the frontend's cue that the backend's
+ * feature nodes can be read; a frontend which reads them promptly
+ * (as Linux blkfront and netfront do, without waiting or retrying)
+ * must not find them missing.
+ */
if (xendev_class->realize) {
xendev_class->realize(xendev, errp);
if (*errp) {
@@ -1100,6 +1112,8 @@ static void xen_device_realize(DeviceState *dev, Error **errp)
}
}
+ xen_device_backend_set_state(xendev, XenbusStateInitWait);
+
xendev->exit.notify = xen_device_exit;
qemu_add_exit_notifier(&xendev->exit);
return;
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 04/21] hw/xen: Publish backend features before setting state to InitWait
2026-11-24 23:22 ` [PATCH v1 04/21] hw/xen: Publish backend features before setting state to InitWait David Woodhouse
@ 2026-11-25 11:05 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:05 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> The XenbusStateInitWait transition tells the frontend that the
> backend's parameters are readable, but xen_device_realize() set it
> before calling the implementation's realize method — which is what
> writes the feature nodes ('max-ring-page-order' et al. for xen-block,
> 'feature-rx-copy' for xen-net).
>
> Linux blkfront reads 'max-ring-page-order' with xenbus_read_unsigned():
> no wait, no retry, default 0. Lose the race and it silently negotiates
> a single-page ring — 32 request slots instead of 256. A device
> hot-plugged into a running guest loses essentially every time; at boot
> the frontend doesn't come looking until long after realize finished.
> Netfront reads its feature nodes the same way.
>
> Commit 240cc11369fc ("hw/xen: Avoid crash when backend watch fires too
> early") introduced this by moving the realize call after the block of
> code which both populates the initial xenstore nodes *and* sets
> InitWait. The crash it fixed was real — xen-block's realize processes
> watch events via blkconf_geometry()'s aio_poll(), and the handlers fell
> over when the nodes didn't yet exist — but only the node population
> needed to come first.
>
> So keep the node population and the 'online' write before realize, and
> move only the InitWait transition after it. A watch event during
> realize now finds the frontend in Initialising and no backend 'state'
> node, which the handlers tolerate; none of the three realize
> implementations reads the backend state. Verified against the original
> 2023 crash reproducer as well as the ring-order negotiation.
>
> Fixes: 240cc11369fc ("hw/xen: Avoid crash when backend watch fires too early")
> Reported-by: Mark Syms <mark.syms@citrix.com>
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/xen/xen-bus.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 05/21] hw/i386/kvm/xen_gnttab: Fix error handling in xen_be_gnttab_map_refs()
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (3 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 04/21] hw/xen: Publish backend features before setting state to InitWait David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:07 ` Paul Durrant
2026-11-30 13:17 ` Alex Bennée
2026-11-24 23:22 ` [PATCH v1 06/21] hw/xen: Validate grant copy segments against the page size David Woodhouse
` (15 subsequent siblings)
20 siblings, 2 replies; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
When the grant's target page cannot be mapped, the failure path calls
gnt_unref(), which asserts that the map_track[] refcount is non-zero —
but the refcount was only incremented after a successful mapping. Take
the reference as soon as gnt_ref() succeeds, so the failure path stays
balanced.
Refuse writable mappings, including a write upgrade of an existing
mapping, when the underlying memory region is read-only, and set errno
when the upgrade fails.
Fixes: b08d88e30f06 ("hw/xen: Add emulated implementation of grant table operations")
Reported-by: Hui Peng <benquike@gmail.com>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/i386/kvm/xen_gnttab.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/hw/i386/kvm/xen_gnttab.c b/hw/i386/kvm/xen_gnttab.c
index 85b324e62d0..26d1febac4d 100644
--- a/hw/i386/kvm/xen_gnttab.c
+++ b/hw/i386/kvm/xen_gnttab.c
@@ -363,7 +363,9 @@ static void *xen_be_gnttab_map_refs(struct xengntdev_handle *xgt,
act = g_hash_table_lookup(xgt->active_maps, GINT_TO_POINTER(refs[0]));
if (act) {
if ((prot & PROT_WRITE) && !(act->prot & PROT_WRITE)) {
- if (gnt_ref(s, refs[0], prot) == INVALID_GPA) {
+ if (act->mrs.readonly ||
+ gnt_ref(s, refs[0], prot) == INVALID_GPA) {
+ errno = EINVAL;
return NULL;
}
act->prot |= PROT_WRITE;
@@ -376,12 +378,19 @@ static void *xen_be_gnttab_map_refs(struct xengntdev_handle *xgt,
return NULL;
}
+ /*
+ * Keep the map_track[] count balanced with the gnt_unref() in the
+ * failure path below, which asserts that it never underflows.
+ */
+ s->map_track[refs[0]]++;
+
act = g_new0(struct active_ref, 1);
act->prot = prot;
act->refcnt = 1;
act->mrs = memory_region_find(get_system_memory(), gpa, XEN_PAGE_SIZE);
if (act->mrs.mr &&
+ !(act->mrs.readonly && (prot & PROT_WRITE)) &&
!int128_lt(act->mrs.size, int128_make64(XEN_PAGE_SIZE)) &&
memory_region_get_ram_addr(act->mrs.mr) != RAM_ADDR_INVALID) {
act->virtaddr = qemu_map_ram_ptr(act->mrs.mr->ram_block,
@@ -394,7 +403,6 @@ static void *xen_be_gnttab_map_refs(struct xengntdev_handle *xgt,
return NULL;
}
- s->map_track[refs[0]]++;
g_hash_table_insert(xgt->active_maps, GINT_TO_POINTER(refs[0]), act);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 05/21] hw/i386/kvm/xen_gnttab: Fix error handling in xen_be_gnttab_map_refs()
2026-11-24 23:22 ` [PATCH v1 05/21] hw/i386/kvm/xen_gnttab: Fix error handling in xen_be_gnttab_map_refs() David Woodhouse
@ 2026-11-25 11:07 ` Paul Durrant
2026-11-30 13:17 ` Alex Bennée
1 sibling, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:07 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> When the grant's target page cannot be mapped, the failure path calls
> gnt_unref(), which asserts that the map_track[] refcount is non-zero —
> but the refcount was only incremented after a successful mapping. Take
> the reference as soon as gnt_ref() succeeds, so the failure path stays
> balanced.
>
> Refuse writable mappings, including a write upgrade of an existing
> mapping, when the underlying memory region is read-only, and set errno
> when the upgrade fails.
>
> Fixes: b08d88e30f06 ("hw/xen: Add emulated implementation of grant table operations")
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/i386/kvm/xen_gnttab.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread* Re: [PATCH v1 05/21] hw/i386/kvm/xen_gnttab: Fix error handling in xen_be_gnttab_map_refs()
2026-11-24 23:22 ` [PATCH v1 05/21] hw/i386/kvm/xen_gnttab: Fix error handling in xen_be_gnttab_map_refs() David Woodhouse
2026-11-25 11:07 ` Paul Durrant
@ 2026-11-30 13:17 ` Alex Bennée
1 sibling, 0 replies; 51+ messages in thread
From: Alex Bennée @ 2026-11-30 13:17 UTC (permalink / raw)
To: David Woodhouse
Cc: qemu-devel, xen-devel, kvm, Paolo Bonzini, Peter Maydell,
Paul Durrant, Stefano Stabellini, Anthony PERARD,
Edgar E . Iglesias, Michael S . Tsirkin, Richard Henderson,
Marcelo Tosatti, Marc-André Lureau, Jason Wang, Hui Peng,
Mark Syms, Feifan Qian, David Woodhouse
David Woodhouse <dwmw2@infradead.org> writes:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> When the grant's target page cannot be mapped, the failure path calls
> gnt_unref(), which asserts that the map_track[] refcount is non-zero —
> but the refcount was only incremented after a successful mapping. Take
> the reference as soon as gnt_ref() succeeds, so the failure path stays
> balanced.
>
> Refuse writable mappings, including a write upgrade of an existing
> mapping, when the underlying memory region is read-only, and set errno
> when the upgrade fails.
>
> Fixes: b08d88e30f06 ("hw/xen: Add emulated implementation of grant table operations")
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
Again Resolves:
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/i386/kvm/xen_gnttab.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/hw/i386/kvm/xen_gnttab.c b/hw/i386/kvm/xen_gnttab.c
> index 85b324e62d0..26d1febac4d 100644
> --- a/hw/i386/kvm/xen_gnttab.c
> +++ b/hw/i386/kvm/xen_gnttab.c
> @@ -363,7 +363,9 @@ static void *xen_be_gnttab_map_refs(struct xengntdev_handle *xgt,
> act = g_hash_table_lookup(xgt->active_maps, GINT_TO_POINTER(refs[0]));
> if (act) {
> if ((prot & PROT_WRITE) && !(act->prot & PROT_WRITE)) {
> - if (gnt_ref(s, refs[0], prot) == INVALID_GPA) {
> + if (act->mrs.readonly ||
> + gnt_ref(s, refs[0], prot) == INVALID_GPA) {
> + errno = EINVAL;
> return NULL;
> }
> act->prot |= PROT_WRITE;
> @@ -376,12 +378,19 @@ static void *xen_be_gnttab_map_refs(struct xengntdev_handle *xgt,
> return NULL;
> }
>
> + /*
> + * Keep the map_track[] count balanced with the gnt_unref() in the
> + * failure path below, which asserts that it never underflows.
> + */
> + s->map_track[refs[0]]++;
> +
> act = g_new0(struct active_ref, 1);
> act->prot = prot;
> act->refcnt = 1;
> act->mrs = memory_region_find(get_system_memory(), gpa, XEN_PAGE_SIZE);
>
> if (act->mrs.mr &&
> + !(act->mrs.readonly && (prot & PROT_WRITE)) &&
> !int128_lt(act->mrs.size, int128_make64(XEN_PAGE_SIZE)) &&
> memory_region_get_ram_addr(act->mrs.mr) != RAM_ADDR_INVALID) {
> act->virtaddr = qemu_map_ram_ptr(act->mrs.mr->ram_block,
> @@ -394,7 +403,6 @@ static void *xen_be_gnttab_map_refs(struct xengntdev_handle *xgt,
> return NULL;
> }
>
> - s->map_track[refs[0]]++;
> g_hash_table_insert(xgt->active_maps, GINT_TO_POINTER(refs[0]), act);
> }
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 06/21] hw/xen: Validate grant copy segments against the page size
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (4 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 05/21] hw/i386/kvm/xen_gnttab: Fix error handling in xen_be_gnttab_map_refs() David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:09 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 07/21] hw/i386/kvm/xen_evtchn: Validate PIRQ numbers in physdev operations David Woodhouse
` (14 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
Reject a grant copy segment whose offset and length reach beyond the
granted page, matching Xen's GNTST_bad_copy_arg behaviour, in both the
emulated gnttab backend and the libxengnttab fallback. The only current
caller, xen-block, already bounds its segments to a single page.
Fixes: b08d88e30f06 ("hw/xen: Add emulated implementation of grant table operations")
Fixes: c412ba47b2ec ("hw/xen: Add gnttab operations to allow redirection to internal emulation")
Reported-by: Hui Peng <benquike@gmail.com>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/i386/kvm/xen_gnttab.c | 10 ++++++++++
hw/xen/xen-operations.c | 11 +++++++++++
2 files changed, 21 insertions(+)
diff --git a/hw/i386/kvm/xen_gnttab.c b/hw/i386/kvm/xen_gnttab.c
index 26d1febac4d..6e0038b22ff 100644
--- a/hw/i386/kvm/xen_gnttab.c
+++ b/hw/i386/kvm/xen_gnttab.c
@@ -473,6 +473,16 @@ static int xen_be_gnttab_copy(struct xengntdev_handle *xgt, bool to_domain,
void *page;
uint32_t ref = to_domain ? seg->dest.foreign.ref :
seg->source.foreign.ref;
+ off_t offset = to_domain ? seg->dest.foreign.offset :
+ seg->source.foreign.offset;
+
+ if (offset < 0 || offset > XEN_PAGE_SIZE ||
+ seg->len > XEN_PAGE_SIZE - offset) {
+ if (errp) {
+ error_setg(errp, "grant copy segment out of page bounds");
+ }
+ return -EINVAL;
+ }
page = xen_be_gnttab_map_refs(xgt, 1, domid, &ref, prot);
if (!page) {
diff --git a/hw/xen/xen-operations.c b/hw/xen/xen-operations.c
index e00983ec447..bf0ec040bcf 100644
--- a/hw/xen/xen-operations.c
+++ b/hw/xen/xen-operations.c
@@ -50,6 +50,17 @@ static int libxengnttab_fallback_grant_copy(xengnttab_handle *xgt,
for (i = 0; i < nr_segs; i++) {
XenGrantCopySegment *seg = &segs[i];
+ off_t offset = to_domain ? seg->dest.foreign.offset :
+ seg->source.foreign.offset;
+
+ if (offset < 0 || offset > XEN_PAGE_SIZE ||
+ seg->len > XEN_PAGE_SIZE - offset) {
+ if (errp) {
+ error_setg(errp, "grant copy segment out of page bounds");
+ }
+ rc = -EINVAL;
+ goto done;
+ }
refs[i] = to_domain ? seg->dest.foreign.ref :
seg->source.foreign.ref;
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 06/21] hw/xen: Validate grant copy segments against the page size
2026-11-24 23:22 ` [PATCH v1 06/21] hw/xen: Validate grant copy segments against the page size David Woodhouse
@ 2026-11-25 11:09 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:09 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> Reject a grant copy segment whose offset and length reach beyond the
> granted page, matching Xen's GNTST_bad_copy_arg behaviour, in both the
> emulated gnttab backend and the libxengnttab fallback. The only current
> caller, xen-block, already bounds its segments to a single page.
>
> Fixes: b08d88e30f06 ("hw/xen: Add emulated implementation of grant table operations")
> Fixes: c412ba47b2ec ("hw/xen: Add gnttab operations to allow redirection to internal emulation")
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/i386/kvm/xen_gnttab.c | 10 ++++++++++
> hw/xen/xen-operations.c | 11 +++++++++++
> 2 files changed, 21 insertions(+)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 07/21] hw/i386/kvm/xen_evtchn: Validate PIRQ numbers in physdev operations
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (5 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 06/21] hw/xen: Validate grant copy segments against the page size David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:12 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 08/21] hw/i386/kvm/xen_evtchn: Fix off-by-one in do_remove_pci_vector() David Woodhouse
` (13 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
xen_physdev_eoi_pirq() and xen_physdev_query_pirq() used the given PIRQ
number to index the PIRQ tables without checking it against nr_pirqs.
Reject out-of-range values, and reject PIRQ 0 in bind_pirq and
map_pirq. PIRQs 0-15 are reserved for the initial domain's identity
claims of the legacy ISA IRQs — the allocators, Xen's and ours alike,
never hand them out — and an HVM guest has no such claim. QEMU's
gsi_pirq[] and MSI target lookups both treat 0 as "no PIRQ", so a
guest-mapped pirq 0 could never deliver anything; better to refuse it
than to create a silently dead mapping.
Fixes: CVE-2026-123070
Fixes: 799c23548f0d ("i386/xen: Implement HYPERVISOR_physdev_op")
Reported-by: bubblehuntr <https://gitlab.com/bubblehuntr>
Reported-by: Hui Peng <benquike@gmail.com>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/3639
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/i386/kvm/xen_evtchn.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
index 9379383e532..3aff01b5d6c 100644
--- a/hw/i386/kvm/xen_evtchn.c
+++ b/hw/i386/kvm/xen_evtchn.c
@@ -1283,7 +1283,7 @@ int xen_evtchn_bind_pirq_op(struct evtchn_bind_pirq *pirq)
return -ENOTSUP;
}
- if (pirq->pirq >= s->nr_pirqs) {
+ if (!pirq->pirq || pirq->pirq >= s->nr_pirqs) {
return -EINVAL;
}
@@ -1877,7 +1877,7 @@ int xen_physdev_map_pirq(struct physdev_map_pirq *map)
return pirq;
}
map->pirq = pirq;
- } else if (pirq >= s->nr_pirqs) {
+ } else if (!pirq || pirq >= s->nr_pirqs) {
return -EINVAL;
} else {
/*
@@ -1958,6 +1958,10 @@ int xen_physdev_eoi_pirq(struct physdev_eoi *eoi)
return -ENOTSUP;
}
+ if (pirq < 0 || pirq >= s->nr_pirqs) {
+ return -EINVAL;
+ }
+
BQL_LOCK_GUARD();
QEMU_LOCK_GUARD(&s->port_lock);
@@ -1990,6 +1994,10 @@ int xen_physdev_query_pirq(struct physdev_irq_status_query *query)
return -ENOTSUP;
}
+ if (pirq < 0 || pirq >= s->nr_pirqs) {
+ return -EINVAL;
+ }
+
BQL_LOCK_GUARD();
QEMU_LOCK_GUARD(&s->port_lock);
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 07/21] hw/i386/kvm/xen_evtchn: Validate PIRQ numbers in physdev operations
2026-11-24 23:22 ` [PATCH v1 07/21] hw/i386/kvm/xen_evtchn: Validate PIRQ numbers in physdev operations David Woodhouse
@ 2026-11-25 11:12 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:12 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> xen_physdev_eoi_pirq() and xen_physdev_query_pirq() used the given PIRQ
> number to index the PIRQ tables without checking it against nr_pirqs.
> Reject out-of-range values, and reject PIRQ 0 in bind_pirq and
> map_pirq. PIRQs 0-15 are reserved for the initial domain's identity
> claims of the legacy ISA IRQs — the allocators, Xen's and ours alike,
> never hand them out — and an HVM guest has no such claim. QEMU's
> gsi_pirq[] and MSI target lookups both treat 0 as "no PIRQ", so a
> guest-mapped pirq 0 could never deliver anything; better to refuse it
> than to create a silently dead mapping.
>
> Fixes: CVE-2026-123070
> Fixes: 799c23548f0d ("i386/xen: Implement HYPERVISOR_physdev_op")
> Reported-by: bubblehuntr <https://gitlab.com/bubblehuntr>
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/3639
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/i386/kvm/xen_evtchn.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 08/21] hw/i386/kvm/xen_evtchn: Fix off-by-one in do_remove_pci_vector()
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (6 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 07/21] hw/i386/kvm/xen_evtchn: Validate PIRQ numbers in physdev operations David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:16 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 09/21] i386/xen: Don't inject event on invalid port in qmp_xen_event_inject() David Woodhouse
` (12 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
The empty-word optimisation advanced pirq by 64 on top of the loop
increment, so the first PIRQ of the following word was never examined
and could retain a stale device binding after the device was removed.
Fixes: 6096cf7877bc ("hw/xen: Support MSI mapping to PIRQ")
Reported-by: Hui Peng <benquike@gmail.com>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/i386/kvm/xen_evtchn.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
index 3aff01b5d6c..d0807f5fece 100644
--- a/hw/i386/kvm/xen_evtchn.c
+++ b/hw/i386/kvm/xen_evtchn.c
@@ -1701,7 +1701,7 @@ static void do_remove_pci_vector(XenEvtchnState *s, PCIDevice *dev, int vector,
* and cache lines).
*/
if (!(pirq & 63) && !(pirq_inuse_word(s, pirq))) {
- pirq += 64;
+ pirq += 63;
continue;
}
if (except_pirq && pirq == except_pirq) {
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 08/21] hw/i386/kvm/xen_evtchn: Fix off-by-one in do_remove_pci_vector()
2026-11-24 23:22 ` [PATCH v1 08/21] hw/i386/kvm/xen_evtchn: Fix off-by-one in do_remove_pci_vector() David Woodhouse
@ 2026-11-25 11:16 ` Paul Durrant
2026-11-25 12:03 ` David Woodhouse
0 siblings, 1 reply; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:16 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> The empty-word optimisation advanced pirq by 64 on top of the loop
> increment, so the first PIRQ of the following word was never examined
> and could retain a stale device binding after the device was removed.
>
> Fixes: 6096cf7877bc ("hw/xen: Support MSI mapping to PIRQ")
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/i386/kvm/xen_evtchn.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
> index 3aff01b5d6c..d0807f5fece 100644
> --- a/hw/i386/kvm/xen_evtchn.c
> +++ b/hw/i386/kvm/xen_evtchn.c
> @@ -1701,7 +1701,7 @@ static void do_remove_pci_vector(XenEvtchnState *s, PCIDevice *dev, int vector,
> * and cache lines).
> */
> if (!(pirq & 63) && !(pirq_inuse_word(s, pirq))) {
> - pirq += 64;
> + pirq += 63;
I guess I'm missing a subtlety here, but the test only fires if pirq is
a multiple of 64... so why is advancing to the next word by adding 64
not correct?
> continue;
> }
> if (except_pirq && pirq == except_pirq) {
^ permalink raw reply [flat|nested] 51+ messages in thread* Re: [PATCH v1 08/21] hw/i386/kvm/xen_evtchn: Fix off-by-one in do_remove_pci_vector()
2026-11-25 11:16 ` Paul Durrant
@ 2026-11-25 12:03 ` David Woodhouse
2026-11-25 13:31 ` Paul Durrant
0 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-25 12:03 UTC (permalink / raw)
To: Paul Durrant, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian
[-- Attachment #1: Type: text/plain, Size: 868 bytes --]
On Wed, 2026-11-25 at 11:16 +0000, Paul Durrant wrote:
>
> I guess I'm missing a subtlety here, but the test only fires if pirq is
> a multiple of 64... so why is advancing to the next word by adding 64
> not correct?
You're missing the same subtlety that I missed when I wrote it in the
first place: the loop *itself* does pirq++ every time, so when we do
'pirq += 64; continue;' we end up adding *65*.
for (pirq = 0; pirq < s->nr_pirqs; pirq++) {
/*
* We could be cleverer here, but it isn't really a fast path, and
* this trivial optimisation is enough to let us skip the big gap
* in the middle a bit quicker (in terms of both loop iterations,
* and cache lines).
*/
if (!(pirq & 63) && !(pirq_inuse_word(s, pirq))) {
pirq += 63;
continue;
}
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6179 bytes --]
^ permalink raw reply [flat|nested] 51+ messages in thread* Re: [PATCH v1 08/21] hw/i386/kvm/xen_evtchn: Fix off-by-one in do_remove_pci_vector()
2026-11-25 12:03 ` David Woodhouse
@ 2026-11-25 13:31 ` Paul Durrant
2026-11-25 13:43 ` David Woodhouse
2026-11-30 12:04 ` Paul Durrant
0 siblings, 2 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 13:31 UTC (permalink / raw)
To: David Woodhouse, Paul Durrant, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian
On 25/11/2026 05:03, David Woodhouse wrote:
> On Wed, 2026-11-25 at 11:16 +0000, Paul Durrant wrote:
>>
>> I guess I'm missing a subtlety here, but the test only fires if pirq is
>> a multiple of 64... so why is advancing to the next word by adding 64
>> not correct?
>
> You're missing the same subtlety that I missed when I wrote it in the
> first place: the loop *itself* does pirq++ every time, so when we do
> 'pirq += 64; continue;' we end up adding *65*.
>
> for (pirq = 0; pirq < s->nr_pirqs; pirq++) {
> /*
> * We could be cleverer here, but it isn't really a fast path, and
> * this trivial optimisation is enough to let us skip the big gap
> * in the middle a bit quicker (in terms of both loop iterations,
> * and cache lines).
> */
> if (!(pirq & 63) && !(pirq_inuse_word(s, pirq))) {
> pirq += 63;
> continue;
> }
Gah! Recoding as a while loop where the increment is either 1 or 64
would make this much less fragile.
^ permalink raw reply [flat|nested] 51+ messages in thread* Re: [PATCH v1 08/21] hw/i386/kvm/xen_evtchn: Fix off-by-one in do_remove_pci_vector()
2026-11-25 13:31 ` Paul Durrant
@ 2026-11-25 13:43 ` David Woodhouse
2026-11-26 10:19 ` David Woodhouse
2026-11-30 12:04 ` Paul Durrant
1 sibling, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-25 13:43 UTC (permalink / raw)
To: Paul Durrant, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian
[-- Attachment #1: Type: text/plain, Size: 1374 bytes --]
On Wed, 2026-11-25 at 13:31 +0000, Paul Durrant wrote:
> On 25/11/2026 05:03, David Woodhouse wrote:
> > On Wed, 2026-11-25 at 11:16 +0000, Paul Durrant wrote:
> > >
> > > I guess I'm missing a subtlety here, but the test only fires if pirq is
> > > a multiple of 64... so why is advancing to the next word by adding 64
> > > not correct?
> >
> > You're missing the same subtlety that I missed when I wrote it in the
> > first place: the loop *itself* does pirq++ every time, so when we do
> > 'pirq += 64; continue;' we end up adding *65*.
> >
> > for (pirq = 0; pirq < s->nr_pirqs; pirq++) {
> > /*
> > * We could be cleverer here, but it isn't really a fast path, and
> > * this trivial optimisation is enough to let us skip the big gap
> > * in the middle a bit quicker (in terms of both loop iterations,
> > * and cache lines).
> > */
> > if (!(pirq & 63) && !(pirq_inuse_word(s, pirq))) {
> > pirq += 63;
> > continue;
> > }
>
> Gah! Recoding as a while loop where the increment is either 1 or 64
> would make this much less fragile.
Or refactor it completely to use ffs? Do we have a for_each_set_bit()
helper? Do we want one?
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6179 bytes --]
^ permalink raw reply [flat|nested] 51+ messages in thread* Re: [PATCH v1 08/21] hw/i386/kvm/xen_evtchn: Fix off-by-one in do_remove_pci_vector()
2026-11-25 13:43 ` David Woodhouse
@ 2026-11-26 10:19 ` David Woodhouse
0 siblings, 0 replies; 51+ messages in thread
From: David Woodhouse @ 2026-11-26 10:19 UTC (permalink / raw)
To: Paul Durrant, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian
[-- Attachment #1: Type: text/plain, Size: 3149 bytes --]
On Wed, 2026-11-25 at 13:43 +0000, David Woodhouse wrote:
> On Wed, 2026-11-25 at 13:31 +0000, Paul Durrant wrote:
> > On 25/11/2026 05:03, David Woodhouse wrote:
> > > On Wed, 2026-11-25 at 11:16 +0000, Paul Durrant wrote:
> > > >
> > > > I guess I'm missing a subtlety here, but the test only fires if pirq is
> > > > a multiple of 64... so why is advancing to the next word by adding 64
> > > > not correct?
> > >
> > > You're missing the same subtlety that I missed when I wrote it in the
> > > first place: the loop *itself* does pirq++ every time, so when we do
> > > 'pirq += 64; continue;' we end up adding *65*.
> > >
> > > for (pirq = 0; pirq < s->nr_pirqs; pirq++) {
> > > /*
> > > * We could be cleverer here, but it isn't really a fast path, and
> > > * this trivial optimisation is enough to let us skip the big gap
> > > * in the middle a bit quicker (in terms of both loop iterations,
> > > * and cache lines).
> > > */
> > > if (!(pirq & 63) && !(pirq_inuse_word(s, pirq))) {
> > > pirq += 63;
> > > continue;
> > > }
> >
> > Gah! Recoding as a while loop where the increment is either 1 or 64
> > would make this much less fragile.
>
> Or refactor it completely to use ffs? Do we have a for_each_set_bit()
> helper? Do we want one?
I iterated on this a few times, and even as a while() loop you still
end up skipping to the last *zero* and then adding one more, so it
might as well stay as for() loop and do the skip *every* time not just
for full empty words:
for (pirq = 0; pirq < s->nr_pirqs; pirq++) {
uint64_t bits;
if (pirq_inuse(s, pirq) &&
!(except_pirq && pirq == except_pirq) &&
s->pirq[pirq].dev == dev &&
(vector == -1 || s->pirq[pirq].vector == vector)) {
/*
* It could theoretically be bound to a port already, but that
* is OK.
*/
s->pirq[pirq].dev = dev;
s->pirq[pirq].gsi = IRQ_UNBOUND;
s->pirq[pirq].is_msix = false;
s->pirq[pirq].vector = 0;
s->pirq[pirq].is_masked = false;
s->pirq[pirq].is_translated = false;
}
/*
* Skip to the last clear bit before the next in-use PIRQ, or to
* the end of the word if the rest of it is clear, leaving the
* loop increment to do the final step.
*/
bits = (pirq_inuse_word(s, pirq) >> (pirq & 63)) >> 1;
if (bits) {
pirq += ctz64(bits);
} else {
pirq |= 63;
}
}
And actually, written like this the *benefit* of the skip is largely
removed, as the subtle difference here is that we now check
pirq_inuse() before dereferencing s->pirq[pirq] so it isn't trashing
the cache anyway.
But on the whole, I think the single-character change I originally
posted is the simpler option in the short term.
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6179 bytes --]
^ permalink raw reply [flat|nested] 51+ messages in thread
* Re: [PATCH v1 08/21] hw/i386/kvm/xen_evtchn: Fix off-by-one in do_remove_pci_vector()
2026-11-25 13:31 ` Paul Durrant
2026-11-25 13:43 ` David Woodhouse
@ 2026-11-30 12:04 ` Paul Durrant
1 sibling, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-30 12:04 UTC (permalink / raw)
To: David Woodhouse, Paul Durrant, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian
On 25/11/2026 13:31, Paul Durrant wrote:
> On 25/11/2026 05:03, David Woodhouse wrote:
>> On Wed, 2026-11-25 at 11:16 +0000, Paul Durrant wrote:
>>>
>>> I guess I'm missing a subtlety here, but the test only fires if pirq is
>>> a multiple of 64... so why is advancing to the next word by adding 64
>>> not correct?
>>
>> You're missing the same subtlety that I missed when I wrote it in the
>> first place: the loop *itself* does pirq++ every time, so when we do
>> 'pirq += 64; continue;' we end up adding *65*.
>>
>> for (pirq = 0; pirq < s->nr_pirqs; pirq++) {
>> /*
>> * We could be cleverer here, but it isn't really a fast
>> path, and
>> * this trivial optimisation is enough to let us skip the big
>> gap
>> * in the middle a bit quicker (in terms of both loop
>> iterations,
>> * and cache lines).
>> */
>> if (!(pirq & 63) && !(pirq_inuse_word(s, pirq))) {
>> pirq += 63;
>> continue;
>> }
>
Given that (in off-thread discussion) this seems to be the least-worst
way to fix this...
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 09/21] i386/xen: Don't inject event on invalid port in qmp_xen_event_inject()
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (7 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 08/21] hw/i386/kvm/xen_evtchn: Fix off-by-one in do_remove_pci_vector() David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-24 23:31 ` Philippe Mathieu-Daudé
2026-11-25 11:17 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 10/21] hw/i386/kvm/xen_evtchn: Reuse existing backend port in find_be_port() David Woodhouse
` (11 subsequent siblings)
20 siblings, 2 replies; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
qmp_xen_event_inject() reported the invalid port with error_setg() but
then carried on regardless, passing it to set_port_pending(). Return
after setting the error.
Fixes: 507cb64d6e66 ("i386/xen: add monitor commands to test event injection")
Reported-by: Hui Peng <benquike@gmail.com>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/i386/kvm/xen_evtchn.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
index d0807f5fece..7fd8c3f3182 100644
--- a/hw/i386/kvm/xen_evtchn.c
+++ b/hw/i386/kvm/xen_evtchn.c
@@ -2342,6 +2342,7 @@ void qmp_xen_event_inject(uint32_t port, Error **errp)
if (!valid_port(port)) {
error_setg(errp, "Invalid port %u", port);
+ return;
}
QEMU_LOCK_GUARD(&s->port_lock);
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 09/21] i386/xen: Don't inject event on invalid port in qmp_xen_event_inject()
2026-11-24 23:22 ` [PATCH v1 09/21] i386/xen: Don't inject event on invalid port in qmp_xen_event_inject() David Woodhouse
@ 2026-11-24 23:31 ` Philippe Mathieu-Daudé
2026-11-25 11:17 ` Paul Durrant
1 sibling, 0 replies; 51+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-24 23:31 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
On 25/11/26 00:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> qmp_xen_event_inject() reported the invalid port with error_setg() but
> then carried on regardless, passing it to set_port_pending(). Return
> after setting the error.
>
> Fixes: 507cb64d6e66 ("i386/xen: add monitor commands to test event injection")
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/i386/kvm/xen_evtchn.c | 1 +
> 1 file changed, 1 insertion(+)
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 51+ messages in thread* Re: [PATCH v1 09/21] i386/xen: Don't inject event on invalid port in qmp_xen_event_inject()
2026-11-24 23:22 ` [PATCH v1 09/21] i386/xen: Don't inject event on invalid port in qmp_xen_event_inject() David Woodhouse
2026-11-24 23:31 ` Philippe Mathieu-Daudé
@ 2026-11-25 11:17 ` Paul Durrant
1 sibling, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:17 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> qmp_xen_event_inject() reported the invalid port with error_setg() but
> then carried on regardless, passing it to set_port_pending(). Return
> after setting the error.
>
> Fixes: 507cb64d6e66 ("i386/xen: add monitor commands to test event injection")
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/i386/kvm/xen_evtchn.c | 1 +
> 1 file changed, 1 insertion(+)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 10/21] hw/i386/kvm/xen_evtchn: Reuse existing backend port in find_be_port()
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (8 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 09/21] i386/xen: Don't inject event on invalid port in qmp_xen_event_inject() David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:18 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 11/21] hw/i386/kvm/xen: Don't leak gnttab handle on reset David Woodhouse
` (10 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
After a guest soft reset, close_port() clears only the guest side of an
interdomain port; the backend handle still owns its be_handles[] slot.
Binding again then allocated a fresh slot each time, leaking the old
one — and leaving a dangling entry if the handle is later closed. Reuse
the slot the handle already owns.
Fixes: 794fba23a53a ("hw/xen: Add backend implementation of interdomain event channel support")
Reported-by: Hui Peng <benquike@gmail.com>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/i386/kvm/xen_evtchn.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
index 7fd8c3f3182..e2803cad0a8 100644
--- a/hw/i386/kvm/xen_evtchn.c
+++ b/hw/i386/kvm/xen_evtchn.c
@@ -2052,6 +2052,16 @@ static int find_be_port(XenEvtchnState *s, struct xenevtchn_handle *xc)
{
int i;
+ /*
+ * A handle may still own a backend port from before a guest soft reset;
+ * close_port() clears only the guest side. Reuse it rather than leaking
+ * the old slot and allocating a second one.
+ */
+ if (xc->be_port && xc->be_port < EVTCHN_2L_NR_CHANNELS &&
+ s->be_handles[xc->be_port] == xc) {
+ return xc->be_port;
+ }
+
for (i = 1; i < EVTCHN_2L_NR_CHANNELS; i++) {
if (!s->be_handles[i]) {
s->be_handles[i] = xc;
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 10/21] hw/i386/kvm/xen_evtchn: Reuse existing backend port in find_be_port()
2026-11-24 23:22 ` [PATCH v1 10/21] hw/i386/kvm/xen_evtchn: Reuse existing backend port in find_be_port() David Woodhouse
@ 2026-11-25 11:18 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:18 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> After a guest soft reset, close_port() clears only the guest side of an
> interdomain port; the backend handle still owns its be_handles[] slot.
> Binding again then allocated a fresh slot each time, leaking the old
> one — and leaving a dangling entry if the handle is later closed. Reuse
> the slot the handle already owns.
>
> Fixes: 794fba23a53a ("hw/xen: Add backend implementation of interdomain event channel support")
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/i386/kvm/xen_evtchn.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
More soft reset joy...
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 11/21] hw/i386/kvm/xen: Don't leak gnttab handle on reset
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (9 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 10/21] hw/i386/kvm/xen_evtchn: Reuse existing backend port in find_be_port() David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:20 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 12/21] hw/i386/kvm/xen_xenstore: Apply offset before truncation in xs_append_strings() David Woodhouse
` (9 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
xen_xenstore_reset() and xen_primary_console_reset() open a new gnttab
handle without closing the previous one, leaking it and its mappings on
each guest soft reset. Close the old handle first; closing unmaps any
remaining refs.
Fixes: d05864d23b1a ("hw/xen: Map guest XENSTORE_PFN grant in emulated Xenstore")
Fixes: a72ccc7fc449 ("hw/xen: add support for Xen primary console in emulated mode")
Reported-by: Hui Peng <benquike@gmail.com>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/i386/kvm/xen_primary_console.c | 3 +++
hw/i386/kvm/xen_xenstore.c | 3 +++
2 files changed, 6 insertions(+)
diff --git a/hw/i386/kvm/xen_primary_console.c b/hw/i386/kvm/xen_primary_console.c
index bf61f6235be..0a2a6de3ecb 100644
--- a/hw/i386/kvm/xen_primary_console.c
+++ b/hw/i386/kvm/xen_primary_console.c
@@ -184,6 +184,9 @@ int xen_primary_console_reset(void)
trace_xen_primary_console_reset(s->guest_port);
+ if (s->gt) {
+ qemu_xen_gnttab_close(s->gt);
+ }
s->gt = qemu_xen_gnttab_open();
uint32_t xs_gntref = GNTTAB_RESERVED_CONSOLE;
s->granted_xs = qemu_xen_gnttab_map_refs(s->gt, 1, xen_domid, &xs_gntref,
diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c
index 7d6d6d5cbb7..ff0dfb1bff8 100644
--- a/hw/i386/kvm/xen_xenstore.c
+++ b/hw/i386/kvm/xen_xenstore.c
@@ -1490,6 +1490,9 @@ int xen_xenstore_reset(void)
* first place. Map the grant anyway, mostly for cosmetic purposes so
* it *looks* like it's in use in the guest-visible grant table.
*/
+ if (s->gt) {
+ qemu_xen_gnttab_close(s->gt);
+ }
s->gt = qemu_xen_gnttab_open();
uint32_t xs_gntref = GNTTAB_RESERVED_XENSTORE;
s->granted_xs = qemu_xen_gnttab_map_refs(s->gt, 1, xen_domid, &xs_gntref,
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 11/21] hw/i386/kvm/xen: Don't leak gnttab handle on reset
2026-11-24 23:22 ` [PATCH v1 11/21] hw/i386/kvm/xen: Don't leak gnttab handle on reset David Woodhouse
@ 2026-11-25 11:20 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:20 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> xen_xenstore_reset() and xen_primary_console_reset() open a new gnttab
> handle without closing the previous one, leaking it and its mappings on
> each guest soft reset. Close the old handle first; closing unmaps any
> remaining refs.
>
> Fixes: d05864d23b1a ("hw/xen: Map guest XENSTORE_PFN grant in emulated Xenstore")
> Fixes: a72ccc7fc449 ("hw/xen: add support for Xen primary console in emulated mode")
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/i386/kvm/xen_primary_console.c | 3 +++
> hw/i386/kvm/xen_xenstore.c | 3 +++
> 2 files changed, 6 insertions(+)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 12/21] hw/i386/kvm/xen_xenstore: Apply offset before truncation in xs_append_strings()
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (10 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 11/21] hw/i386/kvm/xen: Don't leak gnttab handle on reset David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:22 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 13/21] hw/char/xen_console: Fix buffer trim when size exceeds twice the limit David Woodhouse
` (8 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
Truncating a string to the remaining payload space before applying the
requested starting offset corrupts the offset accounting, so
XS_DIRECTORY_PART returned wrong data for non-zero offsets. Skip to the
offset first, then check what fits.
Fixes: 0254c4d19df3 ("hw/xen: Add xenstore wire implementation and implementation stubs")
Reported-by: Hui Peng <benquike@gmail.com>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4525
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/i386/kvm/xen_xenstore.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c
index ff0dfb1bff8..7aa5d97e01a 100644
--- a/hw/i386/kvm/xen_xenstore.c
+++ b/hw/i386/kvm/xen_xenstore.c
@@ -614,6 +614,21 @@ static void xs_append_strings(XenXenstoreState *s, struct xsd_sockmsg *rsp,
size_t len = strlen(l->data) + 1; /* Including the NUL termination */
char *str = l->data;
+ /*
+ * Skip to the requested offset before checking what fits, so that
+ * truncation does not corrupt the offset accounting.
+ */
+ if (start) {
+ if (start >= len) {
+ start -= len;
+ continue;
+ }
+
+ str += start;
+ len -= start;
+ start = 0;
+ }
+
if (rsp->len + len > XENSTORE_PAYLOAD_MAX) {
if (truncate) {
len = XENSTORE_PAYLOAD_MAX - rsp->len;
@@ -626,17 +641,6 @@ static void xs_append_strings(XenXenstoreState *s, struct xsd_sockmsg *rsp,
}
}
- if (start) {
- if (start >= len) {
- start -= len;
- continue;
- }
-
- str += start;
- len -= start;
- start = 0;
- }
-
memcpy(&rsp_data[rsp->len], str, len);
rsp->len += len;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* [PATCH v1 13/21] hw/char/xen_console: Fix buffer trim when size exceeds twice the limit
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (11 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 12/21] hw/i386/kvm/xen_xenstore: Apply offset before truncation in xs_append_strings() David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:24 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 14/21] hw/9pfs/xen-9p-backend: Use validated snapshot for request iovecs David Woodhouse
` (7 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
In buffer_append() we handle a full buffer by discarding bytes from the
*middle*, preserving the oldest and the newest data. When the overflow
exceeded the max capacity (a limit set by the guest), the memmove()
destination was miscalculated and ended up before the start of the
buffer. In that case there is no older data worth preserving anyway;
just keep the newest max_capacity bytes.
Fixes: CVE-2026-123071
Fixes: e57dd20bb706 ("xen: add console backend driver.")
Reported-by: Giovanni Vignone <https://gitlab.com/gio24>
Reported-by: Hui Peng <benquike@gmail.com>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4191
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/char/xen_console.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c
index df6a708494d..849a93a8178 100644
--- a/hw/char/xen_console.c
+++ b/hw/char/xen_console.c
@@ -89,17 +89,25 @@ static bool buffer_append(XenConsole *con)
if (buffer->max_capacity &&
buffer->size > buffer->max_capacity) {
- /* Discard the middle of the data. */
-
+ /*
+ * Discard the middle of the data: keep the head of the buffer
+ * up to where the overflowing data will be moved down to end
+ * at max_capacity, and the newest 'keep' bytes. If the buffer
+ * has grown to more than twice max_capacity (the frontend may
+ * set an arbitrarily small 'limit'), there is no head to keep
+ * and the newest max_capacity bytes alone remain.
+ */
size_t over = buffer->size - buffer->max_capacity;
- uint8_t *maxpos = buffer->data + buffer->max_capacity;
+ size_t keep = MIN(over, buffer->max_capacity);
- memmove(maxpos - over, maxpos, over);
+ memmove(buffer->data + buffer->max_capacity - keep,
+ buffer->data + buffer->size - keep, keep);
buffer->data = g_realloc(buffer->data, buffer->max_capacity);
buffer->size = buffer->capacity = buffer->max_capacity;
- if (buffer->consumed > buffer->max_capacity - over)
- buffer->consumed = buffer->max_capacity - over;
+ if (buffer->consumed > buffer->max_capacity - keep) {
+ buffer->consumed = buffer->max_capacity - keep;
+ }
}
return true;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 13/21] hw/char/xen_console: Fix buffer trim when size exceeds twice the limit
2026-11-24 23:22 ` [PATCH v1 13/21] hw/char/xen_console: Fix buffer trim when size exceeds twice the limit David Woodhouse
@ 2026-11-25 11:24 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:24 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> In buffer_append() we handle a full buffer by discarding bytes from the
> *middle*, preserving the oldest and the newest data. When the overflow
> exceeded the max capacity (a limit set by the guest), the memmove()
> destination was miscalculated and ended up before the start of the
> buffer. In that case there is no older data worth preserving anyway;
> just keep the newest max_capacity bytes.
>
> Fixes: CVE-2026-123071
> Fixes: e57dd20bb706 ("xen: add console backend driver.")
> Reported-by: Giovanni Vignone <https://gitlab.com/gio24>
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4191
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/char/xen_console.c | 20 ++++++++++++++------
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 14/21] hw/9pfs/xen-9p-backend: Use validated snapshot for request iovecs
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (12 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 13/21] hw/char/xen_console: Fix buffer trim when size exceeds twice the limit David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:26 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 15/21] hw/9pfs/xen-9p-backend: Validate the request header size field David Woodhouse
` (6 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
xen_9pfs_out_sg() re-read the consumer index from the shared ring page
when building the request iovecs, so with an index the validation in
xen_9pfs_receive() never saw, the iovecs can reach past the end of the
ring mapping. Reconstruct the index from the out_cons/out_size snapshot
taken at validation time, and split the iovecs purely against the ring
size.
Fixes: CVE-2026-123072
Fixes: 40a2389207fb ("xen/9pfs: implement in/out_iov_from_pdu and vmarshal/vunmarshal")
Reported-by: Hui Peng <benquike@gmail.com>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4523
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/9pfs/xen-9p-backend.c | 43 ++++++++++++++++++----------------------
1 file changed, 19 insertions(+), 24 deletions(-)
diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c
index 06709d54084..22b2190b1b6 100644
--- a/hw/9pfs/xen-9p-backend.c
+++ b/hw/9pfs/xen-9p-backend.c
@@ -105,34 +105,29 @@ static void xen_9pfs_out_sg(Xen9pfsRing *ring,
int *num,
uint32_t idx)
{
- RING_IDX cons, prod, masked_prod, masked_cons;
-
- cons = ring->intf->out_cons;
- prod = ring->intf->out_prod;
- xen_rmb();
- masked_prod = xen_9pfs_mask(prod, XEN_FLEX_RING_SIZE(ring->ring_order));
- masked_cons = xen_9pfs_mask(cons, XEN_FLEX_RING_SIZE(ring->ring_order));
-
- if (masked_cons < masked_prod) {
+ RING_IDX cons, masked_cons;
+ RING_IDX ring_size = XEN_FLEX_RING_SIZE(ring->ring_order);
+
+ /*
+ * Use the consumer index and request size snapshotted when the
+ * request was validated in xen_9pfs_receive(). Do not re-read the
+ * index from the shared page: the guest may have changed it since
+ * validation, and out_size (bounded by the ring size at validation
+ * time) could then reach past the end of the ring mapping.
+ */
+ cons = ring->out_cons - ring->out_size;
+ masked_cons = xen_9pfs_mask(cons, ring_size);
+
+ if (ring->out_size <= ring_size - masked_cons) {
out_sg[0].iov_base = ring->ring.out + masked_cons;
out_sg[0].iov_len = ring->out_size;
*num = 1;
} else {
- if (ring->out_size >
- (XEN_FLEX_RING_SIZE(ring->ring_order) - masked_cons)) {
- out_sg[0].iov_base = ring->ring.out + masked_cons;
- out_sg[0].iov_len = XEN_FLEX_RING_SIZE(ring->ring_order) -
- masked_cons;
- out_sg[1].iov_base = ring->ring.out;
- out_sg[1].iov_len = ring->out_size -
- (XEN_FLEX_RING_SIZE(ring->ring_order) -
- masked_cons);
- *num = 2;
- } else {
- out_sg[0].iov_base = ring->ring.out + masked_cons;
- out_sg[0].iov_len = ring->out_size;
- *num = 1;
- }
+ out_sg[0].iov_base = ring->ring.out + masked_cons;
+ out_sg[0].iov_len = ring_size - masked_cons;
+ out_sg[1].iov_base = ring->ring.out;
+ out_sg[1].iov_len = ring->out_size - (ring_size - masked_cons);
+ *num = 2;
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 14/21] hw/9pfs/xen-9p-backend: Use validated snapshot for request iovecs
2026-11-24 23:22 ` [PATCH v1 14/21] hw/9pfs/xen-9p-backend: Use validated snapshot for request iovecs David Woodhouse
@ 2026-11-25 11:26 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:26 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> xen_9pfs_out_sg() re-read the consumer index from the shared ring page
> when building the request iovecs, so with an index the validation in
> xen_9pfs_receive() never saw, the iovecs can reach past the end of the
> ring mapping. Reconstruct the index from the out_cons/out_size snapshot
> taken at validation time, and split the iovecs purely against the ring
> size.
>
> Fixes: CVE-2026-123072
> Fixes: 40a2389207fb ("xen/9pfs: implement in/out_iov_from_pdu and vmarshal/vunmarshal")
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4523
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/9pfs/xen-9p-backend.c | 43 ++++++++++++++++++----------------------
> 1 file changed, 19 insertions(+), 24 deletions(-)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 15/21] hw/9pfs/xen-9p-backend: Validate the request header size field
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (13 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 14/21] hw/9pfs/xen-9p-backend: Use validated snapshot for request iovecs David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:27 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 16/21] hw/9pfs/xen-9p-backend: Validate frontend-supplied connect parameters David Woodhouse
` (5 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
A request whose header declares a size smaller than the header itself
was accepted, submitting a zero-length PDU and advancing nothing, to be
re-processed on every ring kick. Reject it instead. Set inprogress only
once a request is accepted, so returning early on a half-arrived or
malformed request no longer wedges the ring until disconnect.
Fixes: 40a2389207fb ("xen/9pfs: implement in/out_iov_from_pdu and vmarshal/vunmarshal")
Reported-by: Hui Peng <benquike@gmail.com>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4523
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/9pfs/xen-9p-backend.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c
index 22b2190b1b6..430de23fadb 100644
--- a/hw/9pfs/xen-9p-backend.c
+++ b/hw/9pfs/xen-9p-backend.c
@@ -314,7 +314,6 @@ static int xen_9pfs_receive(Xen9pfsRing *ring)
if (queued < sizeof(h)) {
return 0;
}
- ring->inprogress = true;
masked_prod = xen_9pfs_mask(prod, XEN_FLEX_RING_SIZE(ring->ring_order));
masked_cons = xen_9pfs_mask(cons, XEN_FLEX_RING_SIZE(ring->ring_order));
@@ -322,9 +321,18 @@ static int xen_9pfs_receive(Xen9pfsRing *ring)
xen_9pfs_read_packet((uint8_t *) &h, ring->ring.out, sizeof(h),
masked_prod, &masked_cons,
XEN_FLEX_RING_SIZE(ring->ring_order));
- if (queued < le32_to_cpu(h.size_le)) {
+ /*
+ * A size smaller than the header itself is malformed; returning
+ * with inprogress still clear means it is simply ignored until the
+ * guest fixes up the ring contents. Do not set inprogress before
+ * the request is accepted, or a half-arrived request would wedge
+ * the ring forever.
+ */
+ if (le32_to_cpu(h.size_le) < sizeof(h) ||
+ queued < le32_to_cpu(h.size_le)) {
return 0;
}
+ ring->inprogress = true;
/* cannot fail, because we only handle one request per ring at a time */
pdu = pdu_alloc(&ring->priv->state);
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 15/21] hw/9pfs/xen-9p-backend: Validate the request header size field
2026-11-24 23:22 ` [PATCH v1 15/21] hw/9pfs/xen-9p-backend: Validate the request header size field David Woodhouse
@ 2026-11-25 11:27 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:27 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> A request whose header declares a size smaller than the header itself
> was accepted, submitting a zero-length PDU and advancing nothing, to be
> re-processed on every ring kick. Reject it instead. Set inprogress only
> once a request is accepted, so returning early on a half-arrived or
> malformed request no longer wedges the ring until disconnect.
>
> Fixes: 40a2389207fb ("xen/9pfs: implement in/out_iov_from_pdu and vmarshal/vunmarshal")
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4523
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/9pfs/xen-9p-backend.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 16/21] hw/9pfs/xen-9p-backend: Validate frontend-supplied connect parameters
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (14 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 15/21] hw/9pfs/xen-9p-backend: Validate the request header size field David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:29 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 17/21] hw/9pfs/xen-9p-backend: Close event channel handle on disconnect David Woodhouse
` (4 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
The ring order is read from the guest-shared interface page into a
signed int, so a large value became negative and bypassed the
MAX_RING_ORDER check, leading to an undefined shift. Keep it unsigned.
Treat any negative return from the event channel bind as failure, not
just -1, and fail the connect if the frontend provides no 'tag' key
rather than passing NULL into the fsdev layer.
Fixes: b37eeb020123 ("xen/9pfs: introduce Xen 9pfs backend")
Reported-by: Hui Peng <benquike@gmail.com>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4523
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/9pfs/xen-9p-backend.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c
index 430de23fadb..6e26a445a09 100644
--- a/hw/9pfs/xen-9p-backend.c
+++ b/hw/9pfs/xen-9p-backend.c
@@ -453,7 +453,7 @@ static int xen_9pfs_connect(struct XenLegacyDevice *xendev)
xen_9pdev->rings = g_new0(Xen9pfsRing, xen_9pdev->num_rings);
for (i = 0; i < xen_9pdev->num_rings; i++) {
char *str;
- int ring_order;
+ uint32_t ring_order;
xen_9pdev->rings[i].priv = xen_9pdev;
xen_9pdev->rings[i].evtchn = -1;
@@ -515,7 +515,7 @@ static int xen_9pfs_connect(struct XenLegacyDevice *xendev)
(xen_9pdev->rings[i].evtchndev,
xendev->dom,
xen_9pdev->rings[i].evtchn);
- if (xen_9pdev->rings[i].local_port == -1) {
+ if (xen_9pdev->rings[i].local_port < 0) {
xen_pv_printf(xendev, 0,
"xenevtchn_bind_interdomain failed port=%d\n",
xen_9pdev->rings[i].evtchn);
@@ -531,6 +531,9 @@ static int xen_9pfs_connect(struct XenLegacyDevice *xendev)
xen_9pdev->id = s->fsconf.fsdev_id =
g_strdup_printf("xen9p%d", xendev->dev);
xen_9pdev->tag = s->fsconf.tag = xenstore_read_fe_str(xendev, "tag");
+ if (!xen_9pdev->tag) {
+ goto out;
+ }
fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
s->fsconf.tag,
1, NULL);
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 16/21] hw/9pfs/xen-9p-backend: Validate frontend-supplied connect parameters
2026-11-24 23:22 ` [PATCH v1 16/21] hw/9pfs/xen-9p-backend: Validate frontend-supplied connect parameters David Woodhouse
@ 2026-11-25 11:29 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:29 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> The ring order is read from the guest-shared interface page into a
> signed int, so a large value became negative and bypassed the
> MAX_RING_ORDER check, leading to an undefined shift. Keep it unsigned.
> Treat any negative return from the event channel bind as failure, not
> just -1, and fail the connect if the frontend provides no 'tag' key
> rather than passing NULL into the fsdev layer.
>
> Fixes: b37eeb020123 ("xen/9pfs: introduce Xen 9pfs backend")
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4523
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/9pfs/xen-9p-backend.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 17/21] hw/9pfs/xen-9p-backend: Close event channel handle on disconnect
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (15 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 16/21] hw/9pfs/xen-9p-backend: Validate frontend-supplied connect parameters David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:30 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 18/21] hw/net/xen_nic: Bound the TX and RX rings' producer index David Woodhouse
` (3 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
Disconnect only unbound the port, then dropped the pointer, leaking the
handle and its file descriptor on every disconnect/reconnect cycle.
Close the handle; closing also unbinds.
Fixes: b37eeb020123 ("xen/9pfs: introduce Xen 9pfs backend")
Reported-by: Hui Peng <benquike@gmail.com>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4523
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/9pfs/xen-9p-backend.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c
index 6e26a445a09..612f19c45c8 100644
--- a/hw/9pfs/xen-9p-backend.c
+++ b/hw/9pfs/xen-9p-backend.c
@@ -392,8 +392,7 @@ static void xen_9pfs_disconnect(struct XenLegacyDevice *xendev)
if (xen_9pdev->rings[i].evtchndev != NULL) {
qemu_set_fd_handler(qemu_xen_evtchn_fd(xen_9pdev->rings[i].evtchndev),
NULL, NULL, NULL);
- qemu_xen_evtchn_unbind(xen_9pdev->rings[i].evtchndev,
- xen_9pdev->rings[i].local_port);
+ qemu_xen_evtchn_close(xen_9pdev->rings[i].evtchndev);
xen_9pdev->rings[i].evtchndev = NULL;
}
if (xen_9pdev->rings[i].data != NULL) {
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 17/21] hw/9pfs/xen-9p-backend: Close event channel handle on disconnect
2026-11-24 23:22 ` [PATCH v1 17/21] hw/9pfs/xen-9p-backend: Close event channel handle on disconnect David Woodhouse
@ 2026-11-25 11:30 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:30 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> Disconnect only unbound the port, then dropped the pointer, leaking the
> handle and its file descriptor on every disconnect/reconnect cycle.
> Close the handle; closing also unbinds.
>
> Fixes: b37eeb020123 ("xen/9pfs: introduce Xen 9pfs backend")
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4523
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/9pfs/xen-9p-backend.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 18/21] hw/net/xen_nic: Bound the TX and RX rings' producer index
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (16 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 17/21] hw/9pfs/xen-9p-backend: Close event channel handle on disconnect David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:32 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 19/21] hw/xen: Bound the rep count of PIO and MMIO ioreqs David Woodhouse
` (2 subsequent siblings)
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
net_tx_packets() consumed requests until req_cons caught up with the
raw req_prod from the shared ring. A bogus req_prod made the loop
process up to 2^32 stale slots while holding the BQL. Check
RING_REQUEST_PROD_OVERFLOW on both rings, as xen-block already does.
Fixes: e613b064a88a ("xen: add net backend driver.")
Reported-by: Hui Peng <benquike@gmail.com>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4515
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/net/xen_nic.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c
index e615303da6a..4de2464376f 100644
--- a/hw/net/xen_nic.c
+++ b/hw/net/xen_nic.c
@@ -138,6 +138,12 @@ static bool net_tx_packets(struct XenNetDev *netdev)
rp = netdev->tx_ring.sring->req_prod;
xen_rmb(); /* Ensure we see queued requests up to 'rp'. */
+ if (RING_REQUEST_PROD_OVERFLOW(&netdev->tx_ring, rp)) {
+ qemu_log_mask(LOG_GUEST_ERROR, "vif%u: bad req_prod %u\n",
+ netdev->dev, rp);
+ break;
+ }
+
while ((rc != rp)) {
if (RING_REQUEST_CONS_OVERFLOW(&netdev->tx_ring, rc)) {
break;
@@ -268,7 +274,8 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t size
rp = netdev->rx_ring.sring->req_prod;
xen_rmb(); /* Ensure we see queued requests up to 'rp'. */
- if (rc == rp || RING_REQUEST_CONS_OVERFLOW(&netdev->rx_ring, rc)) {
+ if (rc == rp || RING_REQUEST_PROD_OVERFLOW(&netdev->rx_ring, rp) ||
+ RING_REQUEST_CONS_OVERFLOW(&netdev->rx_ring, rc)) {
return 0;
}
if (size > XEN_PAGE_SIZE - NET_IP_ALIGN) {
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 18/21] hw/net/xen_nic: Bound the TX and RX rings' producer index
2026-11-24 23:22 ` [PATCH v1 18/21] hw/net/xen_nic: Bound the TX and RX rings' producer index David Woodhouse
@ 2026-11-25 11:32 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:32 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> net_tx_packets() consumed requests until req_cons caught up with the
> raw req_prod from the shared ring. A bogus req_prod made the loop
> process up to 2^32 stale slots while holding the BQL. Check
> RING_REQUEST_PROD_OVERFLOW on both rings, as xen-block already does.
>
> Fixes: e613b064a88a ("xen: add net backend driver.")
> Reported-by: Hui Peng <benquike@gmail.com>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4515
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/net/xen_nic.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 19/21] hw/xen: Bound the rep count of PIO and MMIO ioreqs
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (17 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 18/21] hw/net/xen_nic: Bound the TX and RX rings' producer index David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:34 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 20/21] hw/i386/kvm/xen_evtchn: Hold port_lock for whole of bind_pirq_op David Woodhouse
2026-11-24 23:22 ` [PATCH v1 21/21] hw/i386/kvm/xen_evtchn: Allow unmapping an emulated MSI PIRQ David Woodhouse
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
cpu_ioreq_pio() and cpu_ioreq_move() iterated req->count times with no
upper bound, so a count of UINT32_MAX kept the vCPU handler thread
spinning through four billion iterations. Xen's instruction emulator
clips a rep batch to at most 4096 repetitions (hvmemul_virtual_to_linear()
and hvmemul_linear_to_phys() both apply that bound before an ioreq is
sent), so reject larger counts as malformed, and reject a zero size, as
the other framing checks here already do.
Fixes: 9ce94e7c8a99 ("xen: Initialize event channels and io rings")
Reported-by: Feifan Qian <bea1e@proton.me>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/3756
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/xen/xen-hvm-common.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c
index 62d88804c43..48ce655448b 100644
--- a/hw/xen/xen-hvm-common.c
+++ b/hw/xen/xen-hvm-common.c
@@ -321,10 +321,20 @@ void cpu_ioreq_pio(ioreq_t *req)
trace_cpu_ioreq_pio(req, req->dir, req->df, req->data_is_ptr, req->addr,
req->data, req->count, req->size);
- if (req->size > sizeof(uint32_t)) {
+ if (req->size == 0 || req->size > sizeof(uint32_t)) {
hw_error("PIO: bad size (%u)", req->size);
}
+ /*
+ * Xen's instruction emulator clips a rep batch to at most 4096
+ * repetitions (hvmemul_virtual_to_linear(), hvmemul_linear_to_phys()),
+ * so the count of a well-formed ioreq is bounded. Don't spin for
+ * 2^32 iterations on a corrupted one.
+ */
+ if (req->data_is_ptr && req->count > 4096) {
+ hw_error("PIO: bad count (%u)", req->count);
+ }
+
if (req->dir == IOREQ_READ) {
if (!req->data_is_ptr) {
req->data = do_inp(req->addr, req->size);
@@ -361,10 +371,15 @@ static void cpu_ioreq_move(ioreq_t *req)
trace_cpu_ioreq_move(req, req->dir, req->df, req->data_is_ptr, req->addr,
req->data, req->count, req->size);
- if (req->size > sizeof(req->data)) {
+ if (req->size == 0 || req->size > sizeof(req->data)) {
hw_error("MMIO: bad size (%u)", req->size);
}
+ /* As for PIO: Xen clips a rep batch to at most 4096 repetitions. */
+ if (req->count > 4096) {
+ hw_error("MMIO: bad count (%u)", req->count);
+ }
+
if (!req->data_is_ptr) {
if (req->dir == IOREQ_READ) {
for (i = 0; i < req->count; i++) {
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 19/21] hw/xen: Bound the rep count of PIO and MMIO ioreqs
2026-11-24 23:22 ` [PATCH v1 19/21] hw/xen: Bound the rep count of PIO and MMIO ioreqs David Woodhouse
@ 2026-11-25 11:34 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:34 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> cpu_ioreq_pio() and cpu_ioreq_move() iterated req->count times with no
> upper bound, so a count of UINT32_MAX kept the vCPU handler thread
> spinning through four billion iterations. Xen's instruction emulator
> clips a rep batch to at most 4096 repetitions (hvmemul_virtual_to_linear()
> and hvmemul_linear_to_phys() both apply that bound before an ioreq is
> sent), so reject larger counts as malformed, and reject a zero size, as
> the other framing checks here already do.
>
> Fixes: 9ce94e7c8a99 ("xen: Initialize event channels and io rings")
> Reported-by: Feifan Qian <bea1e@proton.me>
> Closes: https://gitlab.com/qemu-project/qemu/-/work_items/3756
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/xen/xen-hvm-common.c | 19 +++++++++++++++++--
> 1 file changed, 17 insertions(+), 2 deletions(-)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 20/21] hw/i386/kvm/xen_evtchn: Hold port_lock for whole of bind_pirq_op
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (18 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 19/21] hw/xen: Bound the rep count of PIO and MMIO ioreqs David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:35 ` Paul Durrant
2026-11-24 23:22 ` [PATCH v1 21/21] hw/i386/kvm/xen_evtchn: Allow unmapping an emulated MSI PIRQ David Woodhouse
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
The check for an existing binding read s->pirq[].port before taking
port_lock, and the allocation wrote it after. The BQL serialises the
writers in practice, but holding port_lock across the check and the
allocation is clearly correct and lets Coverity see it too.
The region now under the lock is pure port_table/pirq bookkeeping.
The MSI unmask and kvm_update_msi_routes_all() calls must remain
outside port_lock: they can re-enter via the MSI translate function,
which takes port_lock itself. The PIRQ→evtchn→GSI delivery paths have
further BQL/port_lock ordering constraints — see the comments in
xen_evtchn_set_callback_level() and xen_evtchn_set_gsi().
Resolves: Coverity CID 1527403
Fixes: 6096cf7877bc ("hw/xen: Support MSI mapping to PIRQ")
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/i386/kvm/xen_evtchn.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
index e2803cad0a8..cfe735219bf 100644
--- a/hw/i386/kvm/xen_evtchn.c
+++ b/hw/i386/kvm/xen_evtchn.c
@@ -1289,24 +1289,21 @@ int xen_evtchn_bind_pirq_op(struct evtchn_bind_pirq *pirq)
BQL_LOCK_GUARD();
- if (s->pirq[pirq->pirq].port) {
- return -EBUSY;
- }
+ WITH_QEMU_LOCK_GUARD(&s->port_lock) {
+ if (s->pirq[pirq->pirq].port) {
+ return -EBUSY;
+ }
- qemu_mutex_lock(&s->port_lock);
+ ret = allocate_port(s, 0, EVTCHNSTAT_pirq, pirq->pirq,
+ &pirq->port);
+ if (ret) {
+ return ret;
+ }
- ret = allocate_port(s, 0, EVTCHNSTAT_pirq, pirq->pirq,
- &pirq->port);
- if (ret) {
- qemu_mutex_unlock(&s->port_lock);
- return ret;
+ s->pirq[pirq->pirq].port = pirq->port;
+ trace_kvm_xen_bind_pirq(pirq->pirq, pirq->port);
}
- s->pirq[pirq->pirq].port = pirq->port;
- trace_kvm_xen_bind_pirq(pirq->pirq, pirq->port);
-
- qemu_mutex_unlock(&s->port_lock);
-
/*
* Need to do the unmask outside port_lock because it may call
* back into the MSI translate function.
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 20/21] hw/i386/kvm/xen_evtchn: Hold port_lock for whole of bind_pirq_op
2026-11-24 23:22 ` [PATCH v1 20/21] hw/i386/kvm/xen_evtchn: Hold port_lock for whole of bind_pirq_op David Woodhouse
@ 2026-11-25 11:35 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:35 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> The check for an existing binding read s->pirq[].port before taking
> port_lock, and the allocation wrote it after. The BQL serialises the
> writers in practice, but holding port_lock across the check and the
> allocation is clearly correct and lets Coverity see it too.
>
> The region now under the lock is pure port_table/pirq bookkeeping.
> The MSI unmask and kvm_update_msi_routes_all() calls must remain
> outside port_lock: they can re-enter via the MSI translate function,
> which takes port_lock itself. The PIRQ→evtchn→GSI delivery paths have
> further BQL/port_lock ordering constraints — see the comments in
> xen_evtchn_set_callback_level() and xen_evtchn_set_gsi().
>
> Resolves: Coverity CID 1527403
> Fixes: 6096cf7877bc ("hw/xen: Support MSI mapping to PIRQ")
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/i386/kvm/xen_evtchn.c | 25 +++++++++++--------------
> 1 file changed, 11 insertions(+), 14 deletions(-)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread
* [PATCH v1 21/21] hw/i386/kvm/xen_evtchn: Allow unmapping an emulated MSI PIRQ
2026-11-24 23:22 [PATCH v1 00/21] hw/xen, i386/xen: security and robustness fixes David Woodhouse
` (19 preceding siblings ...)
2026-11-24 23:22 ` [PATCH v1 20/21] hw/i386/kvm/xen_evtchn: Hold port_lock for whole of bind_pirq_op David Woodhouse
@ 2026-11-24 23:22 ` David Woodhouse
2026-11-25 11:36 ` Paul Durrant
20 siblings, 1 reply; 51+ messages in thread
From: David Woodhouse @ 2026-11-24 23:22 UTC (permalink / raw)
To: qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Paul Durrant,
Stefano Stabellini, Anthony PERARD, Edgar E . Iglesias,
Michael S . Tsirkin, Richard Henderson, Marcelo Tosatti,
Marc-André Lureau, Jason Wang, Hui Peng, Mark Syms,
Feifan Qian, David Woodhouse
From: David Woodhouse <dwmw@amazon.co.uk>
The "unmap GSI PIRQs only" check rejected every negative gsi, which
includes IRQ_MSI_EMU, so the later IRQ_MSI_EMU branch that flushes the
KVM MSI routes was unreachable and guests could never unmap an MSI
PIRQ. Xen permits it: physdev_unmap_pirq() on a domain with HVM pirqs
routes emulated-IRQ pirqs through unmap_domain_pirq_emuirq(), which
succeeds for MSI emuirqs. Let IRQ_MSI_EMU through; the existing
unreachable branch then does the route flush as originally intended.
Resolves: Coverity CID 1507603
Fixes: 6096cf7877bc ("hw/xen: Support MSI mapping to PIRQ")
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
hw/i386/kvm/xen_evtchn.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/hw/i386/kvm/xen_evtchn.c b/hw/i386/kvm/xen_evtchn.c
index cfe735219bf..5a986c1e2a4 100644
--- a/hw/i386/kvm/xen_evtchn.c
+++ b/hw/i386/kvm/xen_evtchn.c
@@ -1925,13 +1925,15 @@ int xen_physdev_unmap_pirq(struct physdev_unmap_pirq *unmap)
gsi = s->pirq[pirq].gsi;
- /* We can only unmap GSI PIRQs */
- if (gsi < 0) {
+ /* We can only unmap GSI PIRQs and emulated MSIs */
+ if (gsi < 0 && gsi != IRQ_MSI_EMU) {
qemu_mutex_unlock(&s->port_lock);
return -EINVAL;
}
- s->gsi_pirq[gsi] = 0;
+ if (gsi >= 0) {
+ s->gsi_pirq[gsi] = 0;
+ }
s->pirq[pirq].gsi = IRQ_UNBOUND; /* Doesn't actually matter because: */
pirq_inuse_word(s, pirq) &= ~pirq_inuse_bit(pirq);
--
2.43.0
^ permalink raw reply related [flat|nested] 51+ messages in thread* Re: [PATCH v1 21/21] hw/i386/kvm/xen_evtchn: Allow unmapping an emulated MSI PIRQ
2026-11-24 23:22 ` [PATCH v1 21/21] hw/i386/kvm/xen_evtchn: Allow unmapping an emulated MSI PIRQ David Woodhouse
@ 2026-11-25 11:36 ` Paul Durrant
0 siblings, 0 replies; 51+ messages in thread
From: Paul Durrant @ 2026-11-25 11:36 UTC (permalink / raw)
To: David Woodhouse, qemu-devel
Cc: xen-devel, kvm, Paolo Bonzini, Peter Maydell, Stefano Stabellini,
Anthony PERARD, Edgar E . Iglesias, Michael S . Tsirkin,
Richard Henderson, Marcelo Tosatti, Marc-André Lureau,
Jason Wang, Hui Peng, Mark Syms, Feifan Qian, David Woodhouse
On 24/11/2026 16:22, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
>
> The "unmap GSI PIRQs only" check rejected every negative gsi, which
> includes IRQ_MSI_EMU, so the later IRQ_MSI_EMU branch that flushes the
> KVM MSI routes was unreachable and guests could never unmap an MSI
> PIRQ. Xen permits it: physdev_unmap_pirq() on a domain with HVM pirqs
> routes emulated-IRQ pirqs through unmap_domain_pirq_emuirq(), which
> succeeds for MSI emuirqs. Let IRQ_MSI_EMU through; the existing
> unreachable branch then does the route flush as originally intended.
>
> Resolves: Coverity CID 1507603
> Fixes: 6096cf7877bc ("hw/xen: Support MSI mapping to PIRQ")
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
> hw/i386/kvm/xen_evtchn.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
Reviewed-by: Paul Durrant <paul@xen.org>
^ permalink raw reply [flat|nested] 51+ messages in thread