diff mbox series

[SRU,Focal] af_key: Do not call xfrm_probe_algs in parallel

Message ID 20220920200515.132111-3-cengiz.can@canonical.com
State New
Headers show
Series [SRU,Focal] af_key: Do not call xfrm_probe_algs in parallel | expand

Commit Message

Cengiz Can Sept. 20, 2022, 8:05 p.m. UTC
From: Herbert Xu <herbert@gondor.apana.org.au>

When namespace support was added to xfrm/afkey, it caused the
previously single-threaded call to xfrm_probe_algs to become
multi-threaded.  This is buggy and needs to be fixed with a mutex.

Reported-by: Abhishek Shah <abhishek.shah@columbia.edu>
Fixes: 283bc9f35bbb ("xfrm: Namespacify xfrm state/policy locks")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
CVE-2022-3028
(cherry picked from commit ba953a9d89a00c078b85f4b190bc1dde66fe16b5)
Signed-off-by: Cengiz Can <cengiz.can@canonical.com>
---
 net/key/af_key.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/net/key/af_key.c b/net/key/af_key.c
index d8bceb8cf7569..e2d68b68c0e98 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -1701,9 +1701,12 @@  static int pfkey_register(struct sock *sk, struct sk_buff *skb, const struct sad
 		pfk->registered |= (1<<hdr->sadb_msg_satype);
 	}
 
+	mutex_lock(&pfkey_mutex);
 	xfrm_probe_algs();
 
 	supp_skb = compose_sadb_supported(hdr, GFP_KERNEL | __GFP_ZERO);
+	mutex_unlock(&pfkey_mutex);
+
 	if (!supp_skb) {
 		if (hdr->sadb_msg_satype != SADB_SATYPE_UNSPEC)
 			pfk->registered &= ~(1<<hdr->sadb_msg_satype);