Skip to content

Commit 5e946d5

Browse files
committed
fix(suidhelper): close_range via raw syscall for aarch64-musl portability
1 parent f5052c5 commit 5e946d5

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

native/suidhelper/src/util/jailer.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,19 @@ impl Jailer<'_> {
298298
/// closing each fd individually — fail closed before handing root to the jailer.
299299
fn close_inherited_fds() {
300300
const FIRST: u32 = 3;
301+
// Invoke `close_range(2)` as a raw syscall rather than through the
302+
// `libc::close_range` wrapper: the `libc` crate does not define that wrapper
303+
// for every target (it is absent on aarch64-musl), but `SYS_close_range` is
304+
// defined on all Linux arches. `syscall` returns 0 on success, -1 on error.
301305
// SAFETY: raw syscall with no memory operands; closing fds has no UB.
302-
let rc = unsafe { nix::libc::close_range(FIRST, u32::MAX, 0) };
306+
let rc = unsafe {
307+
nix::libc::syscall(
308+
nix::libc::SYS_close_range,
309+
FIRST as nix::libc::c_uint,
310+
u32::MAX as nix::libc::c_uint,
311+
0 as nix::libc::c_uint,
312+
)
313+
};
303314
if rc == 0 {
304315
return;
305316
}

0 commit comments

Comments
 (0)