sandlock icon indicating copy to clipboard operation
sandlock copied to clipboard

sandbox: confine_child can deadlock after fork in std::env

Open congwang-mk opened this issue 1 month ago • 0 comments

Step 13 of `confine_child` (context.rs) applies `clean_env`, `env` and GPU vars with `std::env::vars_os/remove_var/set_var` in the forked child. These take std's `ENV_LOCK`; if another host thread held it at fork, the child hangs before exec and the caller waits forever.

Repro: 4 threads creating sandboxes with `clean_env` or an env var while calling `std::env::vars()`; hangs within ~200 rounds.

Fix: build envp before fork and `execve` with it. PATH lookup must use the built envp's PATH (glibc `execvpe` uses the caller's environ), and the `execveat` arm needs the same. `fork.rs` (`set_var("CLONE_ID")`) has the same pattern.

congwang-mk avatar Oct 23 '26 04:10 congwang-mk