examples/vhost: fix use-after-free on drain vhost
PATCH 1/1 examples/vhost: fix use-after-free on drain vhost
When a vdev is removed in destroy_device function, the corresponding vhost_txbuff[vdev->vid] will also be free, but the vhost_txbuff[vdev->vid] may still be used in the drain_vhost function, which will cause an error of heap-use-after-free. Therefore, before accessing vhost_txbuff[vdev->vid], we need to check whether the vdev has been removed, if so, let's skip this vdev.
--- examples/vhost/main.c | 3 +++ 1 file changed, 3 insertions(+)
examples/vhost/main.c +3 -0
@@ -916,6 +916,9 @@ drain_vhost_table(void)uint64_t cur_tsc; TAILQ_FOREACH(vdev, &vhost_dev_list, global_vdev_entry) { +if (unlikely (vdev->remove ==1 )) +continue ; + vhost_txq = vhost_txbuff[lcore_id *MAX_VHOST_DEVICE + vdev->vid];
Signature · 1 line
2.25.1
Hi Wenwu,
Quoted 9 lines
-----Original Message-----
From: Ma, WenwuX <[email protected]>
Sent: Friday, September 24, 2021 4:30 AM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Hu, Jiayu <[email protected]>; Yang, YvonneX <[email protected]>; Ma, WenwuX <[email protected]>
Subject: [PATCH] examples/vhost: fix use-after-free on drain vhost
Quoted 3 lines
When a vdev is removed in
destroy_devicefunction, the corresponding vhost_txbuff[vdev->vid] will also be free, but the vhost_txbuff[vdev->vid] may still
Free -> freed
vhost_txbuff[vdev->vid] -> vhost TX buffer
Quoted 5 lines
be used in the
drain_vhostfunction, which will cause an error of heap-use-after-free. Therefore, before accessing vhost_txbuff[vdev->vid], we need to check whether the vdev has been removed, if so, let's skip this vdev.
This is a bug fix. Please add fix and cc-stable tag.
Thanks,
Chenbo
Quoted 22 lines
Signed-off-by Wenwu Ma <[email protected]>--- examples/vhost/main.c | 3 +++ 1 file changed, 3 insertions(+)examples/vhost/main.c +3
-1@@ -916,6 +916,9 @@ drain_vhost_table(void)uint64_t cur_tsc; TAILQ_FOREACH(vdev, &vhost_dev_list, global_vdev_entry) { +if (unlikely (vdev->remove ==1 )) +continue ; + vhost_txq = vhost_txbuff[lcore_id *MAX_VHOST_DEVICE + vdev->vid]; --2.25.1
PATCH v2 1/1 examples/vhost: fix use-after-free on drain vhost
In reply to Wenwu MaWhen a vdev is removed in destroy_device function, the corresponding vhost TX buffer will also be freed, but the vhost TX buffer may still be used in the drain_vhost function, which will cause an error of heap-use-after-free. Therefore, before accessing vhost TX buffer, we need to check whether the vdev has been removed, if so, let's skip this vdev.
--- examples/vhost/main.c | 3 +++ 1 file changed, 3 insertions(+)
examples/vhost/main.c +3 -0
@@ -916,6 +916,9 @@ drain_vhost_table(void)uint64_t cur_tsc; TAILQ_FOREACH(vdev, &vhost_dev_list, global_vdev_entry) { +if (unlikely (vdev->remove ==1 )) +continue ; + vhost_txq = vhost_txbuff[lcore_id *MAX_VHOST_DEVICE + vdev->vid];
Signature · 1 line
2.25.1
Quoted 17 lines
-----Original Message-----
From: Ma, WenwuX <[email protected]>
Sent: Saturday, September 25, 2021 1:23 AM
To: [email protected]
Cc: [email protected]; Xia, Chenbo <[email protected]>; Jiang, Cheng1 <[email protected]>; Hu, Jiayu <[email protected]>; Yang, YvonneX <[email protected]>; Ma, WenwuX <[email protected]>; [email protected]
Subject: [PATCH v2] examples/vhost: fix use-after-free on drain vhostWhen a vdev is removed in
destroy_devicefunction, the corresponding vhost TX buffer will also be freed, but the vhost TX buffer may still be used in thedrain_vhostfunction, which will cause an error of heap-use-after-free. Therefore, before accessing vhost TX buffer, we need to check whether the vdev has been removed, if so, let's skip this vdev.
Quoted 5 lines
Fixes a68ba8e0a6b6 ("examples/vhost: refactor vhost data path")Signed-off-by Wenwu Ma <[email protected]>---
Maxime Coquelin
AppliedQuoted 22 lines · Wenwu Ma
When a vdev is removed in
destroy_devicefunction, the corresponding vhost TX buffer will also be freed, but the vhost TX buffer may still be used in thedrain_vhostfunction, which will cause an error of heap-use-after-free. Therefore, before accessing vhost TX buffer, we need to check whether the vdev has been removed, if so, let's skip this vdev.Fixes a68ba8e0a6b6 ("examples/vhost: refactor vhost data path")Signed-off-by Wenwu Ma <[email protected]>--- examples/vhost/main.c | 3 +++ 1 file changed, 3 insertions(+)examples/vhost/main.c +0
-0
examples/vhost/main.c drain_vhost_table(void) · line 924
Quoted 9 lines
examples/vhost/main.c +3
-0@@ -916,6 +916,9 @@ drain_vhost_table(void)uint64_t cur_tsc; TAILQ_FOREACH(vdev, &vhost_dev_list, global_vdev_entry) { +if (unlikely (vdev->remove ==1 )) +continue ; + vhost_txq = vhost_txbuff[lcore_id *MAX_VHOST_DEVICE + vdev->vid];
Applied to dpdk-next-virtio/main.
Thanks,
Maxime