All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Vanda <avanda@ptsecurity.com>
To: Thomas Monjalon <thomas@monjalon.net>,
	Maxime Coquelin <maxime.coquelin@redhat.com>,
	Chenbo Xia <chenbox@nvidia.com>, Yuan Wang <yuanx.wang@intel.com>,
	Cheng Jiang <honest.jiang@foxmail.com>
Cc: <dev@dpdk.org>, <stable@dpdk.org>, <cheng1.jiang@intel.com>,
	Anton Vanda <avanda@ptsecurity.com>
Subject: [PATCH] vhost: fix null dereference in async packed dequeue
Date: Tue, 7 Jul 2026 16:50:44 +0300	[thread overview]
Message-ID: <20260707135044.7488-1-avanda@ptsecurity.com> (raw)

In the batch path of the asynchronous packed ring dequeue, the address
of the virtio net header is obtained from vhost_iova_to_vva(), which
returns 0 when a guest-provided descriptor address cannot be fully
translated.  The batch check only validates that the descriptor address
is non-zero and that the length is consistent. A malicious or buggy
guest could therefore trigger a NULL pointer dereference and crash the
vhost application (denial of service).

Check the translation result and leave the batch fast path with an error
on failure, so the single-packet path handles the invalid descriptor, as
is already done for the non-batch async dequeue path.

Perform the header translation before the DMA iovec setup so that the
early return cannot leave the async iterator state partially updated.

Fixes: c2fa52bf1e5d ("vhost: add batch dequeue in async vhost packed ring")
Cc: stable@dpdk.org

Signed-off-by: Anton Vanda <avanda@ptsecurity.com>
---
 .mailmap               |  1 +
 lib/vhost/virtio_net.c | 26 +++++++++++++++++---------
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/.mailmap b/.mailmap
index 05a55c0bd6..9215581a29 100644
--- a/.mailmap
+++ b/.mailmap
@@ -141,6 +141,7 @@ Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
 Anthony Fee <anthonyx.fee@intel.com>
 Anthony Harivel <aharivel@redhat.com>
 Antonio Fischetti <antonio.fischetti@intel.com>
+Anton Vanda <avanda@ptsecurity.com>
 Anup Prabhu <aprabhu@marvell.com>
 Anupam Kapoor <anupam.kapoor@gmail.com>
 Anurag Mandal <anurag.mandal@intel.com>
diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index 0658b81de5..6528c06ea4 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -4039,6 +4039,23 @@ virtio_dev_tx_async_packed_batch(struct virtio_net *dev,
 	vhost_for_each_try_unroll(i, 0, PACKED_BATCH_SIZE)
 		rte_prefetch0((void *)(uintptr_t)desc_addrs[i]);
 
+	if (virtio_net_with_host_offload(dev)) {
+		vhost_for_each_try_unroll(i, 0, PACKED_BATCH_SIZE) {
+			desc_vva = vhost_iova_to_vva(dev, vq, desc_addrs[i],
+						&lens[i], VHOST_ACCESS_RO);
+			/*
+			 * A malformed or unmapped guest descriptor makes the
+			 * IOVA translation fail (returns 0). Bail out of the
+			 * batch fast path so the single-packet path handles the
+			 * error, instead of dereferencing a NULL header.
+			 */
+			if (unlikely(!desc_vva))
+				return -1;
+			hdr = (struct virtio_net_hdr *)(uintptr_t)desc_vva;
+			pkts_info[slot_idx + i].nethdr = *hdr;
+		}
+	}
+
 	vhost_for_each_try_unroll(i, 0, PACKED_BATCH_SIZE) {
 		host_iova[i] = (void *)(uintptr_t)gpa_to_first_hpa(dev,
 			desc_addrs[i] + buf_offset, pkts[i]->pkt_len, &mapped_len[i]);
@@ -4053,15 +4070,6 @@ virtio_dev_tx_async_packed_batch(struct virtio_net *dev,
 		async->iter_idx++;
 	}
 
-	if (virtio_net_with_host_offload(dev)) {
-		vhost_for_each_try_unroll(i, 0, PACKED_BATCH_SIZE) {
-			desc_vva = vhost_iova_to_vva(dev, vq, desc_addrs[i],
-						&lens[i], VHOST_ACCESS_RO);
-			hdr = (struct virtio_net_hdr *)(uintptr_t)desc_vva;
-			pkts_info[slot_idx + i].nethdr = *hdr;
-		}
-	}
-
 	vq_inc_last_avail_packed(vq, PACKED_BATCH_SIZE);
 
 	vhost_async_shadow_dequeue_packed_batch(vq, ids);
-- 
2.51.0


                 reply	other threads:[~2026-07-07 15:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260707135044.7488-1-avanda@ptsecurity.com \
    --to=avanda@ptsecurity.com \
    --cc=chenbox@nvidia.com \
    --cc=cheng1.jiang@intel.com \
    --cc=dev@dpdk.org \
    --cc=honest.jiang@foxmail.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=stable@dpdk.org \
    --cc=thomas@monjalon.net \
    --cc=yuanx.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.