All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	David Ahern <dsahern@kernel.org>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Kees Cook <keescook@chromium.org>,
	Iurii Zaikin <yzaikin@google.com>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>,
	Kuniyuki Iwashima <kuni1840@gmail.com>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	Roopa Prabhu <roopa@cumulusnetworks.com>
Subject: [PATCH v1 net 15/15] nexthop: Fix data-races around nexthop_compat_mode.
Date: Mon, 11 Jul 2022 17:15:33 -0700	[thread overview]
Message-ID: <20220712001533.89927-16-kuniyu@amazon.com> (raw)
In-Reply-To: <20220712001533.89927-1-kuniyu@amazon.com>

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 <kuniyu@amazon.com>
---
CC: Roopa Prabhu <roopa@cumulusnetworks.com>
---
 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


  parent reply	other threads:[~2022-07-12  0:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12  0:15 [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 1) Kuniyuki Iwashima
2022-07-12  0:15 ` [PATCH v1 net 01/15] sysctl: Fix data-races in proc_dou8vec_minmax() Kuniyuki Iwashima
2022-07-12  0:15 ` [PATCH v1 net 02/15] sysctl: Fix data-races in proc_dointvec_ms_jiffies() Kuniyuki Iwashima
2022-07-12  0:15 ` [PATCH v1 net 03/15] tcp: Fix a data-race around sysctl_max_tw_buckets Kuniyuki Iwashima
2022-07-12  0:15 ` [PATCH v1 net 04/15] icmp: Fix a data-race around sysctl_icmp_echo_ignore_all Kuniyuki Iwashima
2022-07-12  0:15 ` [PATCH v1 net 05/15] icmp: Fix data-races around sysctl_icmp_echo_enable_probe Kuniyuki Iwashima
2022-07-12  0:15 ` [PATCH v1 net 06/15] icmp: Fix a data-race around sysctl_icmp_echo_ignore_broadcasts Kuniyuki Iwashima
2022-07-12  0:15 ` [PATCH v1 net 07/15] icmp: Fix a data-race around sysctl_icmp_ignore_bogus_error_responses Kuniyuki Iwashima
2022-07-12  0:15 ` [PATCH v1 net 08/15] icmp: Fix a data-race around sysctl_icmp_errors_use_inbound_ifaddr Kuniyuki Iwashima
2022-07-12  0:15 ` [PATCH v1 net 09/15] icmp: Fix a data-race around sysctl_icmp_ratelimit Kuniyuki Iwashima
2022-07-12  0:15 ` [PATCH v1 net 10/15] icmp: Fix a data-race around sysctl_icmp_ratemask Kuniyuki Iwashima
2022-07-12  0:15 ` [PATCH v1 net 11/15] raw: Fix a data-race around sysctl_raw_l3mdev_accept Kuniyuki Iwashima
2022-07-12  0:15 ` [PATCH v1 net 12/15] tcp: Fix data-races around sysctl_tcp_ecn Kuniyuki Iwashima
2022-07-12  0:15 ` [PATCH v1 net 13/15] tcp: Fix a data-race around sysctl_tcp_ecn_fallback Kuniyuki Iwashima
2022-07-12  0:15 ` [PATCH v1 net 14/15] ipv4: Fix data-races around sysctl_ip_dynaddr Kuniyuki Iwashima
2022-07-12  0:15 ` Kuniyuki Iwashima [this message]
2022-07-13 12:30 ` [PATCH v1 net 00/15] sysctl: Fix data-races around ipv4_net_table (Round 1) patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220712001533.89927-16-kuniyu@amazon.com \
    --to=kuniyu@amazon.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=keescook@chromium.org \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=roopa@cumulusnetworks.com \
    --cc=yzaikin@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.