Skip to content

Commit 17ecf59

Browse files
tracywwnjdavem330
authored andcommitted
ipv6: add key length check into rt6_select()
After rwlock is replaced with rcu and spinlock, fib6_lookup() could potentially return an intermediate node if other thread is doing fib6_del() on a route which is the only route on the node so that fib6_repair_tree() will be called on this node and potentially assigns fn->leaf to the its child's fn->leaf. In order to detect this situation in rt6_select(), we have to check if fn->fn_bit is consistent with the key length stored in the route. And depending on if the fn is in the subtree or not, the key is either rt->rt6i_dst or rt->rt6i_src. If any inconsistency is found, that means the node no longer holds valid routes in it. So net->ipv6.ip6_null_entry is returned. Signed-off-by: Wei Wang <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8d1040e commit 17ecf59

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

net/ipv6/route.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ static struct rt6_info *rt6_select(struct net *net, struct fib6_node *fn,
755755
struct rt6_info *leaf = fn->leaf;
756756
struct rt6_info *match, *rt0;
757757
bool do_rr = false;
758+
int key_plen;
758759

759760
if (!leaf)
760761
return net->ipv6.ip6_null_entry;
@@ -763,6 +764,19 @@ static struct rt6_info *rt6_select(struct net *net, struct fib6_node *fn,
763764
if (!rt0)
764765
fn->rr_ptr = rt0 = leaf;
765766

767+
/* Double check to make sure fn is not an intermediate node
768+
* and fn->leaf does not points to its child's leaf
769+
* (This might happen if all routes under fn are deleted from
770+
* the tree and fib6_repair_tree() is called on the node.)
771+
*/
772+
key_plen = rt0->rt6i_dst.plen;
773+
#ifdef CONFIG_IPV6_SUBTREES
774+
if (rt0->rt6i_src.plen)
775+
key_plen = rt0->rt6i_src.plen;
776+
#endif
777+
if (fn->fn_bit != key_plen)
778+
return net->ipv6.ip6_null_entry;
779+
766780
match = find_rr_leaf(fn, leaf, rt0, rt0->rt6i_metric, oif, strict,
767781
&do_rr);
768782

0 commit comments

Comments
 (0)