Skip to contentSkip to conversation

net/ipv6: fix lookup for ::/0 (non-)subtree route

PATCH In review David Lamparter 2 participants 2 messages Nov 5, 2025 – Nov 11, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.)

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 +4 -1
index 02c16909f618..c18e9331770d 100644
@@ -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
maintainer
#1 lore raw
Quoted 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 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.)

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
index 02c16909f618..c18e9331770d 100644
@@ -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 -1
 								 args + 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