mirror of
https://github.com/openai/codex.git
synced 2026-11-20 23:08:21 +00:00
Drop capabilities from Linux sandbox processes (#39103)
## What changed - Pass `--cap-drop ALL` in both bubblewrap launch modes. - Verify in the inner sandbox stage that the effective and permitted Linux capability sets are empty, and abort before executing the command otherwise. - Cover the generated bubblewrap arguments, capability state of sandboxed commands, and rejection of a capability-bearing inner-stage process. GitOrigin-RevId: 9dbd651d306d92327e36c9b3f308619db7d80a67
This commit is contained in:
1 parent
2eee483e49
commit
632420e67a
4 files changed
+107
No files matched your search
@@ -40,6 +40,7 @@ static PENDING_FORWARDED_SIGNAL: AtomicI32 = AtomicI32::new(0);
|
||||
|
||||
const FORWARDED_SIGNALS: &[libc::c_int] =
|
||||
&[libc::SIGHUP, libc::SIGINT, libc::SIGQUIT, libc::SIGTERM];
|
||||
const LINUX_CAPABILITY_VERSION_3: u32 = 0x2008_0522;
|
||||
const SYNTHETIC_MOUNT_MARKER_SYNTHETIC: &[u8] = b"synthetic\n";
|
||||
const SYNTHETIC_MOUNT_MARKER_EXISTING: &[u8] = b"existing\n";
|
||||
const PROTECTED_CREATE_MARKER: &[u8] = b"protected-create\n";
|
||||
@@ -180,6 +181,30 @@ pub fn run_main() -> ! {
|
||||
// Inner stage: apply seccomp/no_new_privs after bubblewrap has already
|
||||
// established the filesystem view.
|
||||
if apply_seccomp_then_exec {
|
||||
let mut capability_header = [LINUX_CAPABILITY_VERSION_3, 0];
|
||||
let mut capability_sets = [[0_u32; 3]; 2];
|
||||
// SAFETY: capability ABI version 3 uses a [version, pid] header and
|
||||
// two [effective, permitted, inheritable] capability-set entries.
|
||||
let result = unsafe {
|
||||
libc::syscall(
|
||||
libc::SYS_capget,
|
||||
capability_header.as_mut_ptr(),
|
||||
capability_sets.as_mut_ptr(),
|
||||
)
|
||||
};
|
||||
if result < 0 {
|
||||
panic!(
|
||||
"failed to verify Linux sandbox capabilities: {}",
|
||||
std::io::Error::last_os_error()
|
||||
);
|
||||
}
|
||||
if capability_sets
|
||||
.into_iter()
|
||||
.any(|[effective, permitted, _]| effective != 0 || permitted != 0)
|
||||
{
|
||||
panic!("Linux sandbox retained effective or permitted capabilities");
|
||||
}
|
||||
|
||||
if allow_network_for_proxy {
|
||||
let spec = proxy_route_spec
|
||||
.as_deref()
|
||||
|
||||
Reference in new issue
Block a user