From 167d05bc82dbb7d435696b2ccd43300c7825bf31 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 15 Nov 2026 15:06:41 +0000 Subject: [PATCH] net/netns: honor ALL_PROXY when netns is disabled netns.SetEnabled(false) is for processes like userspace-only clients whose traffic never routes back into themselves, so they don't need the namespace setup. But FromDialer also skipped the ALL_PROXY SOCKS wrapping when disabled, so such processes couldn't reach the internet in environments that only allow egress via a proxy, such as ChatGPT Work's sandbox. Only skip the namespace setup when disabled, and still wrap the dialer for the proxy. Updates #22412 Signed-off-by: Brad Fitzpatrick Change-Id: Ic2023a329c640a1e8de32b157ed608ba385000a1 --- net/netns/control_test.go | 6 +++--- net/netns/netns.go | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/net/netns/control_test.go b/net/netns/control_test.go index 48ff6230d..df3e82a8c 100644 --- a/net/netns/control_test.go +++ b/net/netns/control_test.go @@ -109,10 +109,10 @@ func TestFromDialerControlContext(t *testing.T) { } } got := FromDialer(t.Logf, netmon.NewStatic(), d) - if want := proxy && !disable; wrapped != want { - t.Errorf("proxy wrapped = %v; want %v", wrapped, want) + if wrapped != proxy { + t.Errorf("proxy wrapped = %v; want %v", wrapped, proxy) } - if disable && got != d { + if disable && !proxy && got != d { t.Error("disabled FromDialer did not return the original dialer") } if d.Control != nil { diff --git a/net/netns/netns.go b/net/netns/netns.go index 6f0e2a9ee..594979f3b 100644 --- a/net/netns/netns.go +++ b/net/netns/netns.go @@ -119,7 +119,8 @@ func NewDialer(logf logger.Logf, netMon *netmon.Monitor) Dialer { // // FromDialer modifies d and may wrap it to use SOCKS if configured by ALL_PROXY. // The hooks apply to the underlying socket (to the proxy when using SOCKS). -// When netns is disabled, d is returned unchanged and without proxy wrapping. +// When netns is disabled, d gets no namespace setup but may still be wrapped +// to use SOCKS. func FromDialer(logf logger.Logf, netMon *netmon.Monitor, d *net.Dialer) Dialer { if netMon == nil { panic("netns.FromDialer called with nil netMon") @@ -127,10 +128,12 @@ func FromDialer(logf logger.Logf, netMon *netmon.Monitor, d *net.Dialer) Dialer if d.Control != nil { panic("netns.FromDialer: use ControlContext instead of Control") } - if disabled.Load() { - return d + // Disabling netns only turns off the namespace setup. Processes that + // disable it, such as userspace-only clients that never route traffic + // back into themselves, may still need to honor ALL_PROXY. + if !disabled.Load() { + setNamespaceControl(d, control(logf, netMon)) } - setNamespaceControl(d, control(logf, netMon)) if wrapDialer != nil { return wrapDialer(d) }