From mboxrd@z Thu Jan 1 00:00:00 1970 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 503F5C41535 for ; Sun, 9 Oct 2022 22:35:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232949AbiJIWd7 (ORCPT ); Sun, 9 Oct 2022 18:33:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232042AbiJIWaT (ORCPT ); Sun, 9 Oct 2022 18:30:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6F56FD0B; Sun, 9 Oct 2022 15:19:45 -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 60832B80D33; Sun, 9 Oct 2022 22:19:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF387C433C1; Sun, 9 Oct 2022 22:19:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665353984; bh=KAnZS9WcwRk8bgKwx6yLV74+eQUR9dCSvwpUrV+4pIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cGNrEkilKJAykfYGO1eDrgJ0MCNqCFMpQWyMGMFwoMRM2jUxwpRVGwbBY8OCPE3l1 0ekGokuolmf1tFoYhF6FHeOdB6QQuLBw1EmMhXM9iMLd4IQWA1exc0GMuIgDlC4v33 swu0lgmdoA7cZdoM+jbV1W4lLfBb2oiHWq2/Rm5yd1/A7HXjsj6Uqvsmpd2DMTVoMf UmOLSQpBeG7bxqx+PiyA2/ppO2D08HE+hNE8LuU2T1Mnn6T/DRDQkN33PNrgW3X5w4 EDy1eblzkGaS3i1GRiVso/JYBuJjR1mqOmrktKZlRfVxwgniepTBg1wpAG/OlCscAa PUvdUYJM3uP2A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jiri Pirko , Vikas Gupta , Jakub Kicinski , Sasha Levin , davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, jacob.e.keller@intel.com, johannes@sipsolutions.net, nicolas.dichtel@6wind.com, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 10/46] genetlink: hold read cb_lock during iteration of genl_fam_idr in genl_bind() Date: Sun, 9 Oct 2022 18:18:35 -0400 Message-Id: <20221009221912.1217372-10-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009221912.1217372-1-sashal@kernel.org> References: <20221009221912.1217372-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Pirko [ Upstream commit 8f1948bdcf2fb50e9092c0950c3c9ac591382101 ] In genl_bind(), currently genl_lock and write cb_lock are taken for iteration of genl_fam_idr and processing of static values stored in struct genl_family. Take just read cb_lock for this task as it is sufficient to guard the idr and the struct against concurrent genl_register/unregister_family() calls. This will allow to run genl command processing in genl_rcv() and mnl_socket_setsockopt(.., NETLINK_ADD_MEMBERSHIP, ..) in parallel. Reported-by: Vikas Gupta Signed-off-by: Jiri Pirko Link: https://lore.kernel.org/r/20220825081940.1283335-1-jiri@resnulli.us Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/netlink/genetlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c index 57010927e20a..76aed0571e3a 100644 --- a/net/netlink/genetlink.c +++ b/net/netlink/genetlink.c @@ -1362,7 +1362,7 @@ static int genl_bind(struct net *net, int group) unsigned int id; int ret = 0; - genl_lock_all(); + down_read(&cb_lock); idr_for_each_entry(&genl_fam_idr, family, id) { const struct genl_multicast_group *grp; @@ -1383,7 +1383,7 @@ static int genl_bind(struct net *net, int group) break; } - genl_unlock_all(); + up_read(&cb_lock); return ret; } -- 2.35.1