Block WSL interop escapes from restricted filesystem sandboxes (#44286)

## Why

With network access enabled, WSL interop can launch Windows processes outside the Linux filesystem sandbox, including using `wsl.exe` to reenter the distribution as root.

## What changed

- Mask WSL interop sockets in bubblewrap when filesystem write access is restricted, and hide inherited procfs when running without a fresh proc mount.
- Deny `AF_VSOCK` sockets and `io_uring` under restricted filesystem policies even when ordinary network access is allowed, closing the VM socket route to host services.
- Reject legacy Landlock configurations that combine restricted filesystem access with unrestricted networking when the WSL interop directory exists.

## Testing

Add unit coverage for mount masking and legacy policy rejection, plus WSL integration tests for Windows process launch, bind aliases, direct `/init` invocation, root reentry, and `--no-proc` isolation. WSL tests skip when host prerequisites are unavailable.

GitOrigin-RevId: 1e8b97ac43675807ee541ca614534d9b1febf410
This commit is contained in:
Ian MacLeod authored and copyberry committed 2026-09-09 19:43:41 +00:00
1 parent 5d3f8752fc
commit f71543813f
5 files changed
+496 -5

No files matched your search

@@ -22,6 +22,7 @@ use std::time::Duration;
use crate::bwrap::BwrapNetworkMode;
use crate::bwrap::BwrapOptions;
use crate::bwrap::WSL_INTEROP_DIR;
use crate::bwrap::create_bwrap_command_args;
use crate::landlock::apply_permission_profile_to_current_thread;
use crate::launcher::exec_bwrap;
@@ -186,7 +187,9 @@ pub fn run_main() -> ! {
use_legacy_landlock,
&file_system_sandbox_policy,
network_sandbox_policy,
allow_network_for_proxy,
&sandbox_policy_cwd,
Path::new(WSL_INTEROP_DIR),
);
// Inner stage: apply seccomp/no_new_privs after bubblewrap has already
@@ -378,7 +381,9 @@ fn ensure_legacy_landlock_mode_supports_policy(
use_legacy_landlock: bool,
file_system_sandbox_policy: &FileSystemSandboxPolicy,
network_sandbox_policy: NetworkSandboxPolicy,
allow_network_for_proxy: bool,
sandbox_policy_cwd: &Path,
wsl_interop_dir: &Path,
) {
if use_legacy_landlock
&& file_system_sandbox_policy
@@ -388,6 +393,18 @@ fn ensure_legacy_landlock_mode_supports_policy(
"permission profiles requiring direct runtime enforcement are incompatible with --use-legacy-landlock"
);
}
if use_legacy_landlock
&& network_sandbox_policy.is_enabled()
&& !allow_network_for_proxy
&& !file_system_sandbox_policy.has_full_disk_write_access()
// Interop can use another binfmt handler or a newly created socket.
// An active endpoint probe would race with sandboxed command startup.
&& wsl_interop_dir.is_dir()
{
panic!(
"legacy Landlock cannot isolate WSL Windows interop with network access enabled; use bubblewrap or restrict network access"
);
}
}
fn run_bwrap_with_proc_fallback(
@@ -414,6 +431,8 @@ fn run_bwrap_with_proc_fallback(
let options = BwrapOptions {
mount_proc,
network_mode,
mask_wsl_interop: !file_system_sandbox_policy.has_full_disk_write_access()
&& Path::new(WSL_INTEROP_DIR).is_dir(),
..Default::default()
};
let mut bwrap_args = build_bwrap_argv(