[PATCH 1/5] net: check IPv4 header when parsing ptype

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


In rte_net_get_ptype() need to be defensive about IPv4 header.
Add checks that length is valid and that the packet contains
the whole header including options.

Bugzilla ID: 2121
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 | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lib/net/rte_net.c b/lib/net/rte_net.c
index 343eb88835..07284fa97a 100644
--- a/lib/net/rte_net.c
+++ b/lib/net/rte_net.c
@@ -417,6 +417,12 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
 		if (unlikely(ip4h == NULL))
 			return pkt_type;
 
+		if (unlikely(rte_ipv4_hdr_len(ip4h) < sizeof(*ip4h)))
+			return pkt_type;  /* invalid header length */
+
+		if (unlikely(off + rte_ipv4_hdr_len(ip4h) > rte_pktmbuf_pkt_len(m)))
+			return pkt_type;  /* header with options exceeds packet length */
+
 		pkt_type |= ptype_l3_ip(ip4h->version_ihl);
 		hdr_lens->l3_len = rte_ipv4_hdr_len(ip4h);
 		off += hdr_lens->l3_len;
@@ -557,6 +563,12 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
 		if (unlikely(ip4h == NULL))
 			return pkt_type;
 
+		/* the IHL must be valid and its bytes present, see above */
+		if (unlikely(rte_ipv4_hdr_len(ip4h) < sizeof(*ip4h) ||
+				off + rte_ipv4_hdr_len(ip4h) >
+				rte_pktmbuf_pkt_len(m)))
+			return pkt_type;
+
 		pkt_type |= ptype_inner_l3_ip(ip4h->version_ihl);
 		hdr_lens->inner_l3_len = rte_ipv4_hdr_len(ip4h);
 		off += hdr_lens->inner_l3_len;
-- 
2.53.0



More information about the stable mailing list