]> git.baikalelectronics.ru Git - kernel.git/commit
ipv4: Fix device used for dst_alloc with local routes
authorDavid Ahern <dsahern@kernel.org>
Sun, 13 Jun 2021 00:24:59 +0000 (18:24 -0600)
committerDavid S. Miller <davem@davemloft.net>
Mon, 14 Jun 2021 19:30:53 +0000 (12:30 -0700)
commit1b301f02478af248f677472a3017f160d595ba97
tree2ed3760e3200588d63e10f077eb4ea6db37a4bf5
parent15437fa579a81acda172bb14f5a6cdff3ae11bb2
ipv4: Fix device used for dst_alloc with local routes

Oliver reported a use case where deleting a VRF device can hang
waiting for the refcnt to drop to 0. The root cause is that the dst
is allocated against the VRF device but cached on the loopback
device.

The use case (added to the selftests) has an implicit VRF crossing
due to the ordering of the FIB rules (lookup local is before the
l3mdev rule, but the problem occurs even if the FIB rules are
re-ordered with local after l3mdev because the VRF table does not
have a default route to terminate the lookup). The end result is
is that the FIB lookup returns the loopback device as the nexthop,
but the ingress device is in a VRF. The mismatch causes the dst
alloc against the VRF device but then cached on the loopback.

The fix is to bring the trick used for IPv6 (see ip6_rt_get_dev_rcu):
pick the dst alloc device based the fib lookup result but with checks
that the result has a nexthop device (e.g., not an unreachable or
prohibit entry).

Fixes: f1cc121cc4fa ("net: ipv4: dst for local input routes should use l3mdev if relevant")
Reported-by: Oliver Herms <oliver.peter.herms@gmail.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/route.c
tools/testing/selftests/net/fib_tests.sh