Merge branch ‘ipv6-route-rcu’ [Linux 5.0]

This Linux kernel change "Merge branch ‘ipv6-route-rcu’" is included in the Linux 5.0 release. This change is authored by David S. Miller <davem [at] davemloft.net> on Thu Feb 21 09:54:35 2019 -0800. The commit for this change in Linux stable tree is 64cc41e (patch). Other info about this change: Merge: ae3b564 bf1dc8b

Merge branch 'ipv6-route-rcu'

Paolo Abeni says:

====================
ipv6: route: enforce RCU protection for fib6_info->from

This series addresses a couple of RCU left-over dating back to rt6_info->from
conversion to RCU

v1 -> v2:
 - fix a possible race in patch 1
====================

Signed-off-by: David S. Miller <[email protected]>

There is no are 0 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 net/ipv6/route.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 2b1ed8c..74b9b6f 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2743,20 +2743,24 @@ static int ip6_route_check_nh_onlink(struct net *net,
    u32 tbid = l3mdev_fib_table(dev) ? : RT_TABLE_MAIN;
    const struct in6_addr *gw_addr = &cfg->fc_gateway;
    u32 flags = RTF_LOCAL | RTF_ANYCAST | RTF_REJECT;
+   struct fib6_info *from;
    struct rt6_info *grt;
    int err;

    err = 0;
    grt = ip6_nh_lookup_table(net, cfg, gw_addr, tbid, 0);
    if (grt) {
+       rcu_read_lock();
+       from = rcu_dereference(grt->from);
        if (!grt->dst.error &&
            /* 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)) {
            NL_SET_ERR_MSG(extack,
                       "Nexthop has invalid gateway or device mismatch");
            err = -EINVAL;
        }
+       rcu_read_unlock();

        ip6_rt_put(grt);
    }

Leave a Reply

Your email address will not be published. Required fields are marked *