[PATCH 3/5] net: validate TCP data offset in ptype parser

Stephen Hemminger stephen at networkplumber.org
Thu Nov 12 20:54:44 CET 2026


rte_net_get_ptype() reads the fixed 20 bytes of a TCP header and reports
l4_len from the data offset field without checking it. A data offset
below 5 reports an l4_len shorter than the fixed header, and one above 5
counts option bytes that the read did not cover, so l4_len can describe
up to 40 bytes that are not in the packet.

Reject both cases and clear the L4 packet type as the existing short-read
path does, for the outer and inner header.

Bugzilla ID: 2119
Fixes: ab09e04d2c3f ("net: add function to get packet type from data")
Cc: stable at dpdk.org

Reported-by: Anthropic OSS scanner (ANT-2026-8BPC0WL7)
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
 lib/net/rte_net.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/lib/net/rte_net.c b/lib/net/rte_net.c
index b6d5127fcd..882ebf1467 100644
--- a/lib/net/rte_net.c
+++ b/lib/net/rte_net.c
@@ -344,6 +344,7 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
 	struct rte_ether_hdr eh_copy;
 	uint32_t pkt_type = RTE_PTYPE_L2_ETHER;
 	uint32_t off = 0, vlan_depth = 0;
+	uint32_t l4_len;
 	uint16_t proto;
 	int ret;
 
@@ -493,7 +494,13 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
 		if (unlikely(th == NULL))
 			return pkt_type & (RTE_PTYPE_L2_MASK |
 				RTE_PTYPE_L3_MASK);
-		hdr_lens->l4_len = (th->data_off & 0xf0) >> 2;
+		/* data offset may be short, or count options not in the read */
+		l4_len = (th->data_off & 0xf0) >> 2;
+		if (unlikely(l4_len < sizeof(*th) ||
+				off + l4_len > rte_pktmbuf_pkt_len(m)))
+			return pkt_type & (RTE_PTYPE_L2_MASK |
+				RTE_PTYPE_L3_MASK);
+		hdr_lens->l4_len = l4_len;
 		return pkt_type;
 	} else if ((pkt_type & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_SCTP) {
 		hdr_lens->l4_len = sizeof(struct rte_sctp_hdr);
@@ -639,7 +646,13 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
 		if (unlikely(th == NULL))
 			return pkt_type & (RTE_PTYPE_INNER_L2_MASK |
 				RTE_PTYPE_INNER_L3_MASK);
-		hdr_lens->inner_l4_len = (th->data_off & 0xf0) >> 2;
+		/* the data offset must be valid and present, see above */
+		l4_len = (th->data_off & 0xf0) >> 2;
+		if (unlikely(l4_len < sizeof(*th) ||
+				off + l4_len > rte_pktmbuf_pkt_len(m)))
+			return pkt_type & (RTE_PTYPE_INNER_L2_MASK |
+				RTE_PTYPE_INNER_L3_MASK);
+		hdr_lens->inner_l4_len = l4_len;
 	} else if ((pkt_type & RTE_PTYPE_INNER_L4_MASK) ==
 			RTE_PTYPE_INNER_L4_SCTP) {
 		hdr_lens->inner_l4_len = sizeof(struct rte_sctp_hdr);
-- 
2.53.0



More information about the stable mailing list