Skip to contentSkip to conversation

net/memif: fix segfault with large burst size

PATCH Applied Joyce Kong 2 participants 3 messages Sep 4, 2023 – Sep 29, 2023 Network drivers

lore
Share & tools
lore

Joyce Kong

author
#0 lore raw

PATCH 1/1 net/memif: fix segfault with large burst size

There will be a segfault when Rx burst size is greater than MAX_PKT_BURST of memif. Fix the issue by correcting the wrong mbuf index in eth_memif_rx, which results in accessing invalid memory address.

Bugzilla ID: 1273

Fixes aa17df860891 ("net/memif: add a Rx fast path")
---
 drivers/net/memif/rte_eth_memif.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/memif/rte_eth_memif.c +1 -1
index 6a8ff5b4eb..f595656af5 100644
@@ -356,7 +356,7 @@ eth_memif_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		rx_pkts = 0;
 		pkts = nb_pkts < MAX_PKT_BURST ? nb_pkts : MAX_PKT_BURST;
 		while (n_slots && rx_pkts < pkts) {
-			mbuf_head = mbufs[n_rx_pkts];
+			mbuf_head = mbufs[rx_pkts];
 			mbuf = mbuf_head;
 
 next_slot1:
Signature · 1 line
2.25.1
#1 lore raw
Quoted 21 lines · Joyce Kong

There will be a segfault when Rx burst size is greater than MAX_PKT_BURST of memif. Fix the issue by correcting the wrong mbuf index in eth_memif_rx, which results in accessing invalid memory address.

Bugzilla ID: 1273

Fixes aa17df860891 ("net/memif: add a Rx fast path")
---
 drivers/net/memif/rte_eth_memif.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/memif/rte_eth_memif.c +0 -0
index 6a8ff5b4eb..f595656af5 100644

drivers/net/memif/rte_eth_memif.c eth_memif_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) · line 362

Quoted 8 lines
drivers/net/memif/rte_eth_memif.c +1 -1
@@ -356,7 +356,7 @@ eth_memif_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		rx_pkts = 0;
 		pkts = nb_pkts < MAX_PKT_BURST ? nb_pkts : MAX_PKT_BURST;
 		while (n_slots && rx_pkts < pkts) {
-			mbuf_head = mbufs[n_rx_pkts];
+			mbuf_head = mbufs[rx_pkts];
 			mbuf = mbuf_head;
 
 next_slot1:

Hi Jakub,

Can you please look at this patch?

Thanks,
ferruh

Reviewed-by on v1 1/1 Applied
#2 lore raw
In reply to Joyce Kong
Quoted 5 lines · Joyce Kong

There will be a segfault when Rx burst size is greater than MAX_PKT_BURST of memif. Fix the issue by correcting the wrong mbuf index in eth_memif_rx, which results in accessing invalid memory address.

Quoted 8 lines

Bugzilla ID: 1273

Fixes aa17df860891 ("net/memif: add a Rx fast path")

Hi Joyce, good catch.

Applied to dpdk-next-net/main, thanks.

For record, if nb_pkts > MAX_PKT_BURST, memif buffer consumed in chunks of MAX_PKT_BURST mbufs, next chunk consumption starts with 'goto next_bulk' call.

For each chunk, MAX_PKT_BURST mbufs allocated and filled, they are accessed by 'n_rx_pkts' index, but 'n_rx_pkts' is overall received mbuf number, so it shouldn't be used as index for that chunk, but 'rx_pkts' should be used which is reset at the beginning of the chunk processing.

For the first chunk using 'n_rx_pkts' or 'rx_pkts' are same, that explains how issue lived till now, as commit log mentions issue can be observed when nb_pkts > MAX_PKT_BURST.