Skip to content

std::process::Command doesn't follow Unix signal safety in forked child #64718

Open
@ericyoungblut

Description

@ericyoungblut

Update (2022-12-12): The issue description is outdated, but some problems remain.

These lines from spawn can cause a deadlock. It's wrong to assume that you can lock in the parent and the unlock in the child. Read man 2 fork and man 7 signal-safety on Linux.

    // Whatever happens after the fork is almost for sure going to touch or
    // look at the environment in one way or another (PATH in `execvp` or
    // accessing the `environ` pointer ourselves). Make sure no other thread
    // is accessing the environment when we do the fork itself.
    //
    // Note that as soon as we're done with the fork there's no need to hold
    // a lock any more because the parent won't do anything and the child is
    // in its own process.
    let result = unsafe {
        let _env_lock = sys::os::env_lock();
        cvt(libc::fork())?
    };

Qumulo has a custom thread library which exposes this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-processArea: `std::process` and `std::env`C-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-unixOperating system: Unix-likeP-mediumMedium priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions