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

RacyCell<T>: Data race allowed on T #390

Merged
merged 1 commit into from
Aug 4, 2023
Merged

Conversation

kuzeyardabulut
Copy link
Contributor

Hi,
I found a memory-safety/soundness issue in this crate while scanning Rust code for potential vulnerabilities. This PR contains a fix for the issue.

Issue Description

RacyCell<T> unconditionally implements Sync. This allows users to create data races on T: !Sync. Such data races can lead to undefined behavior.

unsafe impl<T> Sync for RacyCell<T> {}

@bjorn3
Copy link
Contributor

bjorn3 commented Aug 3, 2023

RacyCell doesn't expose any safe method that allows access to the internal value through a shared reference, so the internal value doesn't need to be Sync for RacyCell to be sync.

The fact that this PR doesn't break CI suggests that RacyCell isn't needed however. I think all uses can be replaced with the unstable core::cell::SyncOnceCell which does have the T: Sync bound on it's Sync impl.

@kuzeyardabulut
Copy link
Contributor Author

I agree with what you said. This may not cause a direct data race. But making the above changes can be useful.

@phil-opp
Copy link
Member

phil-opp commented Aug 4, 2023

The fact that this PR doesn't break CI suggests that RacyCell isn't needed however. I think all uses can be replaced with the unstable core::cell::SyncOnceCell which does have the T: Sync bound on it's Sync impl.

I guess you mean the SyncUnsafeCell? Yes, we could use that as well, but I would prefer to wait until it's stabilized.

Copy link
Member

@phil-opp phil-opp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me, thanks for submitting!

@phil-opp phil-opp merged commit ef1d4a9 into rust-osdev:main Aug 4, 2023
8 checks passed
@phil-opp phil-opp mentioned this pull request Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants