Skip to content

sched::clone is unsound and should be unsafe to call #1975

@djkoloski

Description

@djkoloski

Reproduced on Debian 5.19.11:

use nix::sched::{clone, CloneFlags};

fn main() {
    let mut bytes = [0u8; 1024];
    let cb = Box::new(|| 0isize) as Box<dyn FnMut() -> isize>;
    let _ = clone(cb, &mut bytes[1024..], CloneFlags::CLONE_VM, None);
    for byte in bytes {
        assert_eq!(byte, 0);
    }
}

Output:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `48`,
 right: `0`', src/main.rs:8:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
*** stack smashing detected ***: terminated
Segmentation fault

This function should be unsafe to call. Related: #360

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions