Skip to content

Current use of pin is unsound #286

Closed

Description

@nbdd0121

In rust_miscdev, this would compile:

let mut state = SharedState::try_new()?;
let mut state2 = SharedState::try_new()?;
core::mem::swap(Arc::get_mut(&mut state).unwrap(), Arc::get_mut(&mut state2).unwrap()); 

but this swaps two pinned CondVar, which is unsound. After pinning the CondVar, we shouldn't be able to obtain any Arc<SharedState>, but rather only Pin<Arc<SharedState>>.

Activity

  1. alex commented on May 22, 2021

    @alex
    Member

    The right fix here is:

    a) To pin the Arc immediately here: https://github.com/Rust-for-Linux/linux/blob/rust/samples/rust/rust_miscdev.rs#L42
    b) To change teh return type to Pin<Arc<SharedState>> here: https://github.com/Rust-for-Linux/linux/blob/rust/samples/rust/rust_miscdev.rs#L41
    c) To update anything else to get it to compile :-)

  2. added
    • driversRelated to the example drivers in `drivers/`.
    on May 22, 2021
  3. added
    unsoundThe possibility of UB in safe code.
    on Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomersunsoundThe possibility of UB in safe code.• driversRelated to the example drivers in `drivers/`.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions