net/ipv6: fix lookup for ::/0 (non-)subtree route
Subsystems (3)
PATCH 1/1 net/ipv6: fix lookup for ::/0 (non-)subtree route
Assume a scenario with something like the following routes:
default via fe80::1 dev dummy0
2001:db8:1::/48 via fe80::10 dev dummy0 2001:db8:1::/48 from 2001:db8:1:2::/64 via fe80::12 dev dummy0
Now if a lookup happens for 2001:db8:1::2345, but with a source address *not* covered by the third route, the expectation is to hit the second one. Unfortunately, this was broken since the code, on failing the lookup in the subtree, didn't consider the node itself which the subtree is attached to, i.e. route #2 above.
The fix is simple, check if the subtree is attached to a node that is itself a valid route before backtracking to less specific destination prefixes.
This case is somewhat rare for several reasons. To begin with, subtree routes are most commonly attached to the default destination. Additionally, in the rare cases where a non-default destination prefix is host to subtree routes, the fallback on not hitting any subtree route is commonly a default route (or a subtree route on that).
(Note that this was working for the "::/0 from ::/0" case since the root node is special-cased. The issue was discovered during RFC 6724 rule 5.5 testing, trying to find edge cases.)
--- net/ipv6/ip6_fib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv6/ip6_fib.c +4 -1
@@ -1650,8 +1650,11 @@ static struct fib6_node *fib6_node_lookup_1(struct fib6_node *root,struct fib6_node *sfn; sfn =fib6_node_lookup_1 (subtree, args +1 ); -if (!sfn) +if (!sfn) { +if (fn->fn_flags &RTN_RTINFO ) +return fn; goto backtrack; + } fn = sfn; }#endif
Signature · 1 line
2.50.1
Paolo Abeni
maintainerQuoted 40 lines · David Lamparter
Assume a scenario with something like the following routes:
default via fe80::1 dev dummy0
2001:db8:1::/48 via fe80::10 dev dummy0 2001:db8:1::/48 from 2001:db8:1:2::/64 via fe80::12 dev dummy0Now if a lookup happens for 2001:db8:1::2345, but with a source address *not* covered by the third route, the expectation is to hit the second one. Unfortunately, this was broken since the code, on failing the lookup in the subtree, didn't consider the node itself which the subtree is attached to, i.e. route #2 above.
The fix is simple, check if the subtree is attached to a node that is itself a valid route before backtracking to less specific destination prefixes.
This case is somewhat rare for several reasons. To begin with, subtree routes are most commonly attached to the default destination. Additionally, in the rare cases where a non-default destination prefix is host to subtree routes, the fallback on not hitting any subtree route is commonly a default route (or a subtree route on that).
(Note that this was working for the "::/0 from ::/0" case since the root node is special-cased. The issue was discovered during RFC 6724 rule 5.5 testing, trying to find edge cases.)
Signed-off-by David Lamparter <[email protected]>Cc Lorenzo Colitti <[email protected]>Cc Patrick Rohr <[email protected]>Cc Maciej Żenczykowski <[email protected]>--- net/ipv6/ip6_fib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/ipv6/ip6_fib.c +0
-0@@ -1650,8 +1650,11 @@ static struct fib6_node *fib6_node_lookup_1(struct fib6_node *root,struct fib6_node *sfn; sfn = fib6_node_lookup_1(subtree,
net/ipv6/ip6_fib.c static struct fib6_node *fib6_node_lookup_1(struct fib6_node *root, · line 1660
Quoted 10 lines
net/ipv6/ip6_fib.c +4
-1args + 1); -if (!sfn) +if (!sfn) { +if (fn->fn_flags &RTN_RTINFO ) +return fn; goto backtrack; + } fn = sfn; }#endif
The patch LGTM, and I agree this should go via net-next, given that it's really a corner case and I could miss nasty side-effects.
It looks like you have some testing scenario handy: it would be great to include it as a paired self-test; could you please add it?
Thanks,
Paolo