[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PULL 14/21] hw/9pfs/xen-9p-backend: Use validated snapshot for request iovecs



From: David Woodhouse <dwmw@xxxxxxxxxxxx>

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@xxxxxxxxx>
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4523
Reviewed-by: Paul Durrant <paul@xxxxxxx>
Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx>
---
 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 06709d5408..22b2190b1b 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.55.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.