The descriptor chains length must be greater than the Virtio-net
header size. Otherwise, such descriptor chains sizes implies no
packet data.

Fixes: fe8477ebbd94 ("vhost: support async packed ring dequeue")
Cc: sta...@dpdk.org

Signed-off-by: Yunjian Wang <wangyunj...@huawei.com>
---
 lib/vhost/virtio_net.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index 69901ab3b5..8fc9bfa056 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -3962,6 +3962,16 @@ virtio_dev_tx_async_single_packed(struct virtio_net *dev,
                                         VHOST_ACCESS_RO) < 0))
                return -1;
 
+       if (unlikely(buf_len <= dev->vhost_hlen)) {
+               if (!allocerr_warned) {
+                       VHOST_DATA_LOG(dev->ifname, ERR, "Invalid buffer 
length.");
+                       allocerr_warned = true;
+               }
+               return -1;
+       }
+
+       buf_len -= dev->vhost_hlen;
+
        if (unlikely(virtio_dev_pktmbuf_prep(dev, pkts, buf_len))) {
                if (!allocerr_warned) {
                        VHOST_DATA_LOG(dev->ifname, ERR, "Failed mbuf alloc of 
size %d from %s.",
-- 
2.33.0

Reply via email to