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

WIP: Use ProcessPrng on Windows #415

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

josephlr
Copy link
Member

@josephlr josephlr commented Apr 30, 2024

Use ProcessPrng on Windows 10 and up, and use RtlGenRandom on older legacy Windows versions. Don't use BCryptGenRandom due to stability issues.

Copy link
Contributor

@briansmith briansmith left a comment

Choose a reason for hiding this comment

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

Besides the lines I commented on, I didn't review the rest.

src/windows.rs Outdated Show resolved Hide resolved
src/windows.rs Outdated
let code = unsafe { NonZeroU32::new_unchecked(code) };
return Err(Error::from(code));
}
let dll = unsafe { LoadLibraryA(b"bcryptprimitives.dll\0".as_ptr()) };
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use LoadLibraryEx with LOAD_LIBRARY_SEARCH_SYSTEM32 instead (but see the documentation about that flag and compatibility) or LOAD_WITH_ALTERED_SEARCH_PATH with an absolute path to the System32 folder.

Google Chrome doesn't security bug reports about this issue to be valid, but not everybody agrees with Google Chrome. Regardless, I can tell you from past experience that this will trigger security vulnerability bug reports to every application that uses getrandom, if we don't restrict the search path to System32. These bug reports are difficult for many projects to deal with. It's worth avoiding.

Choose a reason for hiding this comment

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

If it's in \KnownDlls then it doesn't particularly matter because it will indeed prioritize the system directory for those dlls. However bcryptprimitives is a bit more awkward because it's a late addition, iirc the earliest versions of Windows 10 did not have it as a known dll.

src/windows.rs Outdated Show resolved Hide resolved
@josephlr
Copy link
Member Author

josephlr commented May 21, 2024

@briansmith the above are really good point w.r.t. sandboxing. I think that it would be good to have general documentation along the lines of "before starting a sandbox, you should first successfully call getrandom() on a non-empty buffer". That should be good platform-agnostic advice, and will handle things like LoadLibrary and libc::dlsym.

More generally, this won't work inside many sandboxes, including Chromium's.

I think that this won't cause issues in some sandboxes provided that ProcessPRNG is already loaded. IIRC the sandbox only complains on loading a new dll, not upon looking up a symbol from an already loaded DLL. Regardless, having specific documentation will be good here.

@josephlr josephlr force-pushed the windows branch 7 times, most recently from 6825ae5 to 4bfd348 Compare May 21, 2024 10:47
.github/workflows/tests.yml Show resolved Hide resolved
src/windows.rs Outdated Show resolved Hide resolved
src/windows.rs Outdated Show resolved Hide resolved
src/windows.rs Show resolved Hide resolved
src/windows7.rs Outdated Show resolved Hide resolved
@josephlr
Copy link
Member Author

@newpavlov and @briansmith this is now ready for review!

@josephlr josephlr marked this pull request as ready for review May 26, 2024 04:44
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