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:
viyatb-oai
2026-11-16 22:41:51 +00:00
committed by copyberry
parent 641b4cac88
commit a11d2403a5
3 changed files with 40 additions and 27 deletions
+13 -5
View File
@@ -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]