[PATCH 04/12] net/gve: fix integer truncation in GQI QPL Tx path

Joshua Washington joshwash at google.com
Fri Dec 4 00:26:27 CET 2026


In the GQ QPL Tx path, header length and payload length are computed as
uint32_t, but gve_tx_alloc_from_fifo() takes a uint16_t length. A
packet or TSO payload of 65536 bytes or greater truncates the higher
order bits, causing the FIFO to allocate a smaller size before copying
the full 32-bit length and overflowing the FIFO.

Additionally, GQI Tx descriptors only support 16-bit packet and segment
lengths, and packets exceeding sw_ring or FIFO capacity previously
stalled the queue indefinitely on backpressure checks.

Widen the length parameter of gve_tx_alloc_from_fifo() from uint16_t to
uint32_t, and validate each packet up front before consuming ring or
FIFO resources. Drop, free, and count in invalid_pkts and errors any
packet that is empty, exceeds UINT16_MAX bytes, lacks TSO headers or
payload (hlen == 0 || pkt_len <= hlen), exceeds sw_ring capacity
(nb_segs > nb_tx_desc - 1), or requires more FIFO space than fifo_size.

Fixes: a46583cf43c8 ("net/gve: support Rx/Tx")
Cc: stable at dpdk.org

Signed-off-by: Joshua Washington <joshwash at google.com>
Reviewed-by: Jasper Tran O'Leary <jtranoleary at google.com>
---
 drivers/net/gve/gve_tx.c | 59 ++++++++++++++++++++++++++++++----------
 1 file changed, 45 insertions(+), 14 deletions(-)

diff --git a/drivers/net/gve/gve_tx.c b/drivers/net/gve/gve_tx.c
index bf778a86e6..aa4fba07fd 100644
--- a/drivers/net/gve/gve_tx.c
+++ b/drivers/net/gve/gve_tx.c
@@ -233,7 +233,7 @@ gve_tx_reclaim_fifo_qpl(struct gve_tx_queue *txq, uint32_t tx_tail,
 }
 
 static inline uint64_t
-gve_tx_alloc_from_fifo(struct gve_tx_queue *txq, uint16_t tx_id, uint16_t len)
+gve_tx_alloc_from_fifo(struct gve_tx_queue *txq, uint16_t tx_id, uint32_t len)
 {
 	uint32_t head = txq->fifo_head;
 	uint32_t size = txq->fifo_size;
@@ -268,6 +268,34 @@ gve_tx_alloc_from_fifo(struct gve_tx_queue *txq, uint16_t tx_id, uint16_t len)
 	return fifo_addr;
 }
 
+static inline bool
+gve_tx_validate_pkt_limits_qpl(const struct gve_tx_queue *txq,
+			       const struct rte_mbuf *tx_pkt,
+			       uint64_t ol_flags, uint32_t hlen)
+{
+	uint32_t fifo_needed;
+
+	if (unlikely(tx_pkt->pkt_len == 0 || tx_pkt->pkt_len > UINT16_MAX))
+		return false;
+
+	if (unlikely(tx_pkt->nb_segs > txq->nb_tx_desc - 1))
+		return false;
+
+	if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
+		if (unlikely(hlen == 0 || tx_pkt->pkt_len <= hlen))
+			return false;
+		fifo_needed = RTE_ALIGN(hlen, RTE_CACHE_LINE_SIZE) +
+			RTE_ALIGN(tx_pkt->pkt_len - hlen, RTE_CACHE_LINE_SIZE);
+	} else {
+		fifo_needed = RTE_ALIGN(tx_pkt->pkt_len, RTE_CACHE_LINE_SIZE);
+	}
+
+	if (unlikely(fifo_needed > txq->fifo_size))
+		return false;
+
+	return true;
+}
+
 static inline uint16_t
 gve_tx_burst_qpl(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 {
@@ -303,6 +331,22 @@ gve_tx_burst_qpl(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 		tx_pkt = *tx_pkts++;
 		ol_flags = tx_pkt->ol_flags;
 
+		tx_offload.l2_len = tx_pkt->l2_len;
+		tx_offload.l3_len = tx_pkt->l3_len;
+		tx_offload.l4_len = tx_pkt->l4_len;
+		tx_offload.tso_segsz = tx_pkt->tso_segsz;
+
+		hlen = ol_flags & RTE_MBUF_F_TX_TCP_SEG ?
+			(uint32_t)(tx_offload.l2_len + tx_offload.l3_len + tx_offload.l4_len) :
+			tx_pkt->pkt_len;
+
+		if (unlikely(!gve_tx_validate_pkt_limits_qpl(txq, tx_pkt, ol_flags, hlen))) {
+			txq->stats.invalid_pkts++;
+			txq->stats.errors++;
+			rte_pktmbuf_free(tx_pkt);
+			continue;
+		}
+
 		if (txq->sw_nb_free < tx_pkt->nb_segs) {
 			gve_tx_clean_swr_qpl(txq);
 			if (txq->sw_nb_free < tx_pkt->nb_segs)
@@ -317,25 +361,12 @@ gve_tx_burst_qpl(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 		if (txq->nb_free < nb_used)
 			goto end_of_tx;
 
-		tx_offload.l2_len = tx_pkt->l2_len;
-		tx_offload.l3_len = tx_pkt->l3_len;
-		tx_offload.l4_len = tx_pkt->l4_len;
-		tx_offload.tso_segsz = tx_pkt->tso_segsz;
-
 		first = tx_pkt;
 		txd = &txr[tx_id];
-		hlen = ol_flags & RTE_MBUF_F_TX_TCP_SEG ?
-			(uint32_t)(tx_offload.l2_len + tx_offload.l3_len + tx_offload.l4_len) :
-			tx_pkt->pkt_len;
 
 		if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
 			uint32_t data_len, need;
 
-			if (unlikely(tx_pkt->pkt_len <= hlen)) {
-				rte_pktmbuf_free(tx_pkt);
-				txq->stats.errors++;
-				continue;
-			}
 			data_len = tx_pkt->pkt_len - hlen;
 			need = RTE_ALIGN(hlen, RTE_CACHE_LINE_SIZE) +
 			       RTE_ALIGN(data_len, RTE_CACHE_LINE_SIZE);
-- 
2.56.1.915.g69d5ec7298-goog



More information about the stable mailing list