History

nexthop: Fix data-races around nexthop_compat_mode.

While reading nexthop_compat_mode, it can be changed concurrently. Thus, we need to add READ_ONCE() to its readers.

Kuniyuki Iwashima committed 4 years ago

Commit bdf00bf1 parent e49e4af3 files · +5 −4Browse files

Unified · Split

3 files
  1. net/ipv4/fib_semantics.c +1 −1
  2. net/ipv4/nexthop.c +3 −2
  3. net/ipv6/route.c +1 −1
net/ipv4/fib_semantics.c+1−1
@@ -1811,7 +1811,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, · 1810 unmodified lines
18111811 goto nla_put_failure;
18121812 if (nexthop_is_blackhole(fi->nh))
18131813 rtm->rtm_type = RTN_BLACKHOLE;
1814− if (!fi->fib_net->ipv4.sysctl_nexthop_compat_mode)
1814+ if (!READ_ONCE(fi->fib_net->ipv4.sysctl_nexthop_compat_mode))
18151815 goto offload;
18161816 }
18171817
net/ipv4/nexthop.c+3−2
@@ -1858,7 +1858,7 @@ static void __remove_nexthop_fib(struct net *net, struct nexthop *nh) · 1857 unmodified lines
18581858 /* __ip6_del_rt does a release, so do a hold here */
18591859 fib6_info_hold(f6i);
18601860 ipv6_stub->ip6_del_rt(net, f6i,
1861− !net->ipv4.sysctl_nexthop_compat_mode);
1861+ !READ_ONCE(net->ipv4.sysctl_nexthop_compat_mode));
18621862 }
18631863 }
18641864
@@ -2361,7 +2361,8 @@ out: · 496 unmodified lines
23612361 if (!rc) {
23622362 nh_base_seq_inc(net);
23632363 nexthop_notify(RTM_NEWNEXTHOP, new_nh, &cfg->nlinfo);
2364− if (replace_notify && net->ipv4.sysctl_nexthop_compat_mode)
2364+ if (replace_notify &&
2365+ READ_ONCE(net->ipv4.sysctl_nexthop_compat_mode))
23652366 nexthop_replace_notify(net, new_nh, &cfg->nlinfo);
23662367 }
23672368
net/ipv6/route.c+1−1
@@ -5741,7 +5741,7 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb, · 5740 unmodified lines
57415741 if (nexthop_is_blackhole(rt->nh))
57425742 rtm->rtm_type = RTN_BLACKHOLE;
57435743
5744− if (net->ipv4.sysctl_nexthop_compat_mode &&
5744+ if (READ_ONCE(net->ipv4.sysctl_nexthop_compat_mode) &&
57455745 rt6_fill_node_nexthop(skb, rt->nh, &nh_flags) < 0)
57465746 goto nla_put_failure;
57475747