Skip to contentSkip to conversation

ip6_gre: validate ERSPAN skb dst before PMTU update

PATCH In review Daehyeon Ko 3 participants 3 messages Sep 30 – Oct 1

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

PATCH 1/1 ip6_gre: validate ERSPAN skb dst before PMTU update

A tc tunnel_key action can attach a METADATA_IP_TUNNEL dst to an skb, and mirred preserves it when redirecting the skb to a native ip6erspan device. ip6erspan_tunnel_xmit() treats any non-NULL dst as a route for PMTU updates. A metadata dst has no output device, so dst_dev(dst)->mtu dereferences NULL.

On v7.2 with KASAN, an initial UID/GID 65534 process with CapEff 0 created user and network namespaces, used namespace-local CAP_NET_ADMIN, and triggered:

  KASAN: null-ptr-deref
  RIP: 0010:ip6erspan_tunnel_xmit+0x10fc/0x2cc0
  Kernel panic - not syncing: Fatal exception in interrupt

The collect-metadata path already skips this block because its metadata describes the outer tunnel. Native mode must still propagate PMTU updates for real route destinations. Use skb_valid_dst(), matching IPv4 tunnel PMTU handling, to exclude DST_METADATA without suppressing valid routes.

With this change, the same trigger processed three packets without a sanitizer report, oops, or panic.

Fixes 5a963eb61b7c ("ip6_gre: Add ERSPAN native tunnel support")
Assisted-by Codex:GPT-5

---
Affected since v4.16-rc1; present in v7.2 and all four pinned 2026-09-30 upstream snapshots.

Tested with CONFIG_USER_NS=y, CONFIG_NET_NS=y, CONFIG_IPV6_GRE=y, CONFIG_NET_CLS_ACT=y, CONFIG_NET_ACT_TUNNEL_KEY=y, and CONFIG_NET_ACT_MIRRED=y. Config SHA-256:
f992c9fdb881ca95c467896791c52554719f6204cf06268cd92ac37c14c14f83

The reproducer is available privately on request and is omitted from this public AI-assisted report.

---
 net/ipv6/ip6_gre.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/ip6_gre.c +1 -1
index e61cb10b50dc..3ee7fad6089a 100644
@@ -1059,7 +1059,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 			 htonl(atomic_fetch_inc(&t->o_seqno)));
 
 	/* TooBig packet may have updated dst->dev's mtu */
-	if (!t->parms.collect_md && dst) {
+	if (!t->parms.collect_md && skb_valid_dst(skb)) {
 		mtu = READ_ONCE(dst_dev(dst)->mtu);
 		if (dst_mtu(dst) > mtu)
 			dst->ops->update_pmtu(dst, NULL, skb, mtu, false);

base-commit: 54518e0e827f4ca9229ae657022c60bf60f5c1bf

Signature · 1 line
2.55.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Daehyeon Ko

A tc tunnel_key action can attach a METADATA_IP_TUNNEL dst to an skb, and mirred preserves it when redirecting the skb to a native ip6erspan device. ip6erspan_tunnel_xmit() treats any non-NULL dst as a route for PMTU updates. A metadata dst has no output device, so dst_dev(dst)->mtu dereferences NULL.

On v7.2 with KASAN, an initial UID/GID 65534 process with CapEff 0 created user and network namespaces, used namespace-local CAP_NET_ADMIN, and triggered:

  KASAN: null-ptr-deref
  RIP: 0010:ip6erspan_tunnel_xmit+0x10fc/0x2cc0
  Kernel panic - not syncing: Fatal exception in interrupt

The collect-metadata path already skips this block because its metadata describes the outer tunnel. Native mode must still propagate PMTU updates for real route destinations. Use skb_valid_dst(), matching IPv4 tunnel PMTU handling, to exclude DST_METADATA without suppressing valid routes.

Quoted 7 lines

With this change, the same trigger processed three packets without a sanitizer report, oops, or panic.

Fixes 5a963eb61b7c ("ip6_gre: Add ERSPAN native tunnel support")
Assisted-by Codex:GPT-5

SGTM, thanks.

maintainer
#2 lore raw
In reply to Daehyeon Ko
Quoted 46 lines · Daehyeon Ko

A tc tunnel_key action can attach a METADATA_IP_TUNNEL dst to an skb, and mirred preserves it when redirecting the skb to a native ip6erspan device. ip6erspan_tunnel_xmit() treats any non-NULL dst as a route for PMTU updates. A metadata dst has no output device, so dst_dev(dst)->mtu dereferences NULL.

On v7.2 with KASAN, an initial UID/GID 65534 process with CapEff 0 created user and network namespaces, used namespace-local CAP_NET_ADMIN, and triggered:

  KASAN: null-ptr-deref
  RIP: 0010:ip6erspan_tunnel_xmit+0x10fc/0x2cc0
  Kernel panic - not syncing: Fatal exception in interrupt

The collect-metadata path already skips this block because its metadata describes the outer tunnel. Native mode must still propagate PMTU updates for real route destinations. Use skb_valid_dst(), matching IPv4 tunnel PMTU handling, to exclude DST_METADATA without suppressing valid routes.

With this change, the same trigger processed three packets without a sanitizer report, oops, or panic.

Fixes 5a963eb61b7c ("ip6_gre: Add ERSPAN native tunnel support")
Assisted-by Codex:GPT-5

---
Affected since v4.16-rc1; present in v7.2 and all four pinned 2026-09-30 upstream snapshots.

Tested with CONFIG_USER_NS=y, CONFIG_NET_NS=y, CONFIG_IPV6_GRE=y, CONFIG_NET_CLS_ACT=y, CONFIG_NET_ACT_TUNNEL_KEY=y, and CONFIG_NET_ACT_MIRRED=y. Config SHA-256:
f992c9fdb881ca95c467896791c52554719f6204cf06268cd92ac37c14c14f83

The reproducer is available privately on request and is omitted from this public AI-assisted report.

---
 net/ipv6/ip6_gre.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/ip6_gre.c +0 -0
index e61cb10b50dc..3ee7fad6089a 100644

net/ipv6/ip6_gre.c static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb, · line 1065

Quoted 8 lines
net/ipv6/ip6_gre.c +1 -1
@@ -1059,7 +1059,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 			 htonl(atomic_fetch_inc(&t->o_seqno)));
 
 	/* TooBig packet may have updated dst->dev's mtu */
-	if (!t->parms.collect_md && dst) {
+	if (!t->parms.collect_md && skb_valid_dst(skb)) {
 		mtu = READ_ONCE(dst_dev(dst)->mtu);
 		if (dst_mtu(dst) > mtu)
 			dst->ops->update_pmtu(dst, NULL, skb, mtu, false);

This hunk seems obsolete and it's better to remove it like commit fe1a4ca0a2b7 ("ip6_gre: process toobig in a better way") did in __gre6_xmit().

Nowadays the ICMP error handler sets the PMTU in the underlay route and ip6_tnl_xmit() propagates it to the overlay route.