Files
tailscale/util
Mike O'Driscoll 1aad7a1386 wgengine/router/osrouter,util/linuxfw: add rp_filter source rules
With an exit node, table 52's default route makes strict reverse path
filtering drop replies to tailscaled's own sockets: the kernel checks a
reply's source with a reverse lookup, as uid 0 from the underlay
address, which finds the default route via the Tailscale interface
rather than the one the reply arrived on (#3310). The reverted
src_valid_mark=1 workaround fixed that for the whole host and broke
every other fwmark user (#19796).

Instead, while 0.0.0.0/0 or ::/0 is routed into table 52, install per
address family:

	pref base+55: not fwmark <bypass> lookup 52 suppress_prefixlength 0
	pref base+60: from A uidrange 0-0 lookup main

with a base+60 rule for each underlay address A. base+60 sends the
reverse lookup to the main table, and base+55 keeps table 52's tailnet
and LAN routes ahead of it, so tailnet peers still reach A through the
tunnel and ExitNodeAllowLANAccess=false still blocks the LAN. IPv6,
which has no kernel rp_filter, gets its rules whenever ::/0 is routed.
The IPv4 rules only exist while rp_filter is strict somewhere, re-read
every 10s while an exit node is in use since a sysctl write raises no
event.

The rules are added before the exit node's default route and removed
after it is gone, and in Close. They follow netmon's interface state,
for at most 128 addresses per family and never for our own Tailscale
addresses. They carry rule protocol 52; Up and tailscaled's startup
cleanup sweep away any a previous instance left. They don't use
netfilter, so they work in every netfilter mode.
TS_DEBUG_DISABLE_RPFILTER_SRC_RULES=true turns them off. The router
ignores deletions at their priorities instead of restoring the base
rules, since those deletions are its own.

linuxfw documents that the connmark rules only help reverse path checks
that are mark-aware.

Follow-ups cover replies from LAN peers to the magicsock port with LAN
access off, and rules other processes delete. Not covered, and pinned
by tests: remotes that a more specific table 52 route covers, such as
an accepted subnet route, and IPv4 netfilter reverse path checks
without a strict kernel rp_filter. Nor are hosts whose underlay default
route is not in main.

Behavior change: while an exit node is in use, sockets of root
processes bound to an underlay address, and packets the kernel itself
sends from one, leave by the physical interface rather than the exit
node; non-root processes are unaffected. That holds for IPv6 on every
host and for IPv4 where rp_filter is strict. Hosts that ran a release
with the reverted change keep src_valid_mark=1 until reboot or reset.

RELNOTE: Linux: exit nodes no longer set src_valid_mark=1; root sockets
bound to a physical interface's address now bypass the exit node.

Updates #3310
Updates #19796

Signed-off-by: Mike O'Driscoll <[email protected]>
2026-11-23 11:39:16 -05:00
..
2026-11-14 09:50:33 -08:00
2026-11-14 09:50:33 -08:00