Skip to content

clone() is broken and unsafe with CLONE_VM flag #360

Open
@arcnmx

Description

@arcnmx

clone() has a few issues when used with CLONE_VM, unless it is used together with CLONE_VFORK.

  1. it takes a Box<FnMut> by value, which will be moved, dropped, and destroyed when the function returns back to the caller.
    • essentially means it will unconditionally segfault when passed CLONE_VM
  2. Even if it did work, the mutable borrow of the stack will end once the clone() call returns, even if the cloned process is still running, meaning you can modify the child process' stack as it runs.
  3. There's no way to provide the thread/TLS/etc. parameters for the thread-related flags.

I was actually going to suggest that its prototype be changed to an unboxed FnOnce, since the caller's stack will never fall out from under you unless CLONE_VM is used... but I think it also needs to disallow the CLONE_VM flag entirely (unless CLONE_VM | CLONE_VFORK). Perhaps offer a second unsafe version for that use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions