提交 86482d22 编写于 作者: K Kuniyuki Iwashima 提交者: Zheng Zengkai

nexthop: Fix data-races around nexthop_compat_mode.

stable inclusion
from stable-v5.10.132
commit a51040d4b120f3520df64fb0b9c63b31d69bea9b
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5YS3T

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=a51040d4b120f3520df64fb0b9c63b31d69bea9b

--------------------------------

[ Upstream commit bdf00bf2 ]

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

Fixes: 4f80116d ("net: ipv4: add sysctl for nexthop api compatibility mode")
Signed-off-by: NKuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
上级 b94d4539
...@@ -1831,7 +1831,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event, ...@@ -1831,7 +1831,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
goto nla_put_failure; goto nla_put_failure;
if (nexthop_is_blackhole(fi->nh)) if (nexthop_is_blackhole(fi->nh))
rtm->rtm_type = RTN_BLACKHOLE; 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; goto offload;
} }
......
...@@ -882,7 +882,7 @@ static void __remove_nexthop_fib(struct net *net, struct nexthop *nh) ...@@ -882,7 +882,7 @@ static void __remove_nexthop_fib(struct net *net, struct nexthop *nh)
/* __ip6_del_rt does a release, so do a hold here */ /* __ip6_del_rt does a release, so do a hold here */
fib6_info_hold(f6i); fib6_info_hold(f6i);
ipv6_stub->ip6_del_rt(net, f6i, ipv6_stub->ip6_del_rt(net, f6i,
!net->ipv4.sysctl_nexthop_compat_mode); !READ_ONCE(net->ipv4.sysctl_nexthop_compat_mode));
} }
} }
...@@ -1194,7 +1194,8 @@ static int insert_nexthop(struct net *net, struct nexthop *new_nh, ...@@ -1194,7 +1194,8 @@ static int insert_nexthop(struct net *net, struct nexthop *new_nh,
if (!rc) { if (!rc) {
nh_base_seq_inc(net); nh_base_seq_inc(net);
nexthop_notify(RTM_NEWNEXTHOP, new_nh, &cfg->nlinfo); 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); nexthop_replace_notify(net, new_nh, &cfg->nlinfo);
} }
......
...@@ -5636,7 +5636,7 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb, ...@@ -5636,7 +5636,7 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb,
if (nexthop_is_blackhole(rt->nh)) if (nexthop_is_blackhole(rt->nh))
rtm->rtm_type = RTN_BLACKHOLE; 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) rt6_fill_node_nexthop(skb, rt->nh, &nh_flags) < 0)
goto nla_put_failure; goto nla_put_failure;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册