Skip to content

Commit ecc2656

Browse files
zx2c4gregkh
authored andcommitted
ipv6: do not free rt if FIB_LOOKUP_NOREF is set on suppress rule
[ Upstream commit ca7a03c ] Commit 7d9e5f4 removed references from certain dsts, but accounting for this never translated down into the fib6 suppression code. This bug was triggered by WireGuard users who use wg-quick(8), which uses the "suppress-prefix" directive to ip-rule(8) for routing all of their internet traffic without routing loops. The test case added here causes the reference underflow by causing packets to evaluate a suppress rule. Fixes: 7d9e5f4 ("ipv6: convert major tx path to use RT6_LOOKUP_F_DST_NOREF") Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Acked-by: Wei Wang <weiwan@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cf7665c commit ecc2656

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎net/ipv6/fib6_rules.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ static bool fib6_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg
287287
return false;
288288

289289
suppress_route:
290-
ip6_rt_put(rt);
290+
if (!(arg->flags & FIB_LOOKUP_NOREF))
291+
ip6_rt_put(rt);
291292
return true;
292293
}
293294

‎tools/testing/selftests/net/fib_tests.sh‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ret=0
99
ksft_skip=4
1010

1111
# all tests in this script. Can be overridden with -t option
12-
TESTS="unregister down carrier nexthop ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter"
12+
TESTS="unregister down carrier nexthop suppress ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter"
1313

1414
VERBOSE=0
1515
PAUSE_ON_FAIL=no
@@ -614,6 +614,20 @@ fib_nexthop_test()
614614
cleanup
615615
}
616616

617+
fib_suppress_test()
618+
{
619+
$IP link add dummy1 type dummy
620+
$IP link set dummy1 up
621+
$IP -6 route add default dev dummy1
622+
$IP -6 rule add table main suppress_prefixlength 0
623+
ping -f -c 1000 -W 1 1234::1 || true
624+
$IP -6 rule del table main suppress_prefixlength 0
625+
$IP link del dummy1
626+
627+
# If we got here without crashing, we're good.
628+
return 0
629+
}
630+
617631
################################################################################
618632
# Tests on route add and replace
619633

@@ -1591,6 +1605,7 @@ do
15911605
fib_carrier_test|carrier) fib_carrier_test;;
15921606
fib_rp_filter_test|rp_filter) fib_rp_filter_test;;
15931607
fib_nexthop_test|nexthop) fib_nexthop_test;;
1608+
fib_suppress_test|suppress) fib_suppress_test;;
15941609
ipv6_route_test|ipv6_rt) ipv6_route_test;;
15951610
ipv4_route_test|ipv4_rt) ipv4_route_test;;
15961611
ipv6_addr_metric) ipv6_addr_metric_test;;

0 commit comments

Comments
 (0)