Skip to content

Phase 3: Hermetic Network & Kernel Sandbox Hardening (WS4.1-WS4.3) - #83

Merged
oyesanyf merged 7 commits into
mainfrom
feat/phase3-hermetic-network-sandbox
Nov 14, 2026
Merged

oyesanyf merged 7 commits into
mainfrom
feat/phase3-hermetic-network-sandbox

Conversation

@oyesanyf

Copy link
Copy Markdown
Owner

Phase 3: Hermetic Network & Kernel Sandbox Hardening (WS4.1, WS4.2, WS4.3)

Summary

Closes network egress, loopback-proxy, link-local IMDS, DNS/QUIC, and process escape gaps across Windows, Linux, and macOS:

  • WS4.1 (Windows WFP/BFE + Capabilityless AppContainer):
    • Hardened crates/killswitch-core/src/wfp.rs to strip blanket loopback/discovery port allowances, enforce AppID + exact 127.0.0.1/::1 control-port rules, block 127.0.0.2..=127.255.255.254 aliases (FWP_MATCH_RANGE), IMDS 169.254.169.254, proxy/lateral/discovery ports, and fail closed outside authorized CI self-diagnostic mode (is_authorized_self_diagnostic()).
    • Implemented IPv4 + IPv6 TCP/UDP socket enumeration and termination via iphlpapi.dll (GetTcp6Table, SetTcp6Entry, GetExtendedTcpTable, GetExtendedUdpTable).
    • Implemented WindowsAppContainerSandbox and spawn_sandboxed_agent_process in crates/killswitch-core/src/job_sandbox.rs using CreateAppContainerProfile (zero capabilities), EXTENDED_STARTUPINFO_PRESENT | CREATE_SUSPENDED, fail-closed AssignProcessToJobObject, IsProcessInJob, and TokenIsAppContainer checks before ResumeThread, with DeleteAppContainerProfile rollback/cleanup.
  • WS4.2 (Linux nftables + Netlink SOCK_DESTROY + Landlock + seccomp-bpf):
    • Fixed add_path_rule dir vs regular-file flags (including LANDLOCK_ACCESS_FS_EXECUTE, ABI>=2 REFER, ABI>=3 TRUNCATE) and added pre-fork async-signal-safe PreparedLinuxSandbox (Landlock + PR_SET_NO_NEW_PRIVS + seccomp-bpf blocking 20 container/kernel breakout syscalls and restricting non-network sockets to AF_UNIX) wired into CommandExt::pre_exec on spawn_sandboxed_agent_process and spawn_confined_process.
    • Added atomic nftables inet killswitch_quarantine generation, installation, mandatory nft list table readback verification, and removal alongside Netlink RTN_BLACKHOLE routes and TCP/UDP/RAW SOCK_DESTROY (build_sock_destroy_msg_for_proto, /proc/net/{udp,udp6,raw,raw6} parsers).
  • WS4.3 (macOS PF + Cross-PID Socket Kill + Seatbelt Sandbox):
    • Hardened crates/killswitch-core/src/pf.rs generate_quarantine_rules to drop blanket lo0/127.0.0.1/::1 catch-alls, block IMDS/link-local/DNS/DoT/DHCP/QUIC/proxy/lateral/127.0.0.2+ traffic, and permit only sanitized exact 127.0.0.1<->127.0.0.1 and ::1<->::1 control ports on lo0.
    • Updated MacOsPfIsolator to load /sbin/pfctl -a com.apple/<anchor> -f - atomically with pfctl -E token tracking, mandatory -sr readback verification, cross-PID socket discovery, pfctl -k / tracked-PID socket termination, and fail-closed privilege checks.
    • Added generate_macos_seatbelt_profile and /usr/bin/sandbox-exec wrapper in spawn_sandboxed_agent_process (macos_seatbelt_sandbox).

Verification Plan

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • GitHub Actions CI across windows-latest, ubuntu-latest, and macos-latest (killswitch-core Landlock/seccomp-bpf, Seatbelt, Windows AppContainer, PF/nftables/WFP tests, Clippy, Binary Integrity, Auto-Review Bot)

…osed AppContainer sandbox

- Remove blanket loopback/control-port allowlists in wfp.rs and scope WFP/BFE permits to KillSwitch AppID, exact localhost, and sanitized bound control ports
- Block 127.0.0.2-127.255.255.255 loopback aliases, cloud IMDS 169.254.169.254, local proxy ports, lateral SMB/WinRM ports, and DNS/DoT/DHCP
- Extend iphlpapi.dll teardown and peer counting to IPv6 TCP, 127.0.0.2+ aliases, proxy ports, and tracked-agent UDP sockets
- Remove fake usermode-session-contract fallback in WindowsWfpIsolator and require in-process or CI-scoped KILLSWITCH_SELF_DIAGNOSTIC authorization
- Implement WindowsAppContainerSandbox and spawn_sandboxed_agent_process with capabilityless SECURITY_CAPABILITIES, CREATE_SUSPENDED, pre-resume Job Object + TokenIsAppContainer verification, and DeleteAppContainerProfile cleanup
- Update empirical_challenge_m1_2, empirical_challenge_m2_2, verify.rs, and killchain.rs for fail-closed quarantine contracts
…_DESTROY containment (WS4.2)

- Harden Linux Landlock add_path_rule (dir vs file access flags, ABI>=2 REFER, ABI>=3 TRUNCATE) and enforce pre-fork async-signal-safe PreparedLinuxSandbox (Landlock + PR_SET_NO_NEW_PRIVS + seccomp-bpf blocking ptrace/mount/unshare/setns/bpf/io_uring_setup and restricting non-network sockets to AF_UNIX) via CommandExt::pre_exec in spawn_sandboxed_agent_process and spawn_confined_process
- Add generate_linux_nftables_quarantine_script, install_linux_nftables_quarantine (atomic inet killswitch_quarantine table + readback verify), and remove_linux_nftables_quarantine, removing blanket loopback/discovery allows
- Extend Netlink SOCK_DESTROY (build_sock_destroy_msg_for_proto) and /proc/net/{udp,udp6,raw,raw6} parsers to destroy non-localhost TCP, UDP, RAW, 127.0.0.2+ alias, and loopback proxy sockets with fail-closed privilege gating
- Update lib.rs exports and WS4.2 integration/unit tests
…tbelt sandbox (WS4.3)

- Harden pf.rs generate_quarantine_rules removing blanket lo0/127.0.0.1/::1 catch-alls, explicitly blocking IMDS (169.254.0.0/16, fe80::/10), DNS/DoT/DHCP/QUIC, loopback proxy ports (1080/3128/8080/8888/9050), lateral SMB/WinRM, and 127.0.0.2+ aliases while permitting ONLY sanitized exact 127.0.0.1<->127.0.0.1 and ::1<->::1 control ports on lo0
- Update MacOsPfIsolator to drive /sbin/pfctl -a com.apple/<anchor> atomically with pfctl -E token management, mandatory pfctl -sr readback verification, pfctl -k / tracked-PID state severing, fail-closed privilege checks, and cross-PID socket inspection (lsof/netstat/proc_fdinfo)
- Implement generate_macos_seatbelt_profile and wire /usr/bin/sandbox-exec into spawn_sandboxed_agent_process on macOS with SBPL deny default and deny network*
- Export generate_macos_seatbelt_profile in lib.rs and update macOS PF/Seatbelt tests
…s, and MibTcp6Row size assertion

- Drop DashMap read guard on tainted_descendants before cache_tainted_descendant() writes back in agent_registry.rs, preventing intra-thread shard self-deadlock on child chains, and add pigeonhole shard-collision regression test
- Fix MibTcp6Row size assertion in wfp.rs to match 52-byte _MIB_TCP6ROW Windows SDK ABI and assert MibTcp6RowOwnerPid is 56 bytes
- Guard Windows-only tracing::warn and IPv4/IPv6 localhost/proxy helpers with cfg(windows)/cfg(any(windows, test)) in wfp.rs
- Replace manual loop in landlock.rs find_nft_binary with Iterator::find for clippy::manual-find
- Pass process name argument to crate::killchain::is_critical_system_pid in pf.rs
- Guard Mutex/OnceLock imports and mut bindings in job_sandbox.rs for macOS clean builds
- Guard Duration and debug imports in exec_sensor.rs for macOS clean builds
…-OS warnings

- Add file-map-executable across read-only system/executable subpaths, process-info-pidinfo, dev ioctl, cryptex/select/homebrew read paths, and scoped syslog/libinfo mach-lookup in pf.rs generate_macos_seatbelt_profile so /bin/sh and /usr/bin/python3 execute cleanly under (deny default) while preserving write/network confinement
- Scope is_blocked_proxy_port in wfp.rs strictly with #[cfg(windows)] so Linux/macOS Clippy -D warnings passes cleanly
- Join worker_handle cleanly in MacOsProcessSensor::stop and guard detected_host_kernel_filters mutability in ring0_driver_loader.rs for warning-free macOS builds
…arden macOS Seatbelt SBPL execution

- Add workspace crate killswitch-kernel-patcher with OS/kernel CPE 2.3 discovery (Windows RtlGetVersion + Registry, Linux /etc/os-release + uname, macOS sysctlbyname), NVD API 2.0 client (runtime env NVD_API_KEY only, zero secret persistence), CISA KEV prioritization & CVSS sorting, fail-closed privilege gating (IsElevated / geteuid), OS-native patch orchestration (UsoClient, canonical-livepatch/apt-get/dnf, softwareupdate), and multi-tier offline/live test suites
- Wire `killswitch patch-kernel` CLI subcommand and periodic server NVD/KEV background scanner (with KernelScanSummary caching and dry-run/non-root safety)
- Harden macOS Seatbelt SBPL profile in pf.rs (`(import "system.sb")` baseline plus explicit executable/path isolation and `(deny network*)`), resolve bare command names via PATH before entering sandbox-exec, and report Unix signal termination accurately (128 + sig) in job_sandbox.rs
- Protect `.env` / `.env.*` in .gitignore cleanly
…ng, and macOS python3 Seatbelt CWD scan

- Guard Windows-only imports in discovery/windows.rs with #[cfg(windows)] so Linux Clippy passes with zero unused-import errors
- Filter empty/whitespace NVD_API_KEY values in patcher.rs before setting the HTTP apiKey header
- Set readable sandboxed current_dir and isolated mode (-I) on the Seatbelt test subprocesses in job_sandbox.rs so Apple python3 importlib does not stat restricted workspace directories before loading stdlib sockets
@oyesanyf
oyesanyf merged commit ef72b67 into main Nov 14, 2026
7 checks passed
@oyesanyf
oyesanyf deleted the feat/phase3-hermetic-network-sandbox branch November 14, 2026 13:27
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