patch 'net/memif: validate descriptor length in zero-copy mode' has been queued to stable release 25.11.5

Kevin Traynor ktraynor at redhat.com
Thu Dec 3 14:01:26 CET 2026


Hi,

FYI, your patch has been queued to stable release 25.11.5

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 12/08/26. 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/kevintraynor/dpdk-stable

This queued commit can be viewed at:
https://github.com/kevintraynor/dpdk-stable/commit/c6c156fac86f70c475f9d8049765a9866c60472c

Thanks.

Kevin

---
>From c6c156fac86f70c475f9d8049765a9866c60472c Mon Sep 17 00:00:00 2001
From: Stephen Hemminger <stephen at networkplumber.org>
Date: Tue, 22 Sep 2026 12:40:56 -0700
Subject: [PATCH] net/memif: validate descriptor length in zero-copy mode

[ upstream commit 60019bbb9dd5a0b8814606a93bdb6a30702c0912 ]

In zero-copy mode the receive buffers are the driver's own mbufs,
and the peer supplies the resulting length. That length needs to
be checked so that buggy/hostile peer doesn't crash server.

Validate the length against the buffer size advertised to the peer.
Read descriptor length once to avoid TOCTOU issues.

An invalid length means the peer is not honoring the contract on a
field whose buffer the driver owns, so nothing else in the ring can
be trusted. Drop the burst and disconnect, as is done for the other
invalid descriptor cases.

This also fixes the packet length of chained zero-copy segments.
memif_pktmbuf_chain() adds the tail data_len while it is still
zero, so a multi-segment packet previously carried only the length
of its first segment.

While here, fix a leak on the existing number-of-segments-overflow
path.

Bugzilla ID: 2018
Fixes: 43b815d88188 ("net/memif: support zero-copy slave")

Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
Tested-by: Sriram Yagnaraman <sriram.yagnaraman at ericsson.com>
---
 drivers/net/memif/rte_eth_memif.c | 49 ++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 7 deletions(-)

diff --git a/drivers/net/memif/rte_eth_memif.c b/drivers/net/memif/rte_eth_memif.c
index b30947e9d6..cdeffb1c99 100644
--- a/drivers/net/memif/rte_eth_memif.c
+++ b/drivers/net/memif/rte_eth_memif.c
@@ -712,5 +712,9 @@ eth_memif_rx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	uint16_t cur_slot, last_slot, n_slots, ring_size, mask, s0, head;
 	uint16_t n_rx_pkts = 0;
+	/* Buffer size advertised to the peer by the refill loop below. */
+	const uint16_t buf_size = rte_pktmbuf_data_room_size(mq->mempool) -
+		RTE_PKTMBUF_HEADROOM;
 	memif_desc_t *d0;
+	memif_desc_t desc;
 	struct rte_mbuf *mbuf, *mbuf_tail;
 	struct rte_mbuf *mbuf_head = NULL;
@@ -764,12 +768,29 @@ next_slot:
 
 		mbuf->port = mq->in_port;
-		rte_pktmbuf_data_len(mbuf) = d0->length;
-		rte_pktmbuf_pkt_len(mbuf) = rte_pktmbuf_data_len(mbuf);
+		desc = memif_desc_read(d0);
 
-		mq->n_bytes += rte_pktmbuf_data_len(mbuf);
+		/* The peer only supplies the length here */
+		if (unlikely(desc.length > buf_size)) {
+			memif_desc_error(mq, &desc, MEMIF_DESC_STATUS_ERR_DATA_TOO_BIG);
+			/* Consume the slot before discarding */
+			cur_slot++;
+			n_slots--;
+			goto discard;
+		}
+
+		rte_pktmbuf_data_len(mbuf) = desc.length;
+		rte_pktmbuf_pkt_len(mbuf) = desc.length;
+		if (mbuf != mbuf_head)
+			rte_pktmbuf_pkt_len(mbuf_head) += desc.length;
+
+		mq->n_bytes += desc.length;
 
 		cur_slot++;
 		n_slots--;
-		if (d0->flags & MEMIF_DESC_FLAG_NEXT) {
+		if (desc.flags & MEMIF_DESC_FLAG_NEXT) {
+			if (unlikely(n_slots == 0)) {
+				mq->n_err++;
+				goto discard;
+			}
 			s0 = cur_slot & mask;
 			d0 = &ring->desc[s0];
@@ -779,5 +800,6 @@ next_slot:
 			if (unlikely(ret < 0)) {
 				MIF_LOG(ERR, "number-of-segments-overflow");
-				goto refill;
+				mq->n_err++;
+				goto discard;
 			}
 			goto next_slot;
@@ -789,4 +811,15 @@ next_slot:
 
 	mq->last_tail = cur_slot;
+	goto refill;
+
+discard:
+	/*
+	 * The peer is buggy or hostile, remaining descriptors cannot be trusted.
+	 * Drop the partially built packet and the slots not yet consumed.
+	 */
+	rte_pktmbuf_free(mbuf_head);
+	while (n_slots--)
+		rte_pktmbuf_free_seg(mq->buffers[cur_slot++ & mask]);
+	mq->last_tail = cur_slot;
 
 /* Supply server with new buffers */
@@ -821,6 +854,7 @@ refill:
 				RTE_PKTMBUF_HEADROOM;
 		d0->region = 1;
+		/* Use the constant, the peer can change d0->region at any time. */
 		d0->offset = rte_pktmbuf_mtod(mbuf, uint8_t *) -
-			(uint8_t *)proc_private->regions[d0->region]->addr;
+			(uint8_t *)proc_private->regions[1]->addr;
 	}
 no_free_mbufs:
@@ -1097,6 +1131,7 @@ next_in_chain:
 	/* FIXME: get region index */
 	d0->region = 1;
+	/* Use the constant, the peer can change d0->region at any time. */
 	d0->offset = rte_pktmbuf_mtod(mbuf, uint8_t *) -
-		(uint8_t *)proc_private->regions[d0->region]->addr;
+		(uint8_t *)proc_private->regions[1]->addr;
 	d0->flags = 0;
 
-- 
2.56.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2026-12-03 12:52:43.807489008 +0000
+++ 0160-net-memif-validate-descriptor-length-in-zero-copy-mo.patch	2026-12-03 12:52:39.142476856 +0000
@@ -1 +1 @@
-From 60019bbb9dd5a0b8814606a93bdb6a30702c0912 Mon Sep 17 00:00:00 2001
+From c6c156fac86f70c475f9d8049765a9866c60472c Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit 60019bbb9dd5a0b8814606a93bdb6a30702c0912 ]
+
@@ -28 +29,0 @@
-Cc: stable at dpdk.org
@@ -37 +38 @@
-index 0a745eb8d4..2d42338e48 100644
+index b30947e9d6..cdeffb1c99 100644



More information about the stable mailing list