mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Isolate app-server Unix sockets from filesystem-restricted commands (#45984)
## Why Network access and Unix-socket allowlists must not let commands with filesystem restrictions reach the privileged app-server RPC transport. ## What changed - Bind Unix control sockets in a fixed, user-owned directory with mode `0700`, independent of environment settings, and expose the advertised paths as symlinks. Preserve existing parent permissions, reject unsafe parents, and serialize socket setup and publication. - Mask the socket directory in Linux bubblewrap sandboxes after each bind that exposes it. Reject host mount aliases and nested mounts that compromise isolation. - Deny access to the directory and outbound connections to its sockets in macOS Seatbelt policies, including when network access or Unix-socket allowlists grant broader access. - Require bubblewrap for filesystem-restricted Linux execution. Users with `features.use_legacy_landlock` enabled must disable it for these policies. ## Testing Add regression coverage for direct and symlink socket access, hardlink attempts, Linux host-process links and bind-mount aliases, and continued use of unrelated and sandbox-local sockets. Add transport coverage for parent permissions, concurrent restart after a stale symlink, and cleanup that preserves a replacement at the advertised path. GitOrigin-RevId: 53372c27eea278d964f2cf68aed24323ef3b7082
This commit is contained in:
1 parent
0666c12e78
commit
49305d74b4
25 files changed
+828
-191
No files matched your search
@@ -246,7 +246,7 @@ async fn assert_seccomp_filtered_namespace_reaper(
|
||||
&[
|
||||
"bash",
|
||||
"-c",
|
||||
"if [ \"$(readlink /proc/1/ns/pid 2>/dev/null)\" != \"$(readlink /proc/self/ns/pid 2>/dev/null)\" ]; then printf 'namespace proc unavailable\\n'; exit 0; fi; printf '%s\\n' \"$PPID\"; awk '$1 == \"Seccomp:\" && FNR == NR { print $2 } $1 == \"Seccomp_filters:\" { print $2 }' /proc/1/status /proc/self/status",
|
||||
"if [ ! -r /proc/self/status ] || [ ! -r /proc/1/status ] || [ \"$(readlink /proc/1/ns/pid 2>/dev/null)\" != \"$(readlink /proc/self/ns/pid 2>/dev/null)\" ]; then printf 'namespace proc unavailable\\n'; exit 0; fi; printf '%s\\n' \"$PPID\"; awk '$1 == \"Seccomp:\" && FNR == NR { print $2 } $1 == \"Seccomp_filters:\" { print $2 }' /proc/1/status /proc/self/status",
|
||||
],
|
||||
permission_profile,
|
||||
allow_network_for_proxy,
|
||||
@@ -286,7 +286,7 @@ async fn namespace_reaper_collects_orphaned_descendants() {
|
||||
&[
|
||||
"bash",
|
||||
"-c",
|
||||
"if [ \"$(readlink /proc/1/ns/pid 2>/dev/null)\" != \"$(readlink /proc/self/ns/pid 2>/dev/null)\" ]; then printf 'namespace proc unavailable\\n'; exit 0; fi; orphan=$(bash -c 'sleep 0.05 </dev/null >/dev/null 2>&1 & printf \"%s\\n\" \"$!\"'); for _ in $(seq 1 100); do if [ ! -e \"/proc/$orphan\" ]; then printf 'orphan reaped\\n'; exit 0; fi; sleep 0.01; done; exit 1",
|
||||
"if [ ! -r /proc/self/status ] || [ ! -r /proc/1/status ] || [ \"$(readlink /proc/1/ns/pid 2>/dev/null)\" != \"$(readlink /proc/self/ns/pid 2>/dev/null)\" ]; then printf 'namespace proc unavailable\\n'; exit 0; fi; orphan=$(bash -c 'sleep 0.05 </dev/null >/dev/null 2>&1 & printf \"%s\\n\" \"$!\"'); for _ in $(seq 1 100); do if [ ! -e \"/proc/$orphan\" ]; then printf 'orphan reaped\\n'; exit 0; fi; sleep 0.01; done; exit 1",
|
||||
],
|
||||
&PermissionProfile::read_only(),
|
||||
/*allow_network_for_proxy*/ false,
|
||||
@@ -717,18 +717,25 @@ fn handoff_client() {
|
||||
return;
|
||||
};
|
||||
assert!(std::env::var_os(PROXY_ATTRIBUTION_TOKEN_ENV_KEY).is_none());
|
||||
let inherited_sockets = std::fs::read_dir("/proc/self/fd")
|
||||
.expect("enumerate inherited descriptors")
|
||||
.filter_map(Result::ok)
|
||||
.filter_map(|entry| {
|
||||
let target = std::fs::read_link(entry.path()).ok()?;
|
||||
target
|
||||
.to_string_lossy()
|
||||
.starts_with("socket:")
|
||||
.then(|| (entry.file_name(), target))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(inherited_sockets, Vec::new(), "privileged socket leaked");
|
||||
match std::fs::read_dir("/proc/self/fd") {
|
||||
Ok(entries) => {
|
||||
let inherited_sockets = entries
|
||||
.filter_map(Result::ok)
|
||||
.filter_map(|entry| {
|
||||
let target = std::fs::read_link(entry.path()).ok()?;
|
||||
target
|
||||
.to_string_lossy()
|
||||
.starts_with("socket:")
|
||||
.then(|| (entry.file_name(), target))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(inherited_sockets, Vec::new(), "privileged socket leaked");
|
||||
}
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
|
||||
eprintln!("skipping descriptor enumeration: sandbox proc is unavailable");
|
||||
}
|
||||
Err(error) => panic!("enumerate inherited descriptors: {error}"),
|
||||
}
|
||||
|
||||
let shared = std::env::var("CODEX_TEST_HANDOFF_SHARED").expect("shared directory");
|
||||
let shared = Path::new(&shared);
|
||||
|
||||
Reference in new issue
Block a user