From: Liam Smith For non-vrf unicast, the on-link fallback currently occurs regardless of the particular error returned by fib_lookup(). As a result, routes and rules that are supposed to restrict traffic (blackhole, prohibit, unreachable) are unable to do so comprehensively. A specific example of this being a problem is within Android, where the VPN "kill switch" is implemented with prohibit rules. Any process that can set flowi4_oif (SO_BINDTODEVICE, IP_UNICAST_IF, IP_PKTINFO, etc.) is able to utilize this fallback, meaning unprivileged Android apps can trivially bypass the VPN. This is particularly bad on cellular networks, where ARP is often not needed. Restrict the fallback to routing lookup misses. This was originally observed on an Android device, by way of packet capture. Tested fcnal-test.sh in UML with CONFIG_IP_MULTIPLE_TABLES both enabled and disabled. Signed-off-by: Liam Smith --- net/ipv4/route.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 595a3b7f1783..03db105303b4 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -2849,12 +2849,13 @@ struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4, goto make_route; } - err = fib_lookup(net, fl4, res, 0); + err = fib_lookup(net, fl4, res, FIB_LOOKUP_REPORT_MISS); if (err) { res->fi = NULL; res->table = NULL; if (fl4->flowi4_oif && - (ipv4_is_multicast(fl4->daddr) || !fl4->flowi4_l3mdev)) { + (ipv4_is_multicast(fl4->daddr) || + (!fl4->flowi4_l3mdev && err == -ESRCH))) { /* Apparently, routing tables are wrong. Assume, * that the destination is on link. * @@ -2879,6 +2880,8 @@ struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4, res->type = RTN_UNICAST; goto make_route; } + /* Reverse the mapping induced by FIB_LOOKUP_REPORT_MISS. */ + err = err == -ESRCH ? -ENETUNREACH : err; rth = ERR_PTR(err); goto out; } -- 2.47.3