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 B11E5C4321E for ; Sun, 9 Oct 2022 22:10:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230324AbiJIWKW (ORCPT ); Sun, 9 Oct 2022 18:10:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230318AbiJIWJI (ORCPT ); Sun, 9 Oct 2022 18:09:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B53A5286FB; Sun, 9 Oct 2022 15:08: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 dfw.source.kernel.org (Postfix) with ESMTPS id 3568160B85; Sun, 9 Oct 2022 22:08:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 540C4C433D6; Sun, 9 Oct 2022 22:08:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665353323; bh=KAnZS9WcwRk8bgKwx6yLV74+eQUR9dCSvwpUrV+4pIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pMtbbXxsxmuwhWhDajVpx+Yq2czOcRxU7HPDRBHYKPLN/EJZl51zPgRmRxGUIiGAU 0bb+f8VGRMF+L37rgtZewEF9cQ4vl7UlQGV9VW65qxxBxDHpY9XYnBBE3/Ws9CMqVy IYmeuOuRm9LBRC/+oK4IxZAbiYoEnE/7em9U6dfRT2HgufBz6ZwDfEAlNH2ZKKsl2k /O0Abs3JpDk0hZCdTV4ANMgXdNS4Ku27GWg9lx+M53V7oAdKrzoRbLEMPrM/7WuQ1A Z9AEjku1eAFfBdZTl3wZZs5jdTKROQ6wUkl4klxT6IDKzX5l9B/jZbhkmrBQBBmxbe 697v7ci6Hho5w== 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, nicolas.dichtel@6wind.com, gnault@redhat.com, johannes@sipsolutions.net, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 6.0 17/77] genetlink: hold read cb_lock during iteration of genl_fam_idr in genl_bind() Date: Sun, 9 Oct 2022 18:06:54 -0400 Message-Id: <20221009220754.1214186-17-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221009220754.1214186-1-sashal@kernel.org> References: <20221009220754.1214186-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: netdev@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