Skip to content

New Lint: drop_non_send #7703

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

Closed
Qwaz opened this issue Sep 22, 2021 · 0 comments · Fixed by #7709
Closed

New Lint: drop_non_send #7703

Qwaz opened this issue Sep 22, 2021 · 0 comments · Fixed by #7709
Assignees
Labels
A-lint Area: New lints

Comments

@Qwaz
Copy link
Contributor

Qwaz commented Sep 22, 2021

What it does

Warns about a field in a Send struct that is neither Send nor Copy.

Sending the struct to another thread and drops it there will also drop the field in the new thread. This effectively changes the ownership of the field type and breaks the non-Send requirement which is unsound.

This is one of the most common unsound bug patterns we observed during Rudra project.

Bug examples:

Categories (optional)

  • Kind: Nursery (for now)

Known Problems

  • Raw pointers in data structures could cause false positives, such as Vec<*const T>. They can be partially mitigated by checking if any pointer type is used as a generic type parameter.
  • A field that implements Copy but not Send can actually be a problem, e.g., RUSTSEC-2020-0136. However, they would be better handled in a separate lint because this lint focuses on unsoundness in drop and removing the Copy bound would cause too much false positives.

Example

// Example from google/async-coap, RUSTSEC-2020-0124
#[derive(Debug, Clone)]
pub struct ArcGuard<RC, T> {
    inner: T,
    head: Arc<RC>, // This drops Arc<RC> (and in turn RC) which might not be `Send`
}

unsafe impl<RC, T: Send> Send for ArcGuard<RC, T> {} // There is no `RC: Send` bound here

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant