Skip to contentSkip to conversation

ipmr: forward GSO multicast packets

PATCH Superseded Julius Bairaktaris 1 participant 5 messages Oct 18

Subsystems (3)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover ipmr: forward GSO multicast packets

With fraglist GRO or UDP GRO forwarding on, a routed IPv4 multicast stream arrives as GSO packets. ipmr_prepare_xmit() drops every DF aggregate larger than the MTU, and ip_encap() sets no tunnel GSO state, so a GSO packet sent to a VIFF_TUNNEL vif is dropped during segmentation. With that state set, a fraglist aggregate reaches skb_segment_list() with tunnel headers, which can write before the head of a frag_list member, and a TCP GRO packet keeps its fixed-ID flag on what is now the outer header. Both also happen today when such a packet is routed into a tunnel device.

Patch 1 makes room for the tunnel headers in skb_segment_list(). Patch 2 moves the TCP fixed-ID flag to the inner header on encapsulation. Patch 3 sets up IPXIP4 GSO state and outer IP IDs in ip_encap(). Patch 4 lets DF GSO packets pass when their segments fit the MTU.

Tested in QEMU on veth, n=3 per arm: an MFC entry to a plain vif and a tunnel vif, 4000 1316-byte datagrams per run, fraglist GRO, UDP GRO forwarding and UDP_SEGMENT, DF set and clear, software segmentation on egress; a fraglist stream routed into VXLAN over IPv4 and IPv6; and a TCP stream with fixed IP IDs, merged by GRO and routed into an ipip device with DF clear.
- net (7ec48f396a1d): DF aggregates dropped on both vifs (FragFails), non-DF aggregates dropped on the tunnel vif (tx_dropped); VXLAN:
KASAN slab-out-of-bounds write in skb_segment_list() in 6 of 6 runs, then a panic.
- v2: outer IP IDs repeat on the tunnel vif in 18 of 18 runs.
- without patch 2: TCP over ipip repeats outer IP IDs (831 unique of 14666) and increments the fixed inner IDs, 3 of 3 runs.
- this series: every segment sent on both vifs, FragFails 0, no tx drops, outer IP IDs unique in 18 of 18 runs; VXLAN: no KASAN report in 6 of 6 runs; TCP over ipip: outer IDs unique, inner IDs kept, 3 of 3 runs.

Changes in v3:
- Patch 1: name the VXLAN out-of-bounds write (Sashiko).
- Add patch 2 (Sashiko).
- Patch 3: reserve one outer IP ID per segment (Sashiko).
- v2: https://lore.kernel.org/netdev/[email protected]/

Changes in v2:
- Add patches 1 and 3; v1 let DF GSO packets reach ip_encap() on tunnel vifs, where they were dropped during segmentation (Sashiko).
- Keep the additive MTU comparison and check mtu > encap before subtracting, so a route MTU below 20 cannot wrap (Sashiko).
- v1: https://lore.kernel.org/netdev/[email protected]/

Julius Bairaktaris (4):
net: make room for the tunnel header in skb_segment_list()
ip_tunnel: move the TCP fixed-ID flag to the inner header
ipmr: set up GSO state for tunnel vifs
ipmr: do not drop GSO packets that fit the MTU after segmentation

 net/core/skbuff.c         |  4 ++++
 net/ipv4/ip_tunnel_core.c | 13 ++++++++++++-
 net/ipv4/ipmr.c           | 23 +++++++++++++++++------
 3 files changed, 33 insertions(+), 7 deletions(-)

base-commit: 7ec48f396a1d89532c0537bc38b408b8c31ee37f

Signature · 1 line
2.53.0
#1 lore raw

PATCH v3 1/4 net: make room for the tunnel header in skb_segment_list()

skb_segment_list() pushes each frag_list member back to the outer MAC header and copies the tunnel headers in front of it, but never checks that the member has the headroom. A fraglist GRO packet forwarded into a tunnel and segmented in software then hits skb_under_panic() on IPIP, and on VXLAN the copy writes before the member's head (KASAN:
slab-out-of-bounds write in skb_segment_list()).

Call skb_cow_head() on each member before pushing it.

Fixes 3a1296a38d0c ("net: Support GRO/GSO fraglist chaining.")
Assisted-by Claude:claude-opus-5-5
---
 net/core/skbuff.c | 4 ++++
 1 file changed, 4 insertions(+)
net/core/skbuff.c +4 -0
index 41beaf625421a..3f358c0fc0483 100644
@@ -4729,6 +4729,10 @@ struct sk_buff *skb_segment_list(struct sk_buff *skb,
 			}
 		}
 
+		if (!err)
+			err = skb_cow_head(nskb, offset + tnl_hlen -
+					   skb_network_offset(nskb));
+
 		if (!tail)
 			skb->next = nskb;
 		else
Signature · 1 line
2.53.0
#2 lore raw

PATCH v3 2/4 ip_tunnel: move the TCP fixed-ID flag to the inner header

In reply to Julius Bairaktaris

SKB_GSO_TCP_FIXEDID describes the outer header of an encapsulated GSO packet and SKB_GSO_TCP_FIXEDID_INNER the inner one. TCP GRO sets SKB_GSO_TCP_FIXEDID for the header it merged. When such a packet is forwarded into a tunnel, iptunnel_handle_offloads() makes that header the inner one but leaves the flag, so software segmentation gives every segment the outer ID of the first and increments the inner IDs.

Move the flag to SKB_GSO_TCP_FIXEDID_INNER when the packet becomes encapsulated.

Fixes 3271f19bf7b9 ("net: gso: restore ids of outer ip headers correctly")
Assisted-by Claude:claude-opus-5-5
---
 net/ipv4/ip_tunnel_core.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
net/ipv4/ip_tunnel_core.c +12 -1
index bab42b9e277f7..752ddba1298b6 100644
@@ -174,18 +174,29 @@ EXPORT_SYMBOL_GPL(iptunnel_metadata_reply);
 int iptunnel_handle_offloads(struct sk_buff *skb,
 			     int gso_type_mask)
 {
+	bool inner = false;
 	int err;
 
 	if (likely(!skb->encapsulation)) {
 		skb_reset_inner_headers(skb);
 		skb->encapsulation = 1;
+		inner = true;
 	}
 
 	if (skb_is_gso(skb)) {
+		struct skb_shared_info *shinfo;
+
 		err = skb_header_unclone(skb, GFP_ATOMIC);
 		if (unlikely(err))
 			return err;
-		skb_shinfo(skb)->gso_type |= gso_type_mask;
+
+		shinfo = skb_shinfo(skb);
+		/* The header SKB_GSO_TCP_FIXEDID described is now the inner one */
+		if (inner && (shinfo->gso_type & SKB_GSO_TCP_FIXEDID)) {
+			shinfo->gso_type &= ~SKB_GSO_TCP_FIXEDID;
+			shinfo->gso_type |= SKB_GSO_TCP_FIXEDID_INNER;
+		}
+		shinfo->gso_type |= gso_type_mask;
 		return 0;
 	}
 
Signature · 1 line
2.53.0
#3 lore raw

PATCH v3 3/4 ipmr: set up GSO state for tunnel vifs

In reply to Julius Bairaktaris

ip_encap() pushes the outer IPv4 header but does not set SKB_GSO_IPXIP4, skb->encapsulation or the inner headers. A GSO packet forwarded to a VIFF_TUNNEL vif is then rejected by ipip_gso_segment() and dropped in validate_xmit_skb(), after being counted as sent. A device with UDP segmentation offload is handed a GSO packet whose transport header points at the inner IP header.

Call iptunnel_handle_offloads() and skb_set_inner_ipproto() as ipip_tunnel_xmit() does, and reserve one outer IP ID per segment as iptunnel_xmit() does.

Fixes 9fd1ff5d2ac7 ("udp: Support UDP fraglist GRO/GSO.")
Assisted-by Claude:claude-opus-5-5
---
 net/ipv4/ipmr.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
net/ipv4/ipmr.c +12 -5
index b9c544d48c452..6f2eb571f30f7 100644
@@ -1835,12 +1835,17 @@ static struct notifier_block ip_mr_notifier = {
  * This avoids tunnel drivers and other mess and gives us the speed so
  * important for multicast video.
  */
-static void ip_encap(struct net *net, struct sk_buff *skb,
-		     __be32 saddr, __be32 daddr)
+static int ip_encap(struct net *net, struct sk_buff *skb,
+		    __be32 saddr, __be32 daddr)
 {
+	const struct iphdr *old_iph;
 	struct iphdr *iph;
-	const struct iphdr *old_iph = ip_hdr(skb);
 
+	if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP4))
+		return -1;
+	skb_set_inner_ipproto(skb, IPPROTO_IPIP);
+
+	old_iph = ip_hdr(skb);
 	skb_push(skb, sizeof(struct iphdr));
 	skb->transport_header = skb->network_header;
 	skb_reset_network_header(skb);
@@ -1855,11 +1860,12 @@ static void ip_encap(struct net *net, struct sk_buff *skb,
 	iph->protocol	=	IPPROTO_IPIP;
 	iph->ihl	=	5;
 	iph->tot_len	=	htons(skb->len);
-	ip_select_ident(net, skb, NULL);
+	ip_select_ident_segs(net, skb, NULL, skb_shinfo(skb)->gso_segs ?: 1);
 	ip_send_check(iph);
 
 	memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
 	nf_reset_ct(skb);
+	return 0;
 }
 
 static inline int ipmr_forward_finish(struct net *net, struct sock *sk,
@@ -1968,7 +1974,8 @@ static int ipmr_prepare_xmit(struct net *net, struct mr_table *mrt,
 	 * What do we do with netfilter? -- RR
 	 */
 	if (vif->flags & VIFF_TUNNEL) {
-		ip_encap(net, skb, vif->local, vif->remote);
+		if (ip_encap(net, skb, vif->local, vif->remote))
+			return -1;
 		/* FIXME: extra output firewall step used to be here. --RR */
 		DEV_STATS_INC(vif_dev, tx_packets);
 		DEV_STATS_ADD(vif_dev, tx_bytes, skb->len);
Signature · 1 line
2.53.0
#4 lore raw

PATCH v3 4/4 ipmr: do not drop GSO packets that fit the MTU after segmentation

In reply to Julius Bairaktaris

ipmr_prepare_xmit() drops a packet with DF set when skb->len exceeds the route MTU, without checking whether it is a GSO packet. A UDP multicast stream received with fraglist GRO or UDP GRO forwarding enabled is aggregated into GSO packets, and every aggregate is dropped with FragFails, while ip_forward() lets the same packets pass by checking skb_gso_validate_network_len(). Do the same for multicast routing, leaving room for the outer header on tunnel vifs. ip6mr has no such check and leaves GSO packets to ip6_output().

On an IPQ8074 router with fraglist GRO on, a 10 Mbit/s stream of 1316-byte DF datagrams routed by igmpproxy loses 14.5 to 15.5% (n=3) and 0% with this change.

Fixes 9fd1ff5d2ac7 ("udp: Support UDP fraglist GRO/GSO.")
Assisted-by Claude:claude-opus-5-5
---
 net/ipv4/ipmr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/ipv4/ipmr.c +5 -1
index 6f2eb571f30f7..0a2c573ceeb79 100644
@@ -1914,6 +1914,7 @@ static int ipmr_prepare_xmit(struct net *net, struct mr_table *mrt,
 	struct rtable *rt;
 	struct flowi4 fl4;
 	int    encap = 0;
+	unsigned int mtu;
 
 	vif_dev = vif_dev_read(vif);
 	if (!vif_dev)
@@ -1946,7 +1947,10 @@ static int ipmr_prepare_xmit(struct net *net, struct mr_table *mrt,
 			return -1;
 	}
 
-	if (skb->len+encap > dst4_mtu(&rt->dst) && (ntohs(iph->frag_off) & IP_DF)) {
+	mtu = dst4_mtu(&rt->dst);
+	if (skb->len + encap > mtu && (ntohs(iph->frag_off) & IP_DF) &&
+	    !(skb_is_gso(skb) && mtu > encap &&
+	      skb_gso_validate_network_len(skb, mtu - encap))) {
 		/* Do not fragment multicasts. Alas, IPv4 does not
 		 * allow to send ICMP, so that packets will disappear
 		 * to blackhole.
Signature · 1 line
2.53.0