Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp4050377rwb; Sun, 9 Oct 2022 16:51:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ysPhq4S37Yme+YBtWMJaRo2guCydeyC5UvPcMhdIQOYA4QrGGUDszCsTk6srS3jxaoqvi X-Received: by 2002:a05:6402:5507:b0:452:183f:16d1 with SMTP id fi7-20020a056402550700b00452183f16d1mr15445125edb.96.1665359497252; Sun, 09 Oct 2022 16:51:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665359497; cv=none; d=google.com; s=arc-20160816; b=jQuO9oR1BBYwDACDMbiUXfaEmwvMal+0NgOSglFSwkY8ubLb64l6LqePh7cS0VRzga /TskeG4fVKkBpFSkHaw5SsFkGnLK+Kj972OCUYR9lqIcRh/vJGcuFQPVgOJOv+D7sVHW qaJEmXVEnwqMFvd/vd/u5Chag0RHqoK2pi2LOtaKmsMUxRaaakBIAvqubHrufgvPzDcF qsabc/dy5evuNWS0bnIKo8OtAo3jpEulnf6d5NlE8GPuInSfuO5B2gjr7HYBL8TjnBBK NiB0vU5+KmFk18yxGCS1uomS/mKC7H5uvmGd4vXcFPhckMGQCUGymlSGEzl+oe/E4V2p Nu/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=p7sxqs3tp6xF3T3c6KE3JNUB6g7KrJJRcJ5hl96Ixz8=; b=K48qr5hmoJ92L+k7vsB5rTkBfQxWBTSlQLM+2wKbOBbk5fDnfbQMgLgKWTqYPMFsf7 bXWuptViMwn3jx8/jAeaxUYJFSE/UDIukkOtZ/l2bUYuEraYzcZCmpvTRbtyq4uVbSxf QnZ9cQdEIt3Yq6wX21ngTZW8w5Ov9FGvlFJQO4+AaqY/gmj2B19PgJUJyYtXxEzP8Ito ziyh5KqxQ3FKJu3s2jjdjzEjqFog2LTtXrF8979wulKTsbCzA1Ob0zyycHW6+tS5ZuCY BMdD+AiUX1ejMCvm/ltyO/R6wxoqq9x3WDAK0LgevC8Obz41WbIIl4DJNEHt+34w9otD QMYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pMtbbXxs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z3-20020aa7cf83000000b00458e43471d5si8458437edx.614.2022.10.09.16.51.09; Sun, 09 Oct 2022 16:51:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pMtbbXxs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231238AbiJIWKY (ORCPT + 99 others); Sun, 9 Oct 2022 18:10:24 -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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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