Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3865817imw; Mon, 11 Jul 2022 18:12:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sw5qrNDw0QW3VZGZ++o79uqzQT/5mM+Yzh3nopYK8HeDns6G7OjcL8UXl+bnWSkyQRgL3w X-Received: by 2002:a17:902:c952:b0:16c:1cdd:9077 with SMTP id i18-20020a170902c95200b0016c1cdd9077mr21643571pla.168.1657588362715; Mon, 11 Jul 2022 18:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657588362; cv=none; d=google.com; s=arc-20160816; b=YxxLuxBETjVgbk6ccKBphXpQiwfE3BwIRSWiUB0mbUycJ0O3utyVyWrfJAS/ihMupO owmszGlefAVRgQtcqBZFMBJhjwjbkScK/VOGVi5+NtxW2tMloN0nlkuBeui8cg5f2t5Y vhAsg6nv6Wt9vlvHl5I51qX1ud33OcHYpwr+LUF5tRX9usqXFpp06Q7vQW39RTADb0zT 8Hyfw0gitPOAdFc+N+aHoO7J57fWO0CSiBuVbD60lvBGPQUHxWaWx6WYlV+Ap5hqvjud CpT2/4qy0gwR20MtwKEhHOhBUptYdFm5bz8WxURy6U4ZA+luSO5a6ZPOe4jrMBQba2Il Qhfg== 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=xpFsWJFzay/J0RJVIAQkY1+S1ovBvAqv3a/fYcGd3C8=; b=ghfEdqoM9xN4NY+NuZAVDVuaDFnwfnQsbA33I/c6advValy1bkj807uTkxut+5Uz4R XUwN0FihobKy4T9nNygzi9IW/ZFcqVBHAfVuACmyqTx7dOCk7GeV2dn9gYb07P39y7nC g/5dnKZC8FOOt1ylfFCGZqgo4l/M8GY+ThcpTDJczjO0a4uWZelxNEM4DA1374T8VxaZ D7+h1yVxf188S99KF+lbkn7g3B7Pt1zak23wc527kOPfsSNuKXj2x5FKIcLQ4UgPUFnk G+RojhL9LORv13plA+XGVfNjB97Oox2o0mZEKNMq3z97kHE3uzD/IE9J4arQI+xzrUGN aL1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=X9A5lUAg; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p24-20020a17090b011800b001ef79dec15fsi13777811pjz.26.2022.07.11.18.12.30; Mon, 11 Jul 2022 18:12:42 -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=@amazon.com header.s=amazon201209 header.b=X9A5lUAg; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232258AbiGLAWK (ORCPT + 99 others); Mon, 11 Jul 2022 20:22:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232168AbiGLAVl (ORCPT ); Mon, 11 Jul 2022 20:21:41 -0400 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 212548B493; Mon, 11 Jul 2022 17:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1657585255; x=1689121255; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xpFsWJFzay/J0RJVIAQkY1+S1ovBvAqv3a/fYcGd3C8=; b=X9A5lUAg9ubXaflkA2fDTWzvoC2dfRtMQOtgjjDYP6SwBezqCOuar0Vi fhOeC/7g3//UR/4ITHxkSeWcJFWw7a2AJ3fN+KfPIyMFV+Nwrq31s1DKJ wFpyvli7YBZKpWPYbTEuNlp5eNLhJGspAzIp/CgwWbuwmYnlmLEiP48sg A=; Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-pdx-2c-4213ea4c.us-west-2.amazon.com) ([10.124.125.2]) by smtp-border-fw-6001.iad6.amazon.com with ESMTP; 12 Jul 2022 00:20:53 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-pdx-2c-4213ea4c.us-west-2.amazon.com (Postfix) with ESMTPS id C774C812AF; Tue, 12 Jul 2022 00:20:52 +0000 (UTC) Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Tue, 12 Jul 2022 00:20:51 +0000 Received: from 88665a182662.ant.amazon.com.com (10.43.161.185) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.9; Tue, 12 Jul 2022 00:20:48 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Luis Chamberlain , Kees Cook , Iurii Zaikin CC: Kuniyuki Iwashima , Kuniyuki Iwashima , , , Roopa Prabhu Subject: [PATCH v1 net 15/15] nexthop: Fix data-races around nexthop_compat_mode. Date: Mon, 11 Jul 2022 17:15:33 -0700 Message-ID: <20220712001533.89927-16-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220712001533.89927-1-kuniyu@amazon.com> References: <20220712001533.89927-1-kuniyu@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.43.161.185] X-ClientProxiedBy: EX13D04UWB002.ant.amazon.com (10.43.161.133) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,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 While reading nexthop_compat_mode, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers. Fixes: 4f80116d3df3 ("net: ipv4: add sysctl for nexthop api compatibility mode") Signed-off-by: Kuniyuki Iwashima --- CC: Roopa Prabhu --- net/ipv4/fib_semantics.c | 2 +- net/ipv4/nexthop.c | 5 +++-- net/ipv6/route.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index a57ba23571c9..16dbd5075284 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -1811,7 +1811,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, goto nla_put_failure; if (nexthop_is_blackhole(fi->nh)) rtm->rtm_type = RTN_BLACKHOLE; - if (!fi->fib_net->ipv4.sysctl_nexthop_compat_mode) + if (!READ_ONCE(fi->fib_net->ipv4.sysctl_nexthop_compat_mode)) goto offload; } diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index e459a391e607..853a75a8fbaf 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -1858,7 +1858,7 @@ static void __remove_nexthop_fib(struct net *net, struct nexthop *nh) /* __ip6_del_rt does a release, so do a hold here */ fib6_info_hold(f6i); ipv6_stub->ip6_del_rt(net, f6i, - !net->ipv4.sysctl_nexthop_compat_mode); + !READ_ONCE(net->ipv4.sysctl_nexthop_compat_mode)); } } @@ -2361,7 +2361,8 @@ static int insert_nexthop(struct net *net, struct nexthop *new_nh, if (!rc) { nh_base_seq_inc(net); nexthop_notify(RTM_NEWNEXTHOP, new_nh, &cfg->nlinfo); - if (replace_notify && net->ipv4.sysctl_nexthop_compat_mode) + if (replace_notify && + READ_ONCE(net->ipv4.sysctl_nexthop_compat_mode)) nexthop_replace_notify(net, new_nh, &cfg->nlinfo); } diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 828355710c57..916417944ec8 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -5741,7 +5741,7 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb, if (nexthop_is_blackhole(rt->nh)) rtm->rtm_type = RTN_BLACKHOLE; - if (net->ipv4.sysctl_nexthop_compat_mode && + if (READ_ONCE(net->ipv4.sysctl_nexthop_compat_mode) && rt6_fill_node_nexthop(skb, rt->nh, &nh_flags) < 0) goto nla_put_failure; -- 2.30.2