Skip to content

Enable strict HANDLE checking for all Windows Rust programs #56055

Open
@cpeterso

Description

@cpeterso

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsA-securityArea: Security (example: address space layout randomization).C-enhancementCategory: An issue proposing an enhancement or a PR with one.O-windowsOperating system: WindowsT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions