From nobody Wed Sep 3 02:01:01 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80F1DC38145 for ; Fri, 2 Sep 2022 12:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237274AbiIBMlr (ORCPT ); Fri, 2 Sep 2022 08:41:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237376AbiIBMj2 (ORCPT ); Fri, 2 Sep 2022 08:39:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E74224F18B; Fri, 2 Sep 2022 05:30:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 519B6B82A94; Fri, 2 Sep 2022 12:24:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B55EDC433D7; Fri, 2 Sep 2022 12:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662121445; bh=/VDCL4G/4TRirA5rtUC6oqi0nj8UgZ7kSRGpE9fezhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gQKjTZntKXijCPQVgAF+5dERStJcpmmUjnRCOwF16WgrSiKrLJ6i5EFVCfn5PRl+2 iK04zlV6tHsO1wUuEU+zqkQuPDivvi1aRc0t4hYa4EfDBASgUVjRRQ73K2SeEQUO8r E7lWhytpO+9WZjYa7DCQeytwjaxkKSgshpyvoCKM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Abhishek Shah , Herbert Xu , Steffen Klassert , Sasha Levin Subject: [PATCH 4.19 10/56] af_key: Do not call xfrm_probe_algs in parallel Date: Fri, 2 Sep 2022 14:18:30 +0200 Message-Id: <20220902121400.535624692@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121400.219861128@linuxfoundation.org> References: <20220902121400.219861128@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Herbert Xu [ Upstream commit ba953a9d89a00c078b85f4b190bc1dde66fe16b5 ] 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 Fixes: 283bc9f35bbb ("xfrm: Namespacify xfrm state/policy locks") Signed-off-by: Herbert Xu Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/key/af_key.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/key/af_key.c b/net/key/af_key.c index af67e0d265c05..337c6bc8211ed 100644 --- a/net/key/af_key.c +++ b/net/key/af_key.c @@ -1707,9 +1707,12 @@ static int pfkey_register(struct sock *sk, struct sk= _buff *skb, const struct sad pfk->registered |=3D (1<sadb_msg_satype); } =20 + mutex_lock(&pfkey_mutex); xfrm_probe_algs(); =20 supp_skb =3D compose_sadb_supported(hdr, GFP_KERNEL | __GFP_ZERO); + mutex_unlock(&pfkey_mutex); + if (!supp_skb) { if (hdr->sadb_msg_satype !=3D SADB_SATYPE_UNSPEC) pfk->registered &=3D ~(1<sadb_msg_satype); --=20 2.35.1