Skip to contentSkip to conversation

net: fix wrong network header length

PATCH New Lina Wang 2 participants 3 messages May 5, 2022 – May 9, 2022

Subsystems (5)
lore
Share & tools
lore

Lina Wang

author
#0 lore raw

PATCH v6 1/2 net: fix wrong network header length

When clatd starts with ebpf offloaing, and NETIF_F_GRO_FRAGLIST is enable, several skbs are gathered in skb_shinfo(skb)->frag_list. The first skb's ipv6 header will be changed to ipv4 after bpf_skb_proto_6_to_4, network_header\transport_header\mac_header have been updated as ipv4 acts, but other skbs in frag_list didnot update anything, just ipv6 packets.

udp_queue_rcv_skb will call skb_segment_list to traverse other skbs in frag_list and make sure right udp payload is delivered to user space. Unfortunately, other skbs in frag_list who are still ipv6 packets are updated like the first skb and will have wrong transport header length.

e.g.before bpf_skb_proto_6_to_4,the first skb and other skbs in frag_list has the same network_header(24)& transport_header(64), after bpf_skb_proto_6_to_4, ipv6 protocol has been changed to ipv4, the first skb's network_header is 44,transport_header is 64, other skbs in frag_list didnot change.After skb_segment_list, the other skbs in frag_list has different network_header(24) and transport_header(44), so there will be 20 bytes different from original,that is difference between ipv6 header and ipv4 header. Just change transport_header to be the same with original.

Actually, there are two solutions to fix it, one is traversing all skbs and changing every skb header in bpf_skb_proto_6_to_4, the other is modifying frag_list skb's header in skb_segment_list. Considering efficiency, adopt the second one--- when the first skb and other skbs in frag_list has different network_header length, restore them to make sure right udp payload is delivered to user space.

---
 net/core/skbuff.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/skbuff.c +3 -1
index 10bde7c6db44..e8006e0a1b25 100644
@@ -3897,7 +3897,7 @@ struct sk_buff *skb_segment_list(struct sk_buff *skb,
 	unsigned int delta_len = 0;
 	struct sk_buff *tail = NULL;
 	struct sk_buff *nskb, *tmp;
-	int err;
+	int len_diff, err;
 
 	skb_push(skb, -skb_network_offset(skb) + offset);
 
@@ -3937,9 +3937,11 @@ struct sk_buff *skb_segment_list(struct sk_buff *skb,
 		skb_push(nskb, -skb_network_offset(nskb) + offset);
 
 		skb_release_head_state(nskb);
+		len_diff = skb_network_header_len(nskb) - skb_network_header_len(skb);
 		__copy_skb_header(nskb, skb);
 
 		skb_headers_offset_update(nskb, skb_headroom(nskb) - skb_headroom(skb));
+		nskb->transport_header += len_diff;
 		skb_copy_from_linear_data_offset(skb, -tnl_hlen,
 						 nskb->data - tnl_hlen,
 						 offset + tnl_hlen);
Signature · 1 line
2.18.0
author
#1 lore raw

PATCH v6 2/2 selftests net: add UDP GRO fraglist + bpf self-tests

When NET_F_F_GRO_FRAGLIST is enabled and bpf_skb_change_proto is used, check if udp packets and tcp packets are successfully delivered to user space. If wrong udp packets are delivered, udpgso_bench_rx will exit with "Initial byte out of range"

---
 tools/testing/selftests/net/Makefile          |   3 +
 tools/testing/selftests/net/bpf/Makefile      |  17 ++
 tools/testing/selftests/net/bpf/nat6to4.c     | 286 ++++++++++++++++++
 tools/testing/selftests/net/udpgro_frglist.sh | 101 +++++++
 4 files changed, 407 insertions(+)
 create mode 100644 tools/testing/selftests/net/bpf/Makefile
 create mode 100644 tools/testing/selftests/net/bpf/nat6to4.c
 create mode 100755 tools/testing/selftests/net/udpgro_frglist.sh
tools/testing/selftests/net/Makefile +3 -0
index 3fe2515aa616..f670c20fbc57 100644
@@ -25,6 +25,7 @@ TEST_PROGS += bareudp.sh
 TEST_PROGS += amt.sh
 TEST_PROGS += unicast_extensions.sh
 TEST_PROGS += udpgro_fwd.sh
+TEST_PROGS += udpgro_frglist.sh
 TEST_PROGS += veth.sh
 TEST_PROGS += ioam6.sh
 TEST_PROGS += gro.sh
@@ -60,6 +61,8 @@ TEST_FILES := settings
 KSFT_KHDR_INSTALL := 1
 include ../lib.mk
 
+include bpf/Makefile
+
 $(OUTPUT)/reuseport_bpf_numa: LDLIBS += -lnuma
 $(OUTPUT)/tcp_mmap: LDLIBS += -lpthread
 $(OUTPUT)/tcp_inq: LDLIBS += -lpthread
tools/testing/selftests/net/bpf/Makefile new file +17 -0
new file mode 100644
index 000000000000..47e715e54cab
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+
+CLANG ?= clang
+CCINCLUDE += -I../../bpf 
+CCINCLUDE += -I../../../../../usr/include/
+
+TEST_CUSTOM_PROGS = $(OUTPUT)/bpf/nat6to4.o
+all: $(TEST_CUSTOM_PROGS)
+
+$(OUTPUT)/%.o: %.c
+	$(CLANG) -O2 -target bpf -c $< $(CCINCLUDE) -o $@
+
+clean:
+	rm -f $(TEST_CUSTOM_PROGS)
+
+
+
tools/testing/selftests/net/bpf/nat6to4.c new file +286 -0

286 lines not on this page · raw message

tools/testing/selftests/net/udpgro_frglist.sh new file +101 -0

101 lines not on this page · raw message

Signature · 1 line
2.18.0
#2 lore raw
In reply to Lina Wang
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Quoted 6 lines · On Thu, 5 May 2022 13:48:49 +0800 you wrote:

When clatd starts with ebpf offloaing, and NETIF_F_GRO_FRAGLIST is enable, several skbs are gathered in skb_shinfo(skb)->frag_list. The first skb's ipv6 header will be changed to ipv4 after bpf_skb_proto_6_to_4, network_header\transport_header\mac_header have been updated as ipv4 acts, but other skbs in frag_list didnot update anything, just ipv6 packets.

Quoted 6 lines

udp_queue_rcv_skb will call skb_segment_list to traverse other skbs in frag_list and make sure right udp payload is delivered to user space. Unfortunately, other skbs in frag_list who are still ipv6 packets are updated like the first skb and will have wrong transport header length.

[...]

Here is the summary with links:
- [v6,1/2] net: fix wrong network header length

    https://git.kernel.org/netdev/net/c/cf3ab8d4a797

- [v6,2/2] selftests net: add UDP GRO fraglist + bpf self-tests (no matching commit)

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html