mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
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
This commit is contained in:
@@ -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> {
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user