mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: liamsmith827 <liamsmith827@grapheneos.org>
To: netdev@vger.kernel.org
Cc: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	horms@kernel.org, shuah@kernel.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	liamsmith827 <liamsmith827@proton.me>
Subject: [RFC net-next 1/2] ipv4: Honor prohibit when oif specified
Date: Mon, 19 Oct 2026 03:24:05 +0000	[thread overview]
Message-ID: <20261019032406.88874-2-liamsmith827@grapheneos.org> (raw)
In-Reply-To: <20261019032406.88874-1-liamsmith827@grapheneos.org>

From: liamsmith827 <liamsmith827@proton.me>

When flowi4_oif is set (SO_BINDTODEVICE, IP_PKTINFO, IP_UNICAST_IF,
etc), prohibit rules and routes cause fib_lookup() to return -EACCES,
but still allow the packet (and any necessary ARP) to be transmitted.
This is documented as the expected behavior in the tests, but is
confusing for route and rule maintainers. Specifically, Android uses
prohibit rules as the basis for its VPN "kill switch", with the
expectation that any packet encountering such a rule will not be allowed
out. Due to this interface binding exemption, apps can trivially bypass
the kill switch. This is most serious on cellular networks, where a
connection to an arbitrary IPv4 address can be established without
requiring ARP resolution.

Preserve -EACCES from fib_lookup() instead of constructing an on-link
route when an output interface is specified. This honors prohibit rules
and routes while retaining the existing fallback for other lookup
errors.

Signed-off-by: liamsmith827 <liamsmith827@proton.me>
---
 net/ipv4/route.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 595a3b7f1783..616c20299334 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2853,7 +2853,7 @@ struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4,
 	if (err) {
 		res->fi = NULL;
 		res->table = NULL;
-		if (fl4->flowi4_oif &&
+		if (fl4->flowi4_oif && err != -EACCES &&
 		    (ipv4_is_multicast(fl4->daddr) || !fl4->flowi4_l3mdev)) {
 			/* Apparently, routing tables are wrong. Assume,
 			 * that the destination is on link.
@@ -2864,13 +2864,14 @@ struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *fl4,
 			 * addresses. When oif is specified, routing
 			 * tables are looked up with only one purpose:
 			 * to catch if destination is gatewayed, rather than
-			 * direct. Moreover, if MSG_DONTROUTE is set,
-			 * we send packet, ignoring both routing tables
-			 * and ifaddr state. --ANK
-			 *
+			 * direct.
 			 *
 			 * We could make it even if oif is unknown,
 			 * likely IPv6, but we do not.
+			 *
+			 * Additionally, when oif is specified, routing lookup
+			 * allows us to check if destination is prohibited
+			 * (-EACCES). LS.
 			 */
 
 			if (fl4->saddr == 0)
-- 
2.47.3


  reply	other threads:[~2026-10-19  3:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19  3:24 [RFC net-next 0/2] " liamsmith827
2026-10-19  3:24 ` liamsmith827 [this message]
2026-10-25 17:13   ` [RFC net-next 1/2] " Ido Schimmel
2026-10-19  3:24 ` [RFC net-next 2/2] selftests: net: Test " liamsmith827

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261019032406.88874-2-liamsmith827@grapheneos.org \
    --to=liamsmith827@grapheneos.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=liamsmith827@proton.me \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®