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

[PATCH v1 18/21] hw/net/xen_nic: Bound the TX and RX rings' producer index



From: David Woodhouse <dwmw@xxxxxxxxxxxx>

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@xxxxxxxxx>
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4515
Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx>
---
 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




 


Rackspace

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