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

Enable strict HANDLE checking for all Windows Rust programs #56055

Open
cpeterso opened this Issue Nov 19, 2018 · 0 comments

Comments

Projects
None yet
3 participants
@cpeterso
Copy link
Contributor

cpeterso commented Nov 19, 2018

To help protect against bugs in unsafe or third-party code, the Rust compiler should emit code to enable strict HANDLE checking for all Windows Rust programs. The process will receive a fatal error if it manipulates a HANDLE that is not valid, such as using an uninitialized HANDLE or calling CloseHandle twice.

See MSDN for SetProcessMitigationPolicy and PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY:

https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-setprocessmitigationpolicy

Strict HANDLE checking might cause compatibility problems for Rust programs that depends on third-party libraries that misuse HANDLEs. As a general rule, strict HANDLE checking cannot be turned off once it is turned on, so there would be no backdoor to allow sloppy third-party code to run without raising a HANDLE exception. If that compatibility constraint is too severe, strict HANDLE checking could be limited to debug builds or disabled with an opt-out compiler flag.

Here is how Firefox enables strict HANDLE checking for its sandbox processes:

https://searchfox.org/mozilla-central/rev/5117a4c4e29fcf80a627fecf899a62f117368abf/security/sandbox/chromium/sandbox/win/src/process_mitigations.cc#120-131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.