Skip to contentSkip to conversation

gtp: parse extension headers before reading inner protocol

PATCH Applied Zhixing Chen 3 participants 5 messages Jul 8 – Jul 21

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 gtp: parse extension headers before reading inner protocol

GTPv1-U packets may carry a chain of extension headers before the inner IP packet. The receive path already parses and skips these extension headers, but it currently reads the inner protocol before doing so.

As a result, the first extension header byte is interpreted as the inner IP version. Packets with extension headers are then dropped before PDP lookup.

Parse the extension header chain before calling gtp_inner_proto(), so the inner protocol is read from the actual inner IP header.

Fixes c75fc0b9e5be ("gtp: identify tunnel via GTP device + GTP version + TEID + family")

---

Changes in v3:
- Refetch the GTP header after pskb_may_pull() before checking the extension-header flag.

Changes in v2:
- Add missing Fixes tag.

v2: https://lore.kernel.org/netdev/[email protected]/T/
v1: https://lore.kernel.org/netdev/[email protected]/T/

---
 drivers/net/gtp.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/gtp.c +6 -6
index a60ef32b35b8..c0e38878af51 100644
@@ -826,13 +826,17 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb)
 	if (!pskb_may_pull(skb, hdrlen))
 		return -1;
 
+	gtp1 = (struct gtp1_header *)(skb->data + sizeof(struct udphdr));
+
+	if (gtp1->flags & GTP1_F_EXTHDR &&
+	    gtp_parse_exthdrs(skb, &hdrlen) < 0)
+		return -1;
+
 	if (gtp_inner_proto(skb, hdrlen, &inner_proto) < 0) {
 		netdev_dbg(gtp->dev, "GTP packet does not encapsulate an IP packet\n");
 		return -1;
 	}
 
-	gtp1 = (struct gtp1_header *)(skb->data + sizeof(struct udphdr));
-
 	pctx = gtp1_pdp_find(gtp, ntohl(gtp1->tid),
 			     gtp_proto_to_family(inner_proto));
 	if (!pctx) {
@@ -840,10 +844,6 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb)
 		return 1;
 	}
 
-	if (gtp1->flags & GTP1_F_EXTHDR &&
-	    gtp_parse_exthdrs(skb, &hdrlen) < 0)
-		return -1;
-
 	return gtp_rx(pctx, skb, hdrlen, gtp->role, inner_proto);
 }
 
Signature · 1 line
2.34.1
#1 lore raw

Hi Pablo,

Gentle ping on this v3, in case it fell through the cracks.

It refetches the GTP header after pskb_may_pull() before checking the extension-header flag, as you pointed out on v2.

Thanks,
Zhixing

maintainer
#2 lore raw
Quoted 1 line · Zhixing Chen

Gentle ping on this v3, in case it fell through the cracks.

Please, don't.

Maintainers are overflown by LLM generated contents, and conferences && season interruption reduce the available time. While the patch is alive in PW and no comments from reviewer and/or sashiko are pending, no additional action is needed.

The patch LGTM, I'm applying it now.

/P

#4 lore raw
In reply to Zhixing Chen
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Wed, 8 Jul 2026 12:22:44 +0800 you wrote:

GTPv1-U packets may carry a chain of extension headers before the inner IP packet. The receive path already parses and skips these extension headers, but it currently reads the inner protocol before doing so.

As a result, the first extension header byte is interpreted as the inner IP version. Packets with extension headers are then dropped before PDP lookup.

[...]

Here is the summary with links:
- [net,v3] gtp: parse extension headers before reading inner protocol

    https://git.kernel.org/netdev/net/c/96e37e2f618e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#3 lore raw
In reply to Paolo Abeni
Quoted 3 lines

season interruption reduce the available time. While the patch is alive in PW and no comments from reviewer and/or sashiko are pending, no additional action is needed.

Thanks Pablo, understood. I just learned this workflow and will keep it in mind next time.

I appreciate your review and help.

Best regards,
Zhixing