patch 'net/vhost: fix access to freed memory' has been queued to stable release 20.11.6

Xueming Li xuemingl at nvidia.com
Tue Jun 21 10:01:33 CEST 2022


Hi,

FYI, your patch has been queued to stable release 20.11.6

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 06/23/22. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://github.com/steevenlee/dpdk

This queued commit can be viewed at:
https://github.com/steevenlee/dpdk/commit/e4729f10d06291d8ab915e316bea1f0330ee656e

Thanks.

Xueming Li <xuemingl at nvidia.com>

---
>From e4729f10d06291d8ab915e316bea1f0330ee656e Mon Sep 17 00:00:00 2001
From: Yuan Wang <yuanx.wang at intel.com>
Date: Sat, 12 Mar 2022 00:35:12 +0800
Subject: [PATCH] net/vhost: fix access to freed memory
Cc: Xueming Li <xuemingl at nvidia.com>

[ upstream commit 9dc6bb06824f3c5887f0436ddba5ab9116cb277e ]

This patch fixes heap-use-after-free reported by ASan.

It is possible for the rte_vhost_dequeue_burst() to access the vq
is freed when numa_realloc() gets called in the device running state.
The control plane will set the vq->access_lock to protected the vq
from the data plane. Unfortunately the lock will fail at the moment
the vq is freed, allowing the rte_vhost_dequeue_burst() to access
the fields of the vq, which will trigger a heap-use-after-free error.

In the case of multiple queues, the vhost pmd can access other queues
that are not ready when the first queue is ready, which makes no sense
and also allows numa_realloc() and rte_vhost_dequeue_burst() access to
vq to happen at the same time. By controlling vq->allow_queuing we can make
the pmd access only the queues that are ready.

Fixes: 1ce3c7fe149 ("net/vhost: emulate device start/stop behavior")

Signed-off-by: Yuan Wang <yuanx.wang at intel.com>
Tested-by: Wei Ling <weix.ling at intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin at redhat.com>
---
 drivers/net/vhost/rte_eth_vhost.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 5845bb15f3..0778dfbd13 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -719,6 +719,7 @@ update_queuing_status(struct rte_eth_dev *dev)
 {
 	struct pmd_internal *internal = dev->data->dev_private;
 	struct vhost_queue *vq;
+	struct rte_vhost_vring_state *state;
 	unsigned int i;
 	int allow_queuing = 1;
 
@@ -729,12 +730,17 @@ update_queuing_status(struct rte_eth_dev *dev)
 	    rte_atomic32_read(&internal->dev_attached) == 0)
 		allow_queuing = 0;
 
+	state = vring_states[dev->data->port_id];
+
 	/* Wait until rx/tx_pkt_burst stops accessing vhost device */
 	for (i = 0; i < dev->data->nb_rx_queues; i++) {
 		vq = dev->data->rx_queues[i];
 		if (vq == NULL)
 			continue;
-		rte_atomic32_set(&vq->allow_queuing, allow_queuing);
+		if (allow_queuing && state->cur[vq->virtqueue_id])
+			rte_atomic32_set(&vq->allow_queuing, 1);
+		else
+			rte_atomic32_set(&vq->allow_queuing, 0);
 		while (rte_atomic32_read(&vq->while_queuing))
 			rte_pause();
 	}
@@ -743,7 +749,10 @@ update_queuing_status(struct rte_eth_dev *dev)
 		vq = dev->data->tx_queues[i];
 		if (vq == NULL)
 			continue;
-		rte_atomic32_set(&vq->allow_queuing, allow_queuing);
+		if (allow_queuing && state->cur[vq->virtqueue_id])
+			rte_atomic32_set(&vq->allow_queuing, 1);
+		else
+			rte_atomic32_set(&vq->allow_queuing, 0);
 		while (rte_atomic32_read(&vq->while_queuing))
 			rte_pause();
 	}
@@ -963,6 +972,8 @@ vring_state_changed(int vid, uint16_t vring, int enable)
 	state->max_vring = RTE_MAX(vring, state->max_vring);
 	rte_spinlock_unlock(&state->lock);
 
+	update_queuing_status(eth_dev);
+
 	VHOST_LOG(INFO, "vring%u is %s\n",
 			vring, enable ? "enabled" : "disabled");
 
-- 
2.35.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2022-06-21 15:37:50.567724958 +0800
+++ 0027-net-vhost-fix-access-to-freed-memory.patch	2022-06-21 15:37:49.004451134 +0800
@@ -1 +1 @@
-From 9dc6bb06824f3c5887f0436ddba5ab9116cb277e Mon Sep 17 00:00:00 2001
+From e4729f10d06291d8ab915e316bea1f0330ee656e Mon Sep 17 00:00:00 2001
@@ -4,0 +5,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit 9dc6bb06824f3c5887f0436ddba5ab9116cb277e ]
@@ -31 +34 @@
-index 070f0e6dfd..8a6595504a 100644
+index 5845bb15f3..0778dfbd13 100644
@@ -34 +37 @@
-@@ -720,6 +720,7 @@ update_queuing_status(struct rte_eth_dev *dev)
+@@ -719,6 +719,7 @@ update_queuing_status(struct rte_eth_dev *dev)
@@ -42 +45 @@
-@@ -730,12 +731,17 @@ update_queuing_status(struct rte_eth_dev *dev)
+@@ -729,12 +730,17 @@ update_queuing_status(struct rte_eth_dev *dev)
@@ -61 +64 @@
-@@ -744,7 +750,10 @@ update_queuing_status(struct rte_eth_dev *dev)
+@@ -743,7 +749,10 @@ update_queuing_status(struct rte_eth_dev *dev)
@@ -73 +76 @@
-@@ -967,6 +976,8 @@ vring_state_changed(int vid, uint16_t vring, int enable)
+@@ -963,6 +972,8 @@ vring_state_changed(int vid, uint16_t vring, int enable)


More information about the stable mailing list