提交 c6f71dda 编写于 作者: P Paolo Abeni 提交者: Xie XiuQi

ipv6: route: enforce RCU protection in ip6_route_check_nh_onlink()

mainline inclusion
from mainline-v5.0-rc7
commit bf1dc8ba
category: bugfix
bugzilla: 10918
CVE: NA

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

We need a RCU critical section around rt6_info->from deference, and
proper annotation.

Fixes: 4ed591c8 ("net/ipv6: Allow onlink routes to have a device mismatch if it is the default route")
Signed-off-by: NPaolo Abeni <pabeni@redhat.com>
Reviewed-by: NDavid Ahern <dsahern@gmail.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NLin Miaohe <linmiaohe@huawei.com>
Reviewed-by: NMao Wenan <maowenan@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 f5e84cdf
...@@ -2797,20 +2797,24 @@ static int ip6_route_check_nh_onlink(struct net *net, ...@@ -2797,20 +2797,24 @@ static int ip6_route_check_nh_onlink(struct net *net,
u32 tbid = l3mdev_fib_table(dev) ? : RT_TABLE_MAIN; u32 tbid = l3mdev_fib_table(dev) ? : RT_TABLE_MAIN;
const struct in6_addr *gw_addr = &cfg->fc_gateway; const struct in6_addr *gw_addr = &cfg->fc_gateway;
u32 flags = RTF_LOCAL | RTF_ANYCAST | RTF_REJECT; u32 flags = RTF_LOCAL | RTF_ANYCAST | RTF_REJECT;
struct fib6_info *from;
struct rt6_info *grt; struct rt6_info *grt;
int err; int err;
err = 0; err = 0;
grt = ip6_nh_lookup_table(net, cfg, gw_addr, tbid, 0); grt = ip6_nh_lookup_table(net, cfg, gw_addr, tbid, 0);
if (grt) { if (grt) {
rcu_read_lock();
from = rcu_dereference(grt->from);
if (!grt->dst.error && if (!grt->dst.error &&
/* ignore match if it is the default route */ /* ignore match if it is the default route */
grt->from && !ipv6_addr_any(&grt->from->fib6_dst.addr) && from && !ipv6_addr_any(&from->fib6_dst.addr) &&
(grt->rt6i_flags & flags || dev != grt->dst.dev)) { (grt->rt6i_flags & flags || dev != grt->dst.dev)) {
NL_SET_ERR_MSG(extack, NL_SET_ERR_MSG(extack,
"Nexthop has invalid gateway or device mismatch"); "Nexthop has invalid gateway or device mismatch");
err = -EINVAL; err = -EINVAL;
} }
rcu_read_unlock();
ip6_rt_put(grt); ip6_rt_put(grt);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册