Skip to contentSkip to conversation

WireGuard bug fixes and cleanups

PATCH In review Jason A. Donenfeld 2 participants 8 messages Jan 2, 2020 – Jan 5, 2020

Subsystems (4)
lore
Share & tools
lore

Jason A. Donenfeld

author maintainer
#0 lore raw

cover WireGuard bug fixes and cleanups

I've been working through some personal notes and also the whole git repo history of the out-of-tree module, looking for places where tradeoffs were made (and subsequently forgotten about) for old kernels. The first two patches in this series clean up those. The first one does so in the self-tests and self-test harness, where we're now able to expand test coverage by a bit, and we're now cooking away tests on every commit to both the wireguard-linux repo and to net-next. The second one removes a workaround for a skbuff.h bug that was fixed long ago. Finally, the last patch in the series fixes in a bug unearthed by newer Qualcomm chipsets running the rmnet_perf driver, which does UDP GRO.

Jason A. Donenfeld (3):
wireguard: selftests: remove ancient kernel compatibility code
wireguard: queueing: do not account for pfmemalloc when clearing skb
header
wireguard: socket: mark skbs as not on list when receiving via gro

 drivers/net/wireguard/queueing.h              |  3 -
 drivers/net/wireguard/socket.c                |  1 +
 tools/testing/selftests/wireguard/netns.sh    | 11 +--
 .../testing/selftests/wireguard/qemu/Makefile | 82 ++++++++++---------
 .../selftests/wireguard/qemu/arch/m68k.config |  2 +-
 tools/testing/selftests/wireguard/qemu/init.c |  1 +
 .../selftests/wireguard/qemu/kernel.config    |  2 +
 7 files changed, 51 insertions(+), 51 deletions(-)
Signature · 1 line
2.24.1
author maintainer
#1 lore raw

PATCH 1/3 wireguard: selftests: remove ancient kernel compatibility code

Quite a bit of the test suite was designed to work with ancient kernels. Thankfully we no longer have to deal with this. This commit updates things that we can finally update and removes things that we can finally remove, to avoid the build-up of the last several years as a result of having to support ancient kernels. We can finally rely on suppress_ prefixlength being available. On the build side of things, the no-PIE hack is no longer required, and we can bump some of the tools, repair our m68k and i686-kvm support, and get better coverage of the static branches used in the crypto lib and in udp_tunnel.

---
 tools/testing/selftests/wireguard/netns.sh    | 11 +--
 .../testing/selftests/wireguard/qemu/Makefile | 82 ++++++++++---------
 .../selftests/wireguard/qemu/arch/m68k.config |  2 +-
 tools/testing/selftests/wireguard/qemu/init.c |  1 +
 .../selftests/wireguard/qemu/kernel.config    |  2 +
 5 files changed, 50 insertions(+), 48 deletions(-)
tools/testing/selftests/wireguard/netns.sh +4 -7
index e7310d9390f7..d5c85c7494f2 100755
@@ -37,7 +37,7 @@ n2() { pretty 2 "$*"; maybe_exec ip netns exec $netns2 "$@"; }
 ip0() { pretty 0 "ip $*"; ip -n $netns0 "$@"; }
 ip1() { pretty 1 "ip $*"; ip -n $netns1 "$@"; }
 ip2() { pretty 2 "ip $*"; ip -n $netns2 "$@"; }
-sleep() { read -t "$1" -N 0 || true; }
+sleep() { read -t "$1" -N 1 || true; }
 waitiperf() { pretty "${1//*-}" "wait for iperf:5201"; while [[ $(ss -N "$1" -tlp 'sport = 5201') != *iperf3* ]]; do sleep 0.1; done; }
 waitncatudp() { pretty "${1//*-}" "wait for udp:1111"; while [[ $(ss -N "$1" -ulp 'sport = 1111') != *ncat* ]]; do sleep 0.1; done; }
 waitncattcp() { pretty "${1//*-}" "wait for tcp:1111"; while [[ $(ss -N "$1" -tlp 'sport = 1111') != *ncat* ]]; do sleep 0.1; done; }
@@ -294,12 +294,9 @@ ip1 -6 rule add table main suppress_prefixlength 0
 ip1 -4 route add default dev wg0 table 51820
 ip1 -4 rule add not fwmark 51820 table 51820
 ip1 -4 rule add table main suppress_prefixlength 0
-# suppress_prefixlength only got added in 3.12, and we want to support 3.10+.
-if [[ $(ip1 -4 rule show all) == *suppress_prefixlength* ]]; then
-	# Flood the pings instead of sending just one, to trigger routing table reference counting bugs.
-	n1 ping -W 1 -c 100 -f 192.168.99.7
-	n1 ping -W 1 -c 100 -f abab::1111
-fi
+# Flood the pings instead of sending just one, to trigger routing table reference counting bugs.
+n1 ping -W 1 -c 100 -f 192.168.99.7
+n1 ping -W 1 -c 100 -f abab::1111
 
 n0 iptables -t nat -F
 ip0 link del vethrc
tools/testing/selftests/wireguard/qemu/Makefile +42 -40

250 lines not on this page · raw message

tools/testing/selftests/wireguard/qemu/arch/m68k.config +1 -1
index 5381ea10896c..62a15bdb877e 100644
@@ -1,9 +1,9 @@
 CONFIG_MMU=y
+CONFIG_M68KCLASSIC=y
 CONFIG_M68040=y
 CONFIG_MAC=y
 CONFIG_SERIAL_PMACZILOG=y
 CONFIG_SERIAL_PMACZILOG_TTYS=y
 CONFIG_SERIAL_PMACZILOG_CONSOLE=y
-CONFIG_CMDLINE_BOOL=y
 CONFIG_CMDLINE="console=ttyS0 wg.success=ttyS1"
 CONFIG_FRAME_WARN=1024
tools/testing/selftests/wireguard/qemu/init.c +1 -0
index 51e5ddedee88..90bc9813cadc 100644
@@ -21,6 +21,7 @@
 #include <sys/reboot.h>
 #include <sys/utsname.h>
 #include <sys/sendfile.h>
+#include <sys/sysmacros.h>
 #include <linux/random.h>
 #include <linux/version.h>
 
tools/testing/selftests/wireguard/qemu/kernel.config +2 -0
index 9cca30206014..af9323a0b6e0 100644
@@ -39,6 +39,7 @@ CONFIG_PRINTK=y
 CONFIG_KALLSYMS=y
 CONFIG_BUG=y
 CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y
+CONFIG_JUMP_LABEL=y
 CONFIG_EMBEDDED=n
 CONFIG_BASE_FULL=y
 CONFIG_FUTEX=y
@@ -55,6 +56,7 @@ CONFIG_NO_HZ_IDLE=y
 CONFIG_NO_HZ_FULL=n
 CONFIG_HZ_PERIODIC=n
 CONFIG_HIGH_RES_TIMERS=y
+CONFIG_COMPAT_32BIT_TIME=y
 CONFIG_ARCH_RANDOM=y
 CONFIG_FILE_LOCKING=y
 CONFIG_POSIX_TIMERS=y
Signature · 1 line
2.24.1
author maintainer
#2 lore raw

PATCH 2/3 wireguard: queueing: do not account for pfmemalloc when clearing skb header

In reply to Jason A. Donenfeld

Before 8b7008620b84 ("net: Don't copy pfmemalloc flag in __copy_skb_ header()"), the pfmemalloc flag used to be between headers_start and headers_end, which is a region we clear when preparing the packet for encryption/decryption. This is a parameter we certainly want to preserve, which is why 8b7008620b84 moved it out of there. The code here was written in a world before 8b7008620b84, though, where we had to manually account for it. This commit brings things up to speed.

---
 drivers/net/wireguard/queueing.h | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/wireguard/queueing.h +0 -3
index e49a464238fd..fecb559cbdb6 100644
@@ -83,13 +83,10 @@ static inline __be16 wg_skb_examine_untrusted_ip_hdr(struct sk_buff *skb)
 
 static inline void wg_reset_packet(struct sk_buff *skb)
 {
-	const int pfmemalloc = skb->pfmemalloc;
-
 	skb_scrub_packet(skb, true);
 	memset(&skb->headers_start, 0,
 	       offsetof(struct sk_buff, headers_end) -
 		       offsetof(struct sk_buff, headers_start));
-	skb->pfmemalloc = pfmemalloc;
 	skb->queue_mapping = 0;
 	skb->nohdr = 0;
 	skb->peeked = 0;
Signature · 1 line
2.24.1
author maintainer
#3 lore raw

PATCH 3/3 wireguard: socket: mark skbs as not on list when receiving via gro

In reply to Jason A. Donenfeld

Certain drivers will pass gro skbs to udp, at which point the udp driver simply iterates through them and passes them off to encap_rcv, which is where we pick up. At the moment, we're not attempting to coalesce these into bundles, but we also don't want to wind up having cascaded lists of skbs treated separately. The right behavior here, then, is to just mark each incoming one as not on a list. This can be seen in practice, for example, with Qualcomm's rmnet_perf driver.

---
 drivers/net/wireguard/socket.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/wireguard/socket.c +1 -0
index c46256d0d81c..262f3b5c819d 100644
@@ -333,6 +333,7 @@ static int wg_receive(struct sock *sk, struct sk_buff *skb)
 	wg = sk->sk_user_data;
 	if (unlikely(!wg))
 		goto err;
+	skb_mark_not_on_list(skb);
 	wg_packet_receive(wg, skb);
 	return 0;
 
Signature · 1 line
2.24.1
maintainer
#5 lore raw

From: "Jason A. Donenfeld" <[email protected]>
Date: Sat, 4 Jan 2020 22:04:33 -0500

Quoted 3 lines

I think this might have gotten lost in the post-New Years onslaught of patches that have been coming your way in the last few days. So, just a friendly poke.

Check patchwork, you never need to "poke" me.

maintainer
#6 lore raw
In reply to Jason A. Donenfeld

From: "Jason A. Donenfeld" <[email protected]>
Date: Thu, 2 Jan 2020 17:47:48 +0100

Quoted 10 lines

I've been working through some personal notes and also the whole git repo history of the out-of-tree module, looking for places where tradeoffs were made (and subsequently forgotten about) for old kernels. The first two patches in this series clean up those. The first one does so in the self-tests and self-test harness, where we're now able to expand test coverage by a bit, and we're now cooking away tests on every commit to both the wireguard-linux repo and to net-next. The second one removes a workaround for a skbuff.h bug that was fixed long ago. Finally, the last patch in the series fixes in a bug unearthed by newer Qualcomm chipsets running the rmnet_perf driver, which does UDP GRO.

Series applied.

I wonder if, for patch #3, we should have a gro cells helper which just does that list thing and thus makes the situation self documenting.

author maintainer
#7 lore raw
Quoted 1 line · David Miller

Series applied.

Thanks!

Quoted 3 lines

I wonder if, for patch #3, we should have a gro cells helper which just does that list thing and thus makes the situation self documenting.

I was thinking about something along those lines... If you recall from the netdev presentation, wireguard encrypts/decrypts packets on multiple cores and spreads packets out to whatever core is available. In order to improve cache locality and fallout from scheduler latency, the driver opts in to receive gso super packets, splits them up using the function for that, and then encrypts that list as a unit, on a single core. The result achieved is that alike packets are encrypted together and not spread out. For the receive path, however, this is not the case, since encap_recv gives us just one packet at a time. I was thinking of reworking this to add an encap_recv_gro function, or similar, which is passed entire lists.

Right now the implementation of udp_queue_rcv_skb is something along the lines of:

if (!udp_unexpected_gso(skb))

    return encap_recv(skb);
else
    for_each_gso_seg(skb, seg)
        encap_recv(seg);

That bottom part could be split up into:

if (encap_recv_gro)

    encap_recv_gro(skb);
else
    for_each_gso_seg(skb, seg)
        encap_recv(seg);

I still need to look further into this (e.g. why it's "unexpected" as in the "udp_unexpected_gso" function), and I vaguely recall Steffen Klassart working on some similar ideas. But I may post an RFC something to this effect in the coming weeks.

Jason