Mark inherited descriptors close-on-exec so none reach the sandbox

This commit is contained in:
2026-11-04 18:12:04 +01:00
parent 14c4f44a1f
commit f9ac595d63
4 changed files with 66 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
use std::io;
use crate::SandboxError;
const FIRST_FD_AFTER_STDIO: libc::c_uint = 3;
pub fn keep_out_of_sandbox() -> Result<(), SandboxError> {
let result = unsafe {
libc::syscall(
libc::SYS_close_range,
FIRST_FD_AFTER_STDIO,
libc::c_uint::MAX,
libc::CLOSE_RANGE_CLOEXEC,
)
};
if result < 0 {
return Err(SandboxError::InheritedFdsCloexec(io::Error::last_os_error()));
}
Ok(())
}