All of lore.kernel.org
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: syzbot <syzbot+1e9af9185d8850e2c2fa@syzkaller.appspotmail.com>
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	pabeni@redhat.com, steffen.klassert@secunet.com,
	syzkaller-bugs@googlegroups.com
Subject: [PATCH] af_key: Fix send_acquire race with pfkey_register
Date: Mon, 24 Oct 2022 13:10:34 +0800	[thread overview]
Message-ID: <Y1YeSj2vwPvRAW61@gondor.apana.org.au> (raw)
In-Reply-To: <000000000000fd9a4005ebbeac67@google.com>

With name space support, it is possible for a pfkey_register to
occur in the middle of a send_acquire, thus changing the number
of supported algorithms.

This can be fixed by taking a mutex to make it single-threaded
again.

Reported-by: syzbot+1e9af9185d8850e2c2fa@syzkaller.appspotmail.com
Fixes: 283bc9f35bbb ("xfrm: Namespacify xfrm state/policy locks")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/net/key/af_key.c b/net/key/af_key.c
index c85df5b958d2..4ceef96fef57 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -3160,6 +3160,7 @@ static int pfkey_send_acquire(struct xfrm_state *x, struct xfrm_tmpl *t, struct
 		(sockaddr_size * 2) +
 		sizeof(struct sadb_x_policy);
 
+	mutex_lock(&pfkey_mutex);
 	if (x->id.proto == IPPROTO_AH)
 		size += count_ah_combs(t);
 	else if (x->id.proto == IPPROTO_ESP)
@@ -3171,8 +3172,10 @@ static int pfkey_send_acquire(struct xfrm_state *x, struct xfrm_tmpl *t, struct
 	}
 
 	skb =  alloc_skb(size + 16, GFP_ATOMIC);
-	if (skb == NULL)
+	if (skb == NULL) {
+		mutex_unlock(&pfkey_mutex);
 		return -ENOMEM;
+	}
 
 	hdr = skb_put(skb, sizeof(struct sadb_msg));
 	hdr->sadb_msg_version = PF_KEY_V2;
@@ -3228,6 +3231,7 @@ static int pfkey_send_acquire(struct xfrm_state *x, struct xfrm_tmpl *t, struct
 		dump_ah_combs(skb, t);
 	else if (x->id.proto == IPPROTO_ESP)
 		dump_esp_combs(skb, t);
+	mutex_unlock(&pfkey_mutex);
 
 	/* security context */
 	if (xfrm_ctx) {
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

  parent reply	other threads:[~2022-10-24  5:10 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-24  2:37 [syzbot] kernel BUG in warn_crc32c_csum_combine syzbot
2022-10-24  2:49 ` Eric Dumazet
2022-10-24  5:01   ` Herbert Xu
2022-10-24  5:10 ` Herbert Xu [this message]
2022-10-24  5:21   ` [PATCH] af_key: Fix send_acquire race with pfkey_register Eric Dumazet
2022-10-24  6:06     ` [v2 PATCH] " Herbert Xu
2022-10-24  6:31       ` Eric Dumazet
2022-10-25  5:46         ` Herbert Xu
2022-10-24  7:20       ` Sabrina Dubroca
2022-10-25  6:06         ` [v3 " Herbert Xu
2022-10-26 13:38           ` Sabrina Dubroca
2022-10-27  3:42             ` Herbert Xu
2022-10-27  3:45               ` Eric Dumazet
2022-10-27  3:55                 ` Herbert Xu
2022-10-28 11:26                 ` Steffen Klassert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y1YeSj2vwPvRAW61@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=steffen.klassert@secunet.com \
    --cc=syzbot+1e9af9185d8850e2c2fa@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.