kernel-5.4: backport latest patches for wireguard
[openwrt/openwrt.git] / target / linux / generic / backport-5.4 / 080-wireguard-0132-wireguard-allowedips-initialize-list-head-in-selftes.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: "Jason A. Donenfeld" <Jason@zx2c4.com>
3 Date: Fri, 4 Jun 2021 17:17:35 +0200
4 Subject: [PATCH] wireguard: allowedips: initialize list head in selftest
5
6 commit 46cfe8eee285cde465b420637507884551f5d7ca upstream.
7
8 The randomized trie tests weren't initializing the dummy peer list head,
9 resulting in a NULL pointer dereference when used. Fix this by
10 initializing it in the randomized trie test, just like we do for the
11 static unit test.
12
13 While we're at it, all of the other strings like this have the word
14 "self-test", so add it to the missing place here.
15
16 Fixes: e7096c131e51 ("net: WireGuard secure network tunnel")
17 Cc: stable@vger.kernel.org
18 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
19 Signed-off-by: David S. Miller <davem@davemloft.net>
20 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
21 ---
22 drivers/net/wireguard/selftest/allowedips.c | 3 ++-
23 1 file changed, 2 insertions(+), 1 deletion(-)
24
25 --- a/drivers/net/wireguard/selftest/allowedips.c
26 +++ b/drivers/net/wireguard/selftest/allowedips.c
27 @@ -296,6 +296,7 @@ static __init bool randomized_test(void)
28 goto free;
29 }
30 kref_init(&peers[i]->refcount);
31 + INIT_LIST_HEAD(&peers[i]->allowedips_list);
32 }
33
34 mutex_lock(&mutex);
35 @@ -333,7 +334,7 @@ static __init bool randomized_test(void)
36 if (wg_allowedips_insert_v4(&t,
37 (struct in_addr *)mutated,
38 cidr, peer, &mutex) < 0) {
39 - pr_err("allowedips random malloc: FAIL\n");
40 + pr_err("allowedips random self-test malloc: FAIL\n");
41 goto free_locked;
42 }
43 if (horrible_allowedips_insert_v4(&h,