Skip to content

Commit 64cc41e

Browse files
committed
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]>
2 parents ae3b564 + bf1dc8b commit 64cc41e

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

net/ipv6/route.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,15 +1599,15 @@ static int rt6_remove_exception_rt(struct rt6_info *rt)
15991599
static void rt6_update_exception_stamp_rt(struct rt6_info *rt)
16001600
{
16011601
struct rt6_exception_bucket *bucket;
1602-
struct fib6_info *from = rt->from;
16031602
struct in6_addr *src_key = NULL;
16041603
struct rt6_exception *rt6_ex;
1605-
1606-
if (!from ||
1607-
!(rt->rt6i_flags & RTF_CACHE))
1608-
return;
1604+
struct fib6_info *from;
16091605

16101606
rcu_read_lock();
1607+
from = rcu_dereference(rt->from);
1608+
if (!from || !(rt->rt6i_flags & RTF_CACHE))
1609+
goto unlock;
1610+
16111611
bucket = rcu_dereference(from->rt6i_exception_bucket);
16121612

16131613
#ifdef CONFIG_IPV6_SUBTREES
@@ -1626,6 +1626,7 @@ static void rt6_update_exception_stamp_rt(struct rt6_info *rt)
16261626
if (rt6_ex)
16271627
rt6_ex->stamp = jiffies;
16281628

1629+
unlock:
16291630
rcu_read_unlock();
16301631
}
16311632

@@ -2742,20 +2743,24 @@ static int ip6_route_check_nh_onlink(struct net *net,
27422743
u32 tbid = l3mdev_fib_table(dev) ? : RT_TABLE_MAIN;
27432744
const struct in6_addr *gw_addr = &cfg->fc_gateway;
27442745
u32 flags = RTF_LOCAL | RTF_ANYCAST | RTF_REJECT;
2746+
struct fib6_info *from;
27452747
struct rt6_info *grt;
27462748
int err;
27472749

27482750
err = 0;
27492751
grt = ip6_nh_lookup_table(net, cfg, gw_addr, tbid, 0);
27502752
if (grt) {
2753+
rcu_read_lock();
2754+
from = rcu_dereference(grt->from);
27512755
if (!grt->dst.error &&
27522756
/* ignore match if it is the default route */
2753-
grt->from && !ipv6_addr_any(&grt->from->fib6_dst.addr) &&
2757+
from && !ipv6_addr_any(&from->fib6_dst.addr) &&
27542758
(grt->rt6i_flags & flags || dev != grt->dst.dev)) {
27552759
NL_SET_ERR_MSG(extack,
27562760
"Nexthop has invalid gateway or device mismatch");
27572761
err = -EINVAL;
27582762
}
2763+
rcu_read_unlock();
27592764

27602765
ip6_rt_put(grt);
27612766
}

0 commit comments

Comments
 (0)