Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current use of pin is unsound #286

Closed
nbdd0121 opened this issue May 22, 2021 · 1 comment · Fixed by #289
Closed

Current use of pin is unsound #286

nbdd0121 opened this issue May 22, 2021 · 1 comment · Fixed by #289
Labels
• drivers Related to the example drivers in `drivers/`. good first issue Good for newcomers unsound The possibility of UB in safe code.

Comments

@nbdd0121
Copy link
Member

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>>.

@alex alex added good first issue Good for newcomers prio: high labels May 22, 2021
@alex
Copy link
Member

alex commented May 22, 2021

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 :-)

@ojeda ojeda added the • drivers Related to the example drivers in `drivers/`. label May 22, 2021
@alex alex closed this as completed in #289 May 23, 2021
@ojeda ojeda added the unsound The possibility of UB in safe code. label Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
• drivers Related to the example drivers in `drivers/`. good first issue Good for newcomers unsound The possibility of UB in safe code.
Development

Successfully merging a pull request may close this issue.

3 participants