sandlock icon indicating copy to clipboard operation
sandlock copied to clipboard

seccomp: clone3 bypasses the namespace creation ban

Open congwang-mk opened this issue 2 months ago • 0 comments

clone with a namespace flag is refused, clone3 with the same flag is not:

clone(CLONE_NEWUSER):   EPERM
clone3(CLONE_NEWUSER):  allowed

Reproduced with a raw syscall(SYS_clone3, &args, 64) from python under sandlock run -r /usr -r /lib -r /lib64 -r /bin -r /etc. On main.

resource::handle_fork only checks the flags of SYS_clone (args[0]); its comment says clone3's flags "are caught by the BPF arg filter", but they live in struct clone_args in user memory, which BPF cannot read. The BPF arg filter in seccomp_plan.rs covers clone only.

A sandboxed process can therefore create a user namespace and, inside it, the others. Landlock and the seccomp filter still apply there, so this is not an escape by itself, but it opens the kernel attack surface the ban exists to close.

Checking the struct in the handler is not a fix: the handler returns Continue, the kernel re-reads the struct, and a CLONE_VM peer can swap the flags in between.

Proposed fix: return ENOSYS for clone3 from the BPF filter. glibc and Rust's std fall back to clone, whose flags BPF can check; musl and Go do not use clone3.

congwang-mk avatar Sep 20 '26 02:09 congwang-mk