Skip to content

Commit 7bb77d4

Browse files
committed
Merge branch 'wg-fixes'
Jason A. Donenfeld says: ==================== wireguard fixes for 5.6-rc1 Here are fixes for WireGuard before 5.6-rc1 is tagged. It includes: 1) A fix for a UaF (caused by kmalloc failing during a very small allocation) that syzkaller found, from Eric Dumazet. 2) A fix for a deadlock that syzkaller found, along with an additional selftest to ensure that the bug fix remains correct, from me. 3) Two little fixes/cleanups to the selftests from Krzysztof Kozlowski and me. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 52b5ae5 + 88f404a commit 7bb77d4

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

drivers/net/wireguard/allowedips.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ static int add(struct allowedips_node __rcu **trie, u8 bits, const u8 *key,
263263
} else {
264264
node = kzalloc(sizeof(*node), GFP_KERNEL);
265265
if (unlikely(!node)) {
266+
list_del(&newnode->peer_list);
266267
kfree(newnode);
267268
return -ENOMEM;
268269
}

drivers/net/wireguard/netlink.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,8 @@ static int wg_set_device(struct sk_buff *skb, struct genl_info *info)
569569
private_key);
570570
list_for_each_entry_safe(peer, temp, &wg->peer_list,
571571
peer_list) {
572-
if (wg_noise_precompute_static_static(peer))
573-
wg_noise_expire_current_peer_keypairs(peer);
574-
else
575-
wg_peer_remove(peer);
572+
BUG_ON(!wg_noise_precompute_static_static(peer));
573+
wg_noise_expire_current_peer_keypairs(peer);
576574
}
577575
wg_cookie_checker_precompute_device_keys(&wg->cookie_checker);
578576
up_write(&wg->static_identity.lock);

drivers/net/wireguard/noise.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,21 @@ void __init wg_noise_init(void)
4646
/* Must hold peer->handshake.static_identity->lock */
4747
bool wg_noise_precompute_static_static(struct wg_peer *peer)
4848
{
49-
bool ret = true;
49+
bool ret;
5050

5151
down_write(&peer->handshake.lock);
52-
if (peer->handshake.static_identity->has_identity)
52+
if (peer->handshake.static_identity->has_identity) {
5353
ret = curve25519(
5454
peer->handshake.precomputed_static_static,
5555
peer->handshake.static_identity->static_private,
5656
peer->handshake.remote_static);
57-
else
57+
} else {
58+
u8 empty[NOISE_PUBLIC_KEY_LEN] = { 0 };
59+
60+
ret = curve25519(empty, empty, peer->handshake.remote_static);
5861
memset(peer->handshake.precomputed_static_static, 0,
5962
NOISE_PUBLIC_KEY_LEN);
63+
}
6064
up_write(&peer->handshake.lock);
6165
return ret;
6266
}

tools/testing/selftests/wireguard/netns.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ ip0() { pretty 0 "ip $*"; ip -n $netns0 "$@"; }
3838
ip1() { pretty 1 "ip $*"; ip -n $netns1 "$@"; }
3939
ip2() { pretty 2 "ip $*"; ip -n $netns2 "$@"; }
4040
sleep() { read -t "$1" -N 1 || true; }
41-
waitiperf() { pretty "${1//*-}" "wait for iperf:5201"; while [[ $(ss -N "$1" -tlp 'sport = 5201') != *iperf3* ]]; do sleep 0.1; done; }
42-
waitncatudp() { pretty "${1//*-}" "wait for udp:1111"; while [[ $(ss -N "$1" -ulp 'sport = 1111') != *ncat* ]]; do sleep 0.1; done; }
43-
waitncattcp() { pretty "${1//*-}" "wait for tcp:1111"; while [[ $(ss -N "$1" -tlp 'sport = 1111') != *ncat* ]]; do sleep 0.1; done; }
41+
waitiperf() { pretty "${1//*-}" "wait for iperf:5201 pid $2"; while [[ $(ss -N "$1" -tlpH 'sport = 5201') != *\"iperf3\",pid=$2,fd=* ]]; do sleep 0.1; done; }
42+
waitncatudp() { pretty "${1//*-}" "wait for udp:1111 pid $2"; while [[ $(ss -N "$1" -ulpH 'sport = 1111') != *\"ncat\",pid=$2,fd=* ]]; do sleep 0.1; done; }
4443
waitiface() { pretty "${1//*-}" "wait for $2 to come up"; ip netns exec "$1" bash -c "while [[ \$(< \"/sys/class/net/$2/operstate\") != up ]]; do read -t .1 -N 0 || true; done;"; }
4544

4645
cleanup() {
@@ -119,22 +118,22 @@ tests() {
119118

120119
# TCP over IPv4
121120
n2 iperf3 -s -1 -B 192.168.241.2 &
122-
waitiperf $netns2
121+
waitiperf $netns2 $!
123122
n1 iperf3 -Z -t 3 -c 192.168.241.2
124123

125124
# TCP over IPv6
126125
n1 iperf3 -s -1 -B fd00::1 &
127-
waitiperf $netns1
126+
waitiperf $netns1 $!
128127
n2 iperf3 -Z -t 3 -c fd00::1
129128

130129
# UDP over IPv4
131130
n1 iperf3 -s -1 -B 192.168.241.1 &
132-
waitiperf $netns1
131+
waitiperf $netns1 $!
133132
n2 iperf3 -Z -t 3 -b 0 -u -c 192.168.241.1
134133

135134
# UDP over IPv6
136135
n2 iperf3 -s -1 -B fd00::2 &
137-
waitiperf $netns2
136+
waitiperf $netns2 $!
138137
n1 iperf3 -Z -t 3 -b 0 -u -c fd00::2
139138
}
140139

@@ -207,7 +206,7 @@ n1 ping -W 1 -c 1 192.168.241.2
207206
n1 wg set wg0 peer "$pub2" allowed-ips 192.168.241.0/24
208207
exec 4< <(n1 ncat -l -u -p 1111)
209208
ncat_pid=$!
210-
waitncatudp $netns1
209+
waitncatudp $netns1 $ncat_pid
211210
n2 ncat -u 192.168.241.1 1111 <<<"X"
212211
read -r -N 1 -t 1 out <&4 && [[ $out == "X" ]]
213212
kill $ncat_pid
@@ -216,7 +215,7 @@ n1 wg set wg0 peer "$more_specific_key" allowed-ips 192.168.241.2/32
216215
n2 wg set wg0 listen-port 9997
217216
exec 4< <(n1 ncat -l -u -p 1111)
218217
ncat_pid=$!
219-
waitncatudp $netns1
218+
waitncatudp $netns1 $ncat_pid
220219
n2 ncat -u 192.168.241.1 1111 <<<"X"
221220
! read -r -N 1 -t 1 out <&4 || false
222221
kill $ncat_pid
@@ -516,6 +515,12 @@ n0 wg set wg0 peer "$pub2" allowed-ips 0.0.0.0/0,10.0.0.0/8,100.0.0.0/10,172.16.
516515
n0 wg set wg0 peer "$pub2" allowed-ips 0.0.0.0/0
517516
n0 wg set wg0 peer "$pub2" allowed-ips ::/0,1700::/111,5000::/4,e000::/37,9000::/75
518517
n0 wg set wg0 peer "$pub2" allowed-ips ::/0
518+
n0 wg set wg0 peer "$pub2" remove
519+
low_order_points=( AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= 4Ot6fDtBuK4WVuP68Z/EatoJjeucMrH9hmIFFl9JuAA= X5yVvKNQjCSx0LFVnIPvWwREXMRYHI6G2CJO3dCfEVc= 7P///////////////////////////////////////38= 7f///////////////////////////////////////38= 7v///////////////////////////////////////38= )
520+
n0 wg set wg0 private-key /dev/null ${low_order_points[@]/#/peer }
521+
[[ -z $(n0 wg show wg0 peers) ]]
522+
n0 wg set wg0 private-key <(echo "$key1") ${low_order_points[@]/#/peer }
523+
[[ -z $(n0 wg show wg0 peers) ]]
519524
ip0 link del wg0
520525

521526
declare -A objects

tools/testing/selftests/wireguard/qemu/debug.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
CONFIG_LOCALVERSION="-debug"
2-
CONFIG_ENABLE_WARN_DEPRECATED=y
32
CONFIG_ENABLE_MUST_CHECK=y
43
CONFIG_FRAME_POINTER=y
54
CONFIG_STACK_VALIDATION=y

0 commit comments

Comments
 (0)