Skip to content

Commit 82d81bb

Browse files
committed
Merge branch 'wireguard-fixes'
Jason A. Donenfeld says: ==================== wireguard fixes for 5.6-rc2 Here are four fixes for wireguard collected since rc1: 1) Some small cleanups to the test suite to help massively parallel builds. 2) A change in how we reset our load calculation to avoid a more expensive comparison, suggested by Matt Dunwoodie. 3) I've been loading more and more of wireguard's surface into syzkaller, trying to get our coverage as complete as possible, leading in this case to a fix for mtu=0 devices. 4) A removal of superfluous code, pointed out by Eric Dumazet. v2 fixes a logical problem in the patch for (3) pointed out by Eric Dumazet. v3 replaces some non-obvious bitmath in (3) with a more obvious expression, and adds patch (4). ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents b6e4a1a + 1fbc33b commit 82d81bb

File tree

5 files changed

+34
-35
lines changed

5 files changed

+34
-35
lines changed

drivers/net/wireguard/device.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ static void wg_setup(struct net_device *dev)
258258
enum { WG_NETDEV_FEATURES = NETIF_F_HW_CSUM | NETIF_F_RXCSUM |
259259
NETIF_F_SG | NETIF_F_GSO |
260260
NETIF_F_GSO_SOFTWARE | NETIF_F_HIGHDMA };
261+
const int overhead = MESSAGE_MINIMUM_LENGTH + sizeof(struct udphdr) +
262+
max(sizeof(struct ipv6hdr), sizeof(struct iphdr));
261263

262264
dev->netdev_ops = &netdev_ops;
263265
dev->hard_header_len = 0;
@@ -271,9 +273,8 @@ static void wg_setup(struct net_device *dev)
271273
dev->features |= WG_NETDEV_FEATURES;
272274
dev->hw_features |= WG_NETDEV_FEATURES;
273275
dev->hw_enc_features |= WG_NETDEV_FEATURES;
274-
dev->mtu = ETH_DATA_LEN - MESSAGE_MINIMUM_LENGTH -
275-
sizeof(struct udphdr) -
276-
max(sizeof(struct ipv6hdr), sizeof(struct iphdr));
276+
dev->mtu = ETH_DATA_LEN - overhead;
277+
dev->max_mtu = round_down(INT_MAX, MESSAGE_PADDING_MULTIPLE) - overhead;
277278

278279
SET_NETDEV_DEVTYPE(dev, &device_type);
279280

drivers/net/wireguard/receive.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,13 @@ static void wg_receive_handshake_packet(struct wg_device *wg,
118118

119119
under_load = skb_queue_len(&wg->incoming_handshakes) >=
120120
MAX_QUEUED_INCOMING_HANDSHAKES / 8;
121-
if (under_load)
121+
if (under_load) {
122122
last_under_load = ktime_get_coarse_boottime_ns();
123-
else if (last_under_load)
123+
} else if (last_under_load) {
124124
under_load = !wg_birthdate_has_expired(last_under_load, 1);
125+
if (!under_load)
126+
last_under_load = 0;
127+
}
125128
mac_state = wg_cookie_validate_packet(&wg->cookie_checker, skb,
126129
under_load);
127130
if ((under_load && mac_state == VALID_MAC_WITH_COOKIE) ||

drivers/net/wireguard/send.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,22 @@ static void keep_key_fresh(struct wg_peer *peer)
143143

144144
static unsigned int calculate_skb_padding(struct sk_buff *skb)
145145
{
146+
unsigned int padded_size, last_unit = skb->len;
147+
148+
if (unlikely(!PACKET_CB(skb)->mtu))
149+
return ALIGN(last_unit, MESSAGE_PADDING_MULTIPLE) - last_unit;
150+
146151
/* We do this modulo business with the MTU, just in case the networking
147152
* layer gives us a packet that's bigger than the MTU. In that case, we
148153
* wouldn't want the final subtraction to overflow in the case of the
149-
* padded_size being clamped.
154+
* padded_size being clamped. Fortunately, that's very rarely the case,
155+
* so we optimize for that not happening.
150156
*/
151-
unsigned int last_unit = skb->len % PACKET_CB(skb)->mtu;
152-
unsigned int padded_size = ALIGN(last_unit, MESSAGE_PADDING_MULTIPLE);
157+
if (unlikely(last_unit > PACKET_CB(skb)->mtu))
158+
last_unit %= PACKET_CB(skb)->mtu;
153159

154-
if (padded_size > PACKET_CB(skb)->mtu)
155-
padded_size = PACKET_CB(skb)->mtu;
160+
padded_size = min(PACKET_CB(skb)->mtu,
161+
ALIGN(last_unit, MESSAGE_PADDING_MULTIPLE));
156162
return padded_size - last_unit;
157163
}
158164

drivers/net/wireguard/socket.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,6 @@ void wg_socket_reinit(struct wg_device *wg, struct sock *new4,
432432
wg->incoming_port = ntohs(inet_sk(new4)->inet_sport);
433433
mutex_unlock(&wg->socket_update_lock);
434434
synchronize_rcu();
435-
synchronize_net();
436435
sock_free(old4);
437436
sock_free(old6);
438437
}

tools/testing/selftests/wireguard/qemu/Makefile

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,17 @@ endef
3838
define file_download =
3939
$(DISTFILES_PATH)/$(1):
4040
mkdir -p $(DISTFILES_PATH)
41-
flock -x $$@.lock -c '[ -f $$@ ] && exit 0; wget -O $$@.tmp $(MIRROR)$(1) || wget -O $$@.tmp $(2)$(1) || rm -f $$@.tmp'
42-
if echo "$(3) $$@.tmp" | sha256sum -c -; then mv $$@.tmp $$@; else rm -f $$@.tmp; exit 71; fi
41+
flock -x $$@.lock -c '[ -f $$@ ] && exit 0; wget -O $$@.tmp $(MIRROR)$(1) || wget -O $$@.tmp $(2)$(1) || rm -f $$@.tmp; [ -f $$@.tmp ] || exit 1; if echo "$(3) $$@.tmp" | sha256sum -c -; then mv $$@.tmp $$@; else rm -f $$@.tmp; exit 71; fi'
4342
endef
4443

4544
$(eval $(call tar_download,MUSL,musl,1.1.24,.tar.gz,https://www.musl-libc.org/releases/,1370c9a812b2cf2a7d92802510cca0058cc37e66a7bedd70051f0a34015022a3))
46-
$(eval $(call tar_download,LIBMNL,libmnl,1.0.4,.tar.bz2,https://www.netfilter.org/projects/libmnl/files/,171f89699f286a5854b72b91d06e8f8e3683064c5901fb09d954a9ab6f551f81))
4745
$(eval $(call tar_download,IPERF,iperf,3.7,.tar.gz,https://downloads.es.net/pub/iperf/,d846040224317caf2f75c843d309a950a7db23f9b44b94688ccbe557d6d1710c))
4846
$(eval $(call tar_download,BASH,bash,5.0,.tar.gz,https://ftp.gnu.org/gnu/bash/,b4a80f2ac66170b2913efbfb9f2594f1f76c7b1afd11f799e22035d63077fb4d))
4947
$(eval $(call tar_download,IPROUTE2,iproute2,5.4.0,.tar.xz,https://www.kernel.org/pub/linux/utils/net/iproute2/,fe97aa60a0d4c5ac830be18937e18dc3400ca713a33a89ad896ff1e3d46086ae))
5048
$(eval $(call tar_download,IPTABLES,iptables,1.8.4,.tar.bz2,https://www.netfilter.org/projects/iptables/files/,993a3a5490a544c2cbf2ef15cf7e7ed21af1845baf228318d5c36ef8827e157c))
5149
$(eval $(call tar_download,NMAP,nmap,7.80,.tar.bz2,https://nmap.org/dist/,fcfa5a0e42099e12e4bf7a68ebe6fde05553383a682e816a7ec9256ab4773faa))
5250
$(eval $(call tar_download,IPUTILS,iputils,s20190709,.tar.gz,https://github.com/iputils/iputils/archive/s20190709.tar.gz/#,a15720dd741d7538dd2645f9f516d193636ae4300ff7dbc8bfca757bf166490a))
53-
$(eval $(call tar_download,WIREGUARD_TOOLS,wireguard-tools,1.0.20191226,.tar.xz,https://git.zx2c4.com/wireguard-tools/snapshot/,aa8af0fdc9872d369d8c890a84dbc2a2466b55795dccd5b47721b2d97644b04f))
51+
$(eval $(call tar_download,WIREGUARD_TOOLS,wireguard-tools,1.0.20200206,.tar.xz,https://git.zx2c4.com/wireguard-tools/snapshot/,f5207248c6a3c3e3bfc9ab30b91c1897b00802ed861e1f9faaed873366078c64))
5452

5553
KERNEL_BUILD_PATH := $(BUILD_PATH)/kernel$(if $(findstring yes,$(DEBUG_KERNEL)),-debug)
5654
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
@@ -295,21 +293,13 @@ $(IPERF_PATH)/src/iperf3: | $(IPERF_PATH)/.installed $(USERSPACE_DEPS)
295293
$(MAKE) -C $(IPERF_PATH)
296294
$(STRIP) -s $@
297295

298-
$(LIBMNL_PATH)/.installed: $(LIBMNL_TAR)
299-
flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
300-
touch $@
301-
302-
$(LIBMNL_PATH)/src/.libs/libmnl.a: | $(LIBMNL_PATH)/.installed $(USERSPACE_DEPS)
303-
cd $(LIBMNL_PATH) && ./configure --prefix=/ $(CROSS_COMPILE_FLAG) --enable-static --disable-shared
304-
$(MAKE) -C $(LIBMNL_PATH)
305-
sed -i 's:prefix=.*:prefix=$(LIBMNL_PATH):' $(LIBMNL_PATH)/libmnl.pc
306-
307296
$(WIREGUARD_TOOLS_PATH)/.installed: $(WIREGUARD_TOOLS_TAR)
297+
mkdir -p $(BUILD_PATH)
308298
flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
309299
touch $@
310300

311-
$(WIREGUARD_TOOLS_PATH)/src/wg: | $(WIREGUARD_TOOLS_PATH)/.installed $(LIBMNL_PATH)/src/.libs/libmnl.a $(USERSPACE_DEPS)
312-
LDFLAGS="$(LDFLAGS) -L$(LIBMNL_PATH)/src/.libs" $(MAKE) -C $(WIREGUARD_TOOLS_PATH)/src LIBMNL_CFLAGS="-I$(LIBMNL_PATH)/include" LIBMNL_LDLIBS="-lmnl" wg
301+
$(WIREGUARD_TOOLS_PATH)/src/wg: | $(WIREGUARD_TOOLS_PATH)/.installed $(USERSPACE_DEPS)
302+
$(MAKE) -C $(WIREGUARD_TOOLS_PATH)/src wg
313303
$(STRIP) -s $@
314304

315305
$(BUILD_PATH)/init: init.c | $(USERSPACE_DEPS)
@@ -340,26 +330,26 @@ $(BASH_PATH)/bash: | $(BASH_PATH)/.installed $(USERSPACE_DEPS)
340330
$(IPROUTE2_PATH)/.installed: $(IPROUTE2_TAR)
341331
mkdir -p $(BUILD_PATH)
342332
flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
343-
printf 'CC:=$(CC)\nPKG_CONFIG:=pkg-config\nTC_CONFIG_XT:=n\nTC_CONFIG_ATM:=n\nTC_CONFIG_IPSET:=n\nIP_CONFIG_SETNS:=y\nHAVE_ELF:=n\nHAVE_MNL:=y\nHAVE_BERKELEY_DB:=n\nHAVE_LATEX:=n\nHAVE_PDFLATEX:=n\nCFLAGS+=-DHAVE_SETNS -DHAVE_LIBMNL -I$(LIBMNL_PATH)/include\nLDLIBS+=-lmnl' > $(IPROUTE2_PATH)/config.mk
333+
printf 'CC:=$(CC)\nPKG_CONFIG:=pkg-config\nTC_CONFIG_XT:=n\nTC_CONFIG_ATM:=n\nTC_CONFIG_IPSET:=n\nIP_CONFIG_SETNS:=y\nHAVE_ELF:=n\nHAVE_MNL:=n\nHAVE_BERKELEY_DB:=n\nHAVE_LATEX:=n\nHAVE_PDFLATEX:=n\nCFLAGS+=-DHAVE_SETNS\n' > $(IPROUTE2_PATH)/config.mk
344334
printf 'lib: snapshot\n\t$$(MAKE) -C lib\nip/ip: lib\n\t$$(MAKE) -C ip ip\nmisc/ss: lib\n\t$$(MAKE) -C misc ss\n' >> $(IPROUTE2_PATH)/Makefile
345335
touch $@
346336

347-
$(IPROUTE2_PATH)/ip/ip: | $(IPROUTE2_PATH)/.installed $(LIBMNL_PATH)/src/.libs/libmnl.a $(USERSPACE_DEPS)
348-
LDFLAGS="$(LDFLAGS) -L$(LIBMNL_PATH)/src/.libs" PKG_CONFIG_LIBDIR="$(LIBMNL_PATH)" $(MAKE) -C $(IPROUTE2_PATH) PREFIX=/ ip/ip
349-
$(STRIP) -s $(IPROUTE2_PATH)/ip/ip
337+
$(IPROUTE2_PATH)/ip/ip: | $(IPROUTE2_PATH)/.installed $(USERSPACE_DEPS)
338+
$(MAKE) -C $(IPROUTE2_PATH) PREFIX=/ ip/ip
339+
$(STRIP) -s $@
350340

351-
$(IPROUTE2_PATH)/misc/ss: | $(IPROUTE2_PATH)/.installed $(LIBMNL_PATH)/src/.libs/libmnl.a $(USERSPACE_DEPS)
352-
LDFLAGS="$(LDFLAGS) -L$(LIBMNL_PATH)/src/.libs" PKG_CONFIG_LIBDIR="$(LIBMNL_PATH)" $(MAKE) -C $(IPROUTE2_PATH) PREFIX=/ misc/ss
353-
$(STRIP) -s $(IPROUTE2_PATH)/misc/ss
341+
$(IPROUTE2_PATH)/misc/ss: | $(IPROUTE2_PATH)/.installed $(USERSPACE_DEPS)
342+
$(MAKE) -C $(IPROUTE2_PATH) PREFIX=/ misc/ss
343+
$(STRIP) -s $@
354344

355345
$(IPTABLES_PATH)/.installed: $(IPTABLES_TAR)
356346
mkdir -p $(BUILD_PATH)
357347
flock -s $<.lock tar -C $(BUILD_PATH) -xf $<
358348
sed -i -e "/nfnetlink=[01]/s:=[01]:=0:" -e "/nfconntrack=[01]/s:=[01]:=0:" $(IPTABLES_PATH)/configure
359349
touch $@
360350

361-
$(IPTABLES_PATH)/iptables/xtables-legacy-multi: | $(IPTABLES_PATH)/.installed $(LIBMNL_PATH)/src/.libs/libmnl.a $(USERSPACE_DEPS)
362-
cd $(IPTABLES_PATH) && PKG_CONFIG_LIBDIR="$(LIBMNL_PATH)" ./configure --prefix=/ $(CROSS_COMPILE_FLAG) --enable-static --disable-shared --disable-nftables --disable-bpf-compiler --disable-nfsynproxy --disable-libipq --with-kernel=$(BUILD_PATH)/include
351+
$(IPTABLES_PATH)/iptables/xtables-legacy-multi: | $(IPTABLES_PATH)/.installed $(USERSPACE_DEPS)
352+
cd $(IPTABLES_PATH) && ./configure --prefix=/ $(CROSS_COMPILE_FLAG) --enable-static --disable-shared --disable-nftables --disable-bpf-compiler --disable-nfsynproxy --disable-libipq --disable-connlabel --with-kernel=$(BUILD_PATH)/include
363353
$(MAKE) -C $(IPTABLES_PATH)
364354
$(STRIP) -s $@
365355

0 commit comments

Comments
 (0)