Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3078790rwe; Mon, 29 Aug 2022 05:35:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR7pq5OO7p5rKR6vMwh0ZV+73gIzatO2tOSs7ps9mc6Vr8K0rKk+FrJfiUtlnjmrfcaLutcq X-Received: by 2002:a17:902:cec1:b0:16d:c4f2:66c5 with SMTP id d1-20020a170902cec100b0016dc4f266c5mr16306734plg.20.1661776535865; Mon, 29 Aug 2022 05:35:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661776535; cv=none; d=google.com; s=arc-20160816; b=X5MLng5x/Efp3EWUvqoMC/f5u4TN70bIjbnKvA1CuegoLLViJLi4t1Onrt2erzKNtg 7cUzaaS6DuD05zJi7aygK/AT3Kpnnky6WjFB7RrestTZHRPHhslZekrdkuhLsG6aArlD S3hYyAMf4ji46kdLEJBOmXrZEMtPXdzChiQ992yNbR+vBmxlOyzmJTWUd4/f0lGAcAFr 35z0adePAkUVrE4jqx9+j5IDe9Wzd/0McY5W11jEF/kNFFZ//toWlNWCWTXXkXMcRA78 uH1ezC/oMAwkbBQBZ3F1euDjugON/5g8S56mWNTrl9I1EqhvohW7MldSY+m/p80ccbcE zaTw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZNUaf+mo8CdatSVt6xEolyX9xK1aQKPzMRgqMyAXqzA=; b=njdOP30UbXDiwDOwcy59OBeD+WPRJ4mLm9MZ8ypYNule4viOEzJsS9mwD4+iVGMJ9U gHVk0kwejXBEpcvxQXjxq/lC7cTE36S2CO8sltHPo8X7rywdGlarG7MonVCGw/AgqqcE IAieTPtr3M4085hStuYX9Xe5ubwwuJGDW4InPH9pWldg1EQTMTyoO8+NUzXHrwUQI442 zLJK3xj3EoQNGOFGErx4Mz/vAnEM6P90lZRkk5NMLL2o6OMh1SD6bGHkUCJBRHjr0PBz OfIcdz52elyil+4XGe5ymuTimYgzE82Jii9b0VFm01bRBvSQ/nyVS7Sb328i4RtwWh/j 2fdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VbnObiIJ; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n14-20020a63590e000000b004298268026fsi8587147pgb.142.2022.08.29.05.35.23; Mon, 29 Aug 2022 05:35:35 -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=@linuxfoundation.org header.s=korg header.b=VbnObiIJ; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232130AbiH2L0i (ORCPT + 99 others); Mon, 29 Aug 2022 07:26:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232216AbiH2LYc (ORCPT ); Mon, 29 Aug 2022 07:24:32 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E65130F68; Mon, 29 Aug 2022 04:15:43 -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 44A1FB80F01; Mon, 29 Aug 2022 11:13:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A951EC43142; Mon, 29 Aug 2022 11:13:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771591; bh=bszJK+xsM2ct+CjjbxZn664cxsjOOWBnSDfF/kCyq6A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VbnObiIJw3fpxMZCrtZKmmUVPKHrmx+ekciFVu/d6xuv5SAHar0ldrGsvdJkxVk2E TQRdi/Tleu9KCVNZsKazEkU8oExbRNtYiZQV8TPNbtEy+aiWNxInSjMtGD/BNC3263 sTIOTfcUvnQ3vwz9RKnU5S/gAXkH6d31tPi6mx5E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 59/86] net: Fix data-races around sysctl_devconf_inherit_init_net. Date: Mon, 29 Aug 2022 12:59:25 +0200 Message-Id: <20220829105758.970231758@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105756.500128871@linuxfoundation.org> References: <20220829105756.500128871@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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,T_SCC_BODY_TEXT_LINE 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: Kuniyuki Iwashima [ Upstream commit a5612ca10d1aa05624ebe72633e0c8c792970833 ] While reading sysctl_devconf_inherit_init_net, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 856c395cfa63 ("net: introduce a knob to control whether to inherit devconf config") Signed-off-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- include/linux/netdevice.h | 9 +++++++++ net/ipv4/devinet.c | 16 ++++++++++------ net/ipv6/addrconf.c | 5 ++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index c05701f89d6dd..6564fb4ac49e1 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -643,6 +643,15 @@ static inline bool net_has_fallback_tunnels(const struct net *net) #endif } +static inline int net_inherit_devconf(void) +{ +#if IS_ENABLED(CONFIG_SYSCTL) + return READ_ONCE(sysctl_devconf_inherit_init_net); +#else + return 0; +#endif +} + static inline int netdev_queue_numa_node_read(const struct netdev_queue *q) { #if defined(CONFIG_XPS) && defined(CONFIG_NUMA) diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 148ef484a66ce..8f17538755507 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -2668,23 +2668,27 @@ static __net_init int devinet_init_net(struct net *net) #endif if (!net_eq(net, &init_net)) { - if (IS_ENABLED(CONFIG_SYSCTL) && - sysctl_devconf_inherit_init_net == 3) { + switch (net_inherit_devconf()) { + case 3: /* copy from the current netns */ memcpy(all, current->nsproxy->net_ns->ipv4.devconf_all, sizeof(ipv4_devconf)); memcpy(dflt, current->nsproxy->net_ns->ipv4.devconf_dflt, sizeof(ipv4_devconf_dflt)); - } else if (!IS_ENABLED(CONFIG_SYSCTL) || - sysctl_devconf_inherit_init_net != 2) { - /* inherit == 0 or 1: copy from init_net */ + break; + case 0: + case 1: + /* copy from init_net */ memcpy(all, init_net.ipv4.devconf_all, sizeof(ipv4_devconf)); memcpy(dflt, init_net.ipv4.devconf_dflt, sizeof(ipv4_devconf_dflt)); + break; + case 2: + /* use compiled values */ + break; } - /* else inherit == 2: use compiled values */ } #ifdef CONFIG_SYSCTL diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 05317e6f48f8a..ed1e5bfc97b31 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -7042,9 +7042,8 @@ static int __net_init addrconf_init_net(struct net *net) if (!dflt) goto err_alloc_dflt; - if (IS_ENABLED(CONFIG_SYSCTL) && - !net_eq(net, &init_net)) { - switch (sysctl_devconf_inherit_init_net) { + if (!net_eq(net, &init_net)) { + switch (net_inherit_devconf()) { case 1: /* copy from init_net */ memcpy(all, init_net.ipv6.devconf_all, sizeof(ipv6_devconf)); -- 2.35.1