Skip to contentSkip to conversation

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

PATCH Superseded Paolo Abeni 2 participants 5 messages Feb 20, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Paolo Abeni

author maintainer
#0 lore raw

cover 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

Paolo Abeni (2):
ipv6: route: enforce RCU protection in rt6_update_exception_stamp_rt()
ipv6: route: enforce RCU protection in ip6_route_check_nh_onlink()

 net/ipv6/route.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH 1/2 ipv6: route: enforce RCU protection in rt6_update_exception_stamp_rt()

We must access rt6_info->from under RCU read lock: move the dereference under such lock, with proper annotation, and use rcu_access_pointer() to check for null value outside the lock.

Fixes a68886a69180 ("net/ipv6: Make from in rt6_info rcu protected")
---
 net/ipv6/route.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/ipv6/route.c +3 -3
index bd09abd1fb22..cbaa8745d9ff 100644
@@ -1610,15 +1610,15 @@ static int rt6_remove_exception_rt(struct rt6_info *rt)
 static void rt6_update_exception_stamp_rt(struct rt6_info *rt)
 {
 	struct rt6_exception_bucket *bucket;
-	struct fib6_info *from = rt->from;
 	struct in6_addr *src_key = NULL;
 	struct rt6_exception *rt6_ex;
+	struct fib6_info *from;
 
-	if (!from ||
-	    !(rt->rt6i_flags & RTF_CACHE))
+	if (!rcu_access_pointer(rt->from) || !(rt->rt6i_flags & RTF_CACHE))
 		return;
 
 	rcu_read_lock();
+	from = rcu_dereference(rt->from);
 	bucket = rcu_dereference(from->rt6i_exception_bucket);
 
 #ifdef CONFIG_IPV6_SUBTREES
Signature · 1 line
2.20.1
author maintainer
#2 lore raw

Re: [PATCH net 1/2] ipv6: route: enforce RCU protection in rt6_update_exception_stamp_rt()

Quoted 20 lines · Paolo Abeni

We must access rt6_info->from under RCU read lock: move the dereference under such lock, with proper annotation, and use rcu_access_pointer() to check for null value outside the lock.

Fixes a68886a69180 ("net/ipv6: Make from in rt6_info rcu protected")
---
 net/ipv6/route.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/ipv6/route.c +0 -1
index bd09abd1fb22..cbaa8745d9ff 100644
@@ -1610,15 +1610,15 @@ static int rt6_remove_exception_rt(struct rt6_info *rt)
 static void rt6_update_exception_stamp_rt(struct rt6_info *rt)
 {
 	struct rt6_exception_bucket *bucket;
-	struct fib6_info *from = rt->from;
 	struct in6_addr *src_key = NULL;

net/ipv6/route.c static int rt6_remove_exception_rt(struct rt6_info *rt) · line 1621

Quoted 10 lines
net/ipv6/route.c +3 -2
 	struct rt6_exception *rt6_ex;
+	struct fib6_info *from;
 
-	if (!from ||
-	    !(rt->rt6i_flags & RTF_CACHE))
+	if (!rcu_access_pointer(rt->from) || !(rt->rt6i_flags & RTF_CACHE))
 		return;
 
 	rcu_read_lock();
+	from = rcu_dereference(rt->from);

-ELOWONCOFFEE: even this one is racy, as rt->from can go away due to underlying device removal between the two fetch operation.

I'll send a v2.

Again, I'm sorry for the noise,

Paolo

maintainer
#3 lore raw

Re: [PATCH net 1/2] ipv6: route: enforce RCU protection in rt6_update_exception_stamp_rt()

From: Paolo Abeni <[email protected]>
Date: Wed, 20 Feb 2019 18:22:55 +0100

Quoted 1 line

-ELOWONCOFFEE:

Mind if I make you some? :)

Quoted 3 lines

I'll send a v2.

Again, I'm sorry for the noise,

You are keeping me busy today.

author maintainer
#4 lore raw

PATCH 2/2 ipv6: route: enforce RCU protection in ip6_route_check_nh_onlink()

In reply to Paolo Abeni

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

Fixes 4ed591c8ab44 ("net/ipv6: Allow onlink routes to have a device mismatch if it is the default route")
---
 net/ipv6/route.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/ipv6/route.c +5 -1
index cbaa8745d9ff..3b526a070299 100644
@@ -2753,20 +2753,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);
 	}
Signature · 1 line
2.20.1