Fix -x/--exec to also join a session's network namespace

net was deliberately excluded from exec_session.cpp's joinable_namespaces
list, written back when this project never isolated networking at
all. Now that -r/--run sometimes does (whenever -n/--network was
used), -x/--exec'ing into such a session saw the host's own network
stack instead of the container's -- confirmed directly: it showed the
host's unrelated listening ports and couldn't reach the container's
own service on 127.0.0.1.

Fixed by joining net the same way -x/--exec already joins
mnt/uts/ipc/pid/cgroup/user when they differ from the caller's own --
not required, so a session with no isolated net namespace (never
joined any network) is unaffected, the entry is just skipped like any
other identical-to-ours namespace.

Verified as root (via a scoped doas rule): execing into a session
joined to an extern network now correctly shows its own eth0 and
reaches its own service on 127.0.0.1; execing into a plain session
with no -n is unaffected.
This commit is contained in:
2026-08-30 13:39:25 +00:00
parent 7605831269
commit a9cd3bf643
3 changed files with 48 additions and 23 deletions
+5 -4
View File
@@ -276,10 +276,11 @@ pass.
non-loopback interface and drops it as martian) — verified instead via
`curl <host's real IP>:<port>`, the actually-relevant path for real
clients. Also surfaced, unrelated to `-p` itself but found while
testing it: `-x/--exec` doesn't join the `net` namespace (written back
when this project never isolated networking at all), so it currently
sees the *host's* network stack, not a network-isolated session's own —
not fixed as part of this commit.
testing it: `-x/--exec` didn't join the `net` namespace (written back
when this project never isolated networking at all), so it saw the
*host's* network stack, not a network-isolated session's own — fixed in
a follow-up commit (`exec_session.cpp`, see `CLAUDE.md`'s own entry for
that file).
6. **Crash-orphan cleanup sweep**
- Extend `--clean-processes` (or add a dedicated `--clean-networks`,