Re: [PATCH net-next v5 0/4] ipv4: restrict on-link fallback to lookup misses
From: Ido Schimmel
Date: Tue Nov 17 2026 - 05:57:01 EST
On Mon, Nov 16, 2026 at 08:27:37PM +0000, liamsmith827 wrote:
> From: Liam Smith <liamsmith827@xxxxxxxxx>
>
> When an output interface is specified (e.g., using SO_BINDTODEVICE,
> IP_UNICAST_IF or IP_PKTINFO) and the FIB lookup fails, the IPv4 output
> path ignores the error and constructs an on-link route via the
> specified interface. According to the comment above the code, the
> intent was to allow sending packets via an interface that does not have
> any routes.
>
> However, the error code is not checked, so the fallback is also taken
> when the lookup hits an unreachable, blackhole or prohibit route/rule.
> In other words, these routes and rules are ignored when an output
> interface is specified [1].
>
> This is a problem for Android, which implements its VPN "kill switch"
> using prohibit rules, with the expectation that packets hitting such
> rules are never transmitted. Unprivileged applications can bind a
> socket to an interface and trivially bypass the VPN. This is especially
> bad on cellular interfaces where neighbor resolution is not needed, so
> packets can reach any destination and not only on-link ones.
>
> Solve this by only taking the fallback when the lookup did not match
> any route (i.e., a miss) and returning the error to the caller
> otherwise [2].
>
> It is currently impossible to distinguish between a miss and an
> unreachable rule since they both return the same error (-ENETUNREACH).
> Therefore, patch #1 adds a lookup flag that makes the lookup return a
> different error upon a miss and patch #2 uses it to restrict the
> fallback. Patch #3 adjusts the selftests and patch #4 updates the
> comment above the fallback.
>
> After the change, a packet that was previously transmitted on-link
> despite hitting one of these routes/rules is no longer transmitted and
> an error is returned to user space instead. It is unlikely that anyone
> is relying on the current behavior:
>
> 1. It is a side effect of not checking the error code and it contradicts
> ip-route(8) and ip-rule(8), which document these routes and rules as
> dropping packets or generating an error.
>
> 2. These routes and rules are already honored when the output interface
> is a VRF device or enslaved to one.
>
> 3. These rules are already honored by IPv6, which does not have such a
> fallback.
>
> The following is unchanged:
>
> 1. Packets can still be sent via the specified interface when the
> lookup does not match any route, which is the original use case.
>
> 2. The fallback is still always taken for multicast packets. The
> precedent in ip_route_output_key_hash_rcu() is to not enforce
> restriction rule/routes on oif-bound multicast, so that precedent should
> be followed here too.
I think this series can be merged. It does change user-visible behavior,
but the regression risk seems to be low. Any configuration broken by
this change most likely doesn't work with VRFs / IPv6. If regressions
are reported, we can look into allowing the fallback for specific error
codes.
Reviewed-by: Ido Schimmel <idosch@xxxxxxxxxx>