1 |
From fd4bc5d9d5c2f39b406cde4ca4dcc2e5c08a06b0 Mon Sep 17 00:00:00 2001 |
2 |
From: Sasha Levin <sashal@kernel.org> |
3 |
Date: Thu, 4 Aug 2022 18:03:46 +0800 |
4 |
Subject: af_key: Do not call xfrm_probe_algs in parallel |
5 |
|
6 |
From: Herbert Xu <herbert@gondor.apana.org.au> |
7 |
|
8 |
[ Upstream commit ba953a9d89a00c078b85f4b190bc1dde66fe16b5 ] |
9 |
|
10 |
When namespace support was added to xfrm/afkey, it caused the |
11 |
previously single-threaded call to xfrm_probe_algs to become |
12 |
multi-threaded. This is buggy and needs to be fixed with a mutex. |
13 |
|
14 |
Reported-by: Abhishek Shah <abhishek.shah@columbia.edu> |
15 |
Fixes: 283bc9f35bbb ("xfrm: Namespacify xfrm state/policy locks") |
16 |
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> |
17 |
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com> |
18 |
Signed-off-by: Sasha Levin <sashal@kernel.org> |
19 |
--- |
20 |
net/key/af_key.c | 3 +++ |
21 |
1 file changed, 3 insertions(+) |
22 |
|
23 |
diff --git a/net/key/af_key.c b/net/key/af_key.c |
24 |
index fb16d7c4e1b8d..20e73643b9c89 100644 |
25 |
--- a/net/key/af_key.c |
26 |
+++ b/net/key/af_key.c |
27 |
@@ -1697,9 +1697,12 @@ static int pfkey_register(struct sock *sk, struct sk_buff *skb, const struct sad |
28 |
pfk->registered |= (1<<hdr->sadb_msg_satype); |
29 |
} |
30 |
|
31 |
+ mutex_lock(&pfkey_mutex); |
32 |
xfrm_probe_algs(); |
33 |
|
34 |
supp_skb = compose_sadb_supported(hdr, GFP_KERNEL | __GFP_ZERO); |
35 |
+ mutex_unlock(&pfkey_mutex); |
36 |
+ |
37 |
if (!supp_skb) { |
38 |
if (hdr->sadb_msg_satype != SADB_SATYPE_UNSPEC) |
39 |
pfk->registered &= ~(1<<hdr->sadb_msg_satype); |
40 |
-- |
41 |
2.35.1 |
42 |
|