patch 'net/memif: validate descriptor length in zero-copy mode' has been queued to stable release 24.11.9
luca.boccassi at gmail.com
luca.boccassi at gmail.com
Tue Oct 27 12:50:29 CET 2026
Hi,
FYI, your patch has been queued to stable release 24.11.9
Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 10/29/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/bluca/dpdk-stable
This queued commit can be viewed at:
https://github.com/bluca/dpdk-stable/commit/5aa591474d97bc080b40251d8ce6a0c8e8f6cccf
Thanks.
Luca Boccassi
---
>From 5aa591474d97bc080b40251d8ce6a0c8e8f6cccf 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 6fe25b8353f..19858fe4091 100644
--- a/drivers/net/memif/rte_eth_memif.c
+++ b/drivers/net/memif/rte_eth_memif.c
@@ -709,7 +709,11 @@ eth_memif_rx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
memif_ring_t *ring = memif_get_ring_from_queue(proc_private, mq);
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;
int ret;
@@ -761,14 +765,31 @@ next_slot:
rte_prefetch0(&ring->desc[(cur_slot + 1) & mask]);
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];
mbuf_tail = mbuf;
@@ -776,7 +797,8 @@ next_slot:
ret = memif_pktmbuf_chain(mbuf_head, mbuf_tail, mbuf);
if (unlikely(ret < 0)) {
MIF_LOG(ERR, "number-of-segments-overflow");
- goto refill;
+ mq->n_err++;
+ goto discard;
}
goto next_slot;
}
@@ -786,6 +808,17 @@ 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 */
refill:
@@ -818,8 +851,9 @@ refill:
d0->length = rte_pktmbuf_data_room_size(mq->mempool) -
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:
/* The ring->head acts as a guard variable between Tx and Rx
@@ -1094,8 +1128,9 @@ next_in_chain:
mq->n_bytes += rte_pktmbuf_data_len(mbuf);
/* 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;
/* check if buffer is chained */
--
2.47.3
---
Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- - 2026-10-27 11:43:58.902327792 +0000
+++ 0135-net-memif-validate-descriptor-length-in-zero-copy-mo.patch 2026-10-27 11:43:53.658063905 +0000
@@ -1 +1 @@
-From 60019bbb9dd5a0b8814606a93bdb6a30702c0912 Mon Sep 17 00:00:00 2001
+From 5aa591474d97bc080b40251d8ce6a0c8e8f6cccf 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 6fe25b8353f..19858fe4091 100644
@@ -40 +41 @@
-@@ -711,7 +711,11 @@ eth_memif_rx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
+@@ -709,7 +709,11 @@ eth_memif_rx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
@@ -52 +53 @@
-@@ -763,14 +767,31 @@ next_slot:
+@@ -761,14 +765,31 @@ next_slot:
@@ -88 +89 @@
-@@ -778,7 +799,8 @@ next_slot:
+@@ -776,7 +797,8 @@ next_slot:
@@ -98 +99 @@
-@@ -788,6 +810,17 @@ next_slot:
+@@ -786,6 +808,17 @@ next_slot:
@@ -116 +117 @@
-@@ -820,8 +853,9 @@ refill:
+@@ -818,8 +851,9 @@ refill:
@@ -127 +128 @@
-@@ -1096,8 +1130,9 @@ next_in_chain:
+@@ -1094,8 +1128,9 @@ next_in_chain:
More information about the stable
mailing list