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

Unsound use of unsafe in src/utils/parallelism.rs #1491

Open
albertsgarde opened this issue Apr 12, 2024 · 1 comment · May be fixed by #1532
Open

Unsound use of unsafe in src/utils/parallelism.rs #1491

albertsgarde opened this issue Apr 12, 2024 · 1 comment · May be fixed by #1532
Labels

Comments

@albertsgarde
Copy link

albertsgarde commented Apr 12, 2024

The static variable USED_PARALLELISM is accessed in has_parallelism_been_used, and modified in MaybeParallelIterator::into_maybe_par_iter and MaybeParallelBridge::maybe_par_bridge.
All these cases are unsafe because if they are done at the same time from different threads, they could cause a data race which has undefined behaviour.
The issue is that all of these are safe functions, and no checks are made to ensure that the unsafe operations are in fact safe.
This means that it would be possible to cause UB in safe rust by calling these functions from separate threads.
There maybe reasons to believe that this is unlikely or impossible given the rest of the library (I don't know the code base well enough to say), but that does not change the fact that this is unsound.

The easiest way to fix this would be to place the variable in a Mutex. I propose an implementation of this in #1492 .

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant