From a11d2403a5c8f346527379ccd061c2aa95e7edc4 Mon Sep 17 00:00:00 2001 From: viyatb-oai Date: Mon, 16 Nov 2026 22:26:05 +0000 Subject: [PATCH] Fix proc mount fallback detection for Bubblewrap 0.12 (#61900) ## Why Bubblewrap 0.12 reports proc mount failures at `/proc` instead of `/newroot/proc`, so the Linux sandbox preflight did not recognize failures that should enable the existing fallback. ## What changed Recognize both destinations for `Invalid argument`, `Operation not permitted`, and `Permission denied`. Match the destination and error on the same diagnostic line to avoid treating unrelated errors as proc mount failures. ## Testing Extend unit tests to cover both diagnostic formats and reject unrelated destinations, unsupported errors, and errors on separate lines. Exercise the fallback and explicit PID namespace inheritance integration test with both destinations. GitOrigin-RevId: 7cb0d004cd88ec3dcf14960497c1fac665e6e74a --- codex-rs/linux-sandbox/src/linux_run_main.rs | 18 ++++++--- .../linux-sandbox/src/linux_run_main_tests.rs | 37 +++++++++---------- .../tests/suite/managed_proxy.rs | 12 +++++- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/codex-rs/linux-sandbox/src/linux_run_main.rs b/codex-rs/linux-sandbox/src/linux_run_main.rs index b6873663ac..4a8774fbc1 100644 --- a/codex-rs/linux-sandbox/src/linux_run_main.rs +++ b/codex-rs/linux-sandbox/src/linux_run_main.rs @@ -1217,11 +1217,19 @@ fn close_fd_or_panic(fd: libc::c_int, context: &str) { } fn is_proc_mount_failure(stderr: &str) -> bool { - stderr.contains("Can't mount proc") - && stderr.contains("/newroot/proc") - && (stderr.contains("Invalid argument") - || stderr.contains("Operation not permitted") - || stderr.contains("Permission denied")) + stderr.lines().any(|line| { + let Some((_, diagnostic)) = line.split_once("Can't mount proc on ") else { + return false; + }; + // Bubblewrap 0.12 reports the destination inside the sandbox. + matches!( + diagnostic.split_once(": "), + Some(( + "/newroot/proc" | "/proc", + "Invalid argument" | "Operation not permitted" | "Permission denied" + )) + ) + }) } struct InnerSeccompCommandArgs<'a> { diff --git a/codex-rs/linux-sandbox/src/linux_run_main_tests.rs b/codex-rs/linux-sandbox/src/linux_run_main_tests.rs index 4938bfca11..2909c19ebf 100644 --- a/codex-rs/linux-sandbox/src/linux_run_main_tests.rs +++ b/codex-rs/linux-sandbox/src/linux_run_main_tests.rs @@ -25,28 +25,25 @@ fn read_only_file_system_policy() -> FileSystemSandboxPolicy { read_only_permission_profile().file_system_sandbox_policy() } -#[test] -fn detects_proc_mount_invalid_argument_failure() { - let stderr = "bwrap: Can't mount proc on /newroot/proc: Invalid argument"; - assert!(is_proc_mount_failure(stderr)); +#[test_case::test_case("/newroot/proc"; "older bubblewrap")] +#[test_case::test_case("/proc"; "bubblewrap 0.12")] +fn detects_proc_mount_failures(destination: &str) { + for error in [ + "Invalid argument", + "Operation not permitted", + "Permission denied", + ] { + let stderr = format!("bwrap: Can't mount proc on {destination}: {error}\n"); + assert!(is_proc_mount_failure(&stderr), "{stderr}"); + } } -#[test] -fn detects_proc_mount_operation_not_permitted_failure() { - let stderr = "bwrap: Can't mount proc on /newroot/proc: Operation not permitted"; - assert!(is_proc_mount_failure(stderr)); -} - -#[test] -fn detects_proc_mount_permission_denied_failure() { - let stderr = "bwrap: Can't mount proc on /newroot/proc: Permission denied"; - assert!(is_proc_mount_failure(stderr)); -} - -#[test] -fn ignores_non_proc_mount_errors() { - let stderr = "bwrap: Can't bind mount /dev/null: Operation not permitted"; - assert!(!is_proc_mount_failure(stderr)); +#[test_case::test_case("bwrap: Can't bind mount /dev/null: Operation not permitted"; "non proc mount")] +#[test_case::test_case("bwrap: Can't mount proc on /proc-other: Operation not permitted"; "different destination")] +#[test_case::test_case("bwrap: Can't mount proc on /proc: Limit exceeded (ENOSPC)"; "unhandled mount error")] +#[test_case::test_case("bwrap: Can't mount proc on /newroot/proc: Limit exceeded (ENOSPC)\nbwrap: Permission denied"; "unrelated error on a different line")] +fn ignores_unrelated_mount_errors(stderr: &str) { + assert!(!is_proc_mount_failure(stderr), "{stderr}"); } #[test] diff --git a/codex-rs/linux-sandbox/tests/suite/managed_proxy.rs b/codex-rs/linux-sandbox/tests/suite/managed_proxy.rs index 70efb1962e..82124b7b6e 100644 --- a/codex-rs/linux-sandbox/tests/suite/managed_proxy.rs +++ b/codex-rs/linux-sandbox/tests/suite/managed_proxy.rs @@ -339,8 +339,12 @@ async fn namespace_reaper_collects_orphaned_descendants() { assert_eq!(output.stdout, b"orphan reaped\n"); } +#[test_case::test_case("/newroot/proc"; "older bubblewrap")] +#[test_case::test_case("/proc"; "bubblewrap 0.12")] #[tokio::test] -async fn proc_mount_denial_preserves_legacy_fallback_and_explicit_pid_inheritance() { +async fn proc_mount_denial_preserves_legacy_fallback_and_explicit_pid_inheritance( + destination: &str, +) { if should_skip_bwrap_tests().await { eprintln!("skipping bwrap test: bubblewrap is unavailable"); return; @@ -361,7 +365,7 @@ async fn proc_mount_denial_preserves_legacy_fallback_and_explicit_pid_inheritanc for arg in "$@"; do [ "$arg" = "--" ] && break if [ "$arg" = "--proc" ]; then - printf '%s\n' "bwrap: Can't mount proc on /newroot/proc: Operation not permitted" >&2 + printf '%s\n' "bwrap: Can't mount proc on $CODEX_TEST_PROC_DESTINATION: Operation not permitted" >&2 exit 1 fi done @@ -419,6 +423,10 @@ printf 'legacy proc fallback\n' "CODEX_TEST_REAL_BWRAP".to_string(), system_bwrap.display().to_string(), ); + env.insert( + "CODEX_TEST_PROC_DESTINATION".to_string(), + destination.to_string(), + ); env.insert( "CODEX_TEST_PID_NAMESPACE".to_string(), pid_namespace.display().to_string(),