Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3054045rwe; Mon, 29 Aug 2022 05:12:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR49bTbEeuSJR6/1E8K4osRAk7BIHAT/nEpIbEeOcUjiDYby0E0stFdTZQnzxUXNR1/U/nVn X-Received: by 2002:aa7:dc0a:0:b0:447:a7c0:54de with SMTP id b10-20020aa7dc0a000000b00447a7c054demr16860207edu.261.1661775155590; Mon, 29 Aug 2022 05:12:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661775155; cv=none; d=google.com; s=arc-20160816; b=R7QDbLewVtKUGzpbHpL9ZV3/r6Pk6ox8olJEsgGMn+rbY/guE3WLUpv1fttlDLHuhS uhxm0PU5GmcriHWx6BQ5G5MN/0SVqc2bUxmokUD6MzOHBrMlpiy8XgrDx+N+LwbyN7wt AGnIkDvk2AVqhqZ0Jc9oE6kc0tKPZSfQFKj0yFjfKSB0LNAUVS8gJYlxILqCvqixoj11 94NnXhDs9ioW7f8fPCOD1OfLf/om74GlkbwXKM9GcCKPd7HlSXeV6kglR2035t7s38PE YKqZSXhxYZQE7NAeMeR7jCY/utVndWxfWIFLL+BtnLqcle5EV2UGlaTBq4qaI44zwVaI v7lg== 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=wcCFKGddiOtkSwWti9PlJ4LaSXJ+MH3aOzziAFSyWf4=; b=u22MpotFVfDEDiyY0DeqdnoOEPyIVx7m8fF4M5r7Rs4bE+tNkE2M6idRxmDgWpO7Hs 1clwqa03KTPk97yNM2Y/UGUFThC+BWn4IuPyUNT94ZhHtNmqWJp3jbe502Ph6TKAld4N rO75AWWekL3APpsGzIal2Qf/EYk5TzVn+a/30Pl2y3poRkO2upwDGQAlokIQL4ZAjwrY MC/e54d8Z5YugAd73JEZMR9h4HucoCQ84sp9DQVueSsCynOkBkxmNwWDUPcULrdvXjDL JitBKDT8HJ6KaHSzDf73LUGn7EoNs8a4JVIkm5nSiAaCRwYktQRO/89DPILUT27bH+pt /byQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="WOG/fpWB"; 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 jg15-20020a170907970f00b0073306ff26besi6286673ejc.969.2022.08.29.05.12.09; Mon, 29 Aug 2022 05:12: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="WOG/fpWB"; 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 S232554AbiH2LdQ (ORCPT + 99 others); Mon, 29 Aug 2022 07:33:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232319AbiH2LaL (ORCPT ); Mon, 29 Aug 2022 07:30:11 -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 464D97C1EC; Mon, 29 Aug 2022 04:18:20 -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 87D64611DA; Mon, 29 Aug 2022 11:15:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 797C4C433D6; Mon, 29 Aug 2022 11:15:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771750; bh=F9CMrlLKuDuW/PSzOwejgDCrb0NKteycphC9H61ILMM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WOG/fpWB173qNRMcFFWSVPCzZ3PIPi0bvKapyDCKqfCqmoIhH4gPPsEntHBfBHK3k /3DVgB3XlbK6BdOgTvLTKlY+s8XA1ZDnNcxV7Rxf+53IyiEOCscJPHV6DfbmnhNxqA pNeZjkhZHJYUWZsoQYHAn5j4vFJiUwVhTh70eDuw= 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.19 078/158] net: Fix data-races around sysctl_devconf_inherit_init_net. Date: Mon, 29 Aug 2022 12:58:48 +0200 Message-Id: <20220829105812.310428515@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@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 78dd63a5c7c80..db40bc62213bd 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -650,6 +650,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 b2366ad540e62..787a44e3222db 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -2682,23 +2682,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 49cc6587dd771..b738eb7e1cae8 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -7158,9 +7158,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