Skip to content

Allow host TCP connects under Landlock when dialing directly - #233

Open
dividedby wants to merge 1 commit into
windtf:masterfrom
dividedby:feat/landlock-net
Open

dividedby wants to merge 1 commit into
windtf:masterfrom
dividedby:feat/landlock-net

Conversation

@dividedby

Copy link
Copy Markdown

Summary

On kernels with Landlock ABI 4+ (Linux 6.7+), lockNetwork restricts TCP connect as well as bind, and only TCPServerTunnel targets get a ConnectTCP rule. That silently breaks host-side connects wireproxy itself makes:

  • direct dials for hosts not matched by TunnelDomains (HTTP, SOCKS5 and SNI split routing);
  • system-resolver lookups that fall back to TCP (truncated answers) when DNS is not set.

The rule choice is now a testable function:

  • if any routine can dial directly (TunnelDomains set) or the system resolver is in use (no DNS), only TCP bind is restricted;
  • otherwise connect stays restricted to the server-tunnel targets plus TCP port 53.

/etc/hosts and /etc/nsswitch.conf are added next to /etc/resolv.conf in the read-only rules, so the Go resolver can still read them after the lockdown. On kernels without ABI 4 the best-effort config is unchanged (nothing is restricted).

Test plan

  • go test -race ./..., go vet ./... (also GOOS=linux), gofmt -l ., golangci-lint (fork CI green).
  • New tests in cmd/wireproxy/main_test.go: rule selection across six configurations and the resolver file list. The kernel call itself is not exercised in tests.

🤖 Generated with Claude Code

lockNetwork handled both bind and connect for TCP with V4, but only
TCPServerTunnel targets received a connect rule. On kernels with Landlock
ABI 4 or newer this denied host-side connects: split-routing direct dials
(TunnelDomains on HTTP/SOCKS5/SNI), and the Go resolver's TCP fallback for
truncated DNS answers, which covers lookups through the system resolver.

Choose the rules in networkRules. When any routine may dial directly
(TunnelDomains set, or no DNS = so names resolve on the host), only TCP bind
is restricted. Otherwise connect stays restricted, with an additional
allowance for TCP port 53 for the resolver's TCP fallback. Endpoint
re-resolution uses the system resolver, so it relies on this.

Also allow reading /etc/hosts and /etc/nsswitch.conf after lockdown (next to
/etc/resolv.conf), which the Go resolver consults for host lookups.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant