net/vhost: fix access to freed memory
authorYuan Wang <yuanx.wang@intel.com>
Fri, 11 Mar 2022 16:35:12 +0000 (00:35 +0800)
committerMaxime Coquelin <maxime.coquelin@redhat.com>
Mon, 9 May 2022 19:15:38 +0000 (21:15 +0200)
commit9dc6bb06824f3c5887f0436ddba5ab9116cb277e
tree9620be0a23bdab6e1420e385b57588e654e96567
parent666ff7763582bf2494e85b5175fc549ae89aa9fd
net/vhost: fix access to freed memory

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@intel.com>
Tested-by: Wei Ling <weix.ling@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
drivers/net/vhost/rte_eth_vhost.c