Leadaxe 报告 sing-box-lx 在 Linux 停止自动重定向后未恢复 rp_filter
Leadaxe 报告,Linux 上的 TUN auto_redirect 会将各接口、all 和 default 的 rp_filter 设为 0,停止后仍不恢复,使反向路径过滤保持关闭;其复现来自 Ubuntu runner 的网络命名空间,Android、macOS 和单独使用 auto_route 不在该报告范围。他说明,其分支在清零前记录原有非零值,在该命名空间最后一个 auto_redirect 关闭时恢复,且只恢复仍为 0 的键,保留运行期间他人作出的修改。新建接口继承的 0,以及 SIGKILL、崩溃或 OOM 后的恢复仍不覆盖。
作者原文@LeadaxeSymptom
On Linux, a tun inbound with
auto_redirectsetsnet.ipv4.conf.*.rp_filterto0on start and leaves it there after sing-box stops. Reverse path filtering (protection against spoofed source addresses) stays off on every interface, onalland ondefault(so on interfaces created later too) until the next reboot. On OpenWrt, whereallanddefaultare1out of the box, a router running the core withauto_redirectsilently loses this protection once the core is stopped or removed.Affected:
v1.14.6-lx.41…v1.14.7-lx.45, Linux only (OpenWrt routers, Linux desktop). Android and macOS are not affected. Plainauto_routewithoutauto_redirectdoes not touch the global keys.Reproduced in a network namespace on an Ubuntu runner, values before start
all=1 default=1 lo=0 vn=2:| | while running | after stop |
|---|---|---|
| lx.45, start → stop |all=0 default=0 vn=0|all=0 default=0 vn=0|
| lx.45, start → SIGHUP → stop |all=0 default=0 vn=0|all=0 default=0 vn=0|Cause
The code is upstream's (sing-tun
redirect_linux.go,enableForwarding, commit7247a83, 2026-11-29). Auto-redirect needsrp_filter=0while it runs: packets of LAN clients arrive on the LAN interface, get a mark, and policy routing sends them to the tun table, so a strict reverse path check drops them. sing-tun writes0into every entry of/proc/sys/net/ipv4/confandClosenever writes the old values back.Two minutes earlier upstream removed the restore of the forwarding sysctls on close on purpose (
0ec7ffa, "Keep forwarding sysctls enabled after auto-redirect close");rp_filterwas added without a restore as well. No reason is given. Writing IPv6forwardingback is disruptive by itself (the kernel propagates it to every interface and touches RA default routes), writingrp_filterback is not. Leaving forwarding on keeps a capability, leavingrp_filteroff removes a protection, so I treat the latter as a defect. sing-tundevhas the same code.Narrowing it down is not an option: the effective value is
max(all, interface), soallhas to go to0anyway, and the drop happens on the ingress interface, not on the tun. Loose mode2instead of0can still drop sources routed through WireGuard and other tunnels in separate policy routing tables.Fix
- Right before zeroing, the fork remembers the non-zero
rp_filtervalues of everyconfentry.- When the last auto-redirect of that network namespace closes, they are written back.
- A key is restored only if it still reads
0; a key someone changed while sing-box ran is left alone.- Forwarding and
accept_rakeep the upstream behaviour.Limits: interfaces created while sing-box runs inherit
default=0and keep it; after SIGKILL, a crash or OOM nothing is restored (a state file in/runwould cover that and is noted in the SPEC as a possible follow-up).