Skip to content

Restrict Windows DLL search path as a precaution against DLL pre-loading attacks #56056

Open
@cpeterso

Description

@cpeterso

Windows' standard DLL search path contains directories that can be vulnerable to DLL pre-loading attacks. An application can use the SetDefaultDllDirectories API to specify a default DLL search path for the process that eliminates the most vulnerable directories and limits the other directories that are searched.

For example, as a precaution, Firefox removes the current directory from the DLL search path and then restricts the DLL search path to the application's installation directory, the Windows system directory, and any paths explicitly added using the AddDllDirectory or SetDllDirectory APIs.

https://searchfox.org/mozilla-central/rev/5117a4c4e29fcf80a627fecf899a62f117368abf/toolkit/mozapps/update/updater/loaddlls.cpp#15-30

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

To help protect against DLL pre-loading attacks, the Rust compiler could emit similar code to restrict its DLL search path for all Windows Rust programs. Changing the DLL search path could cause compatibility problems for Windows Rust programs that assume they can implicitly load DLLs in the current directory without explicitly configuring their DLL search path. The workaround is for those programs to configure their DLL search path using the the AddDllDirectory or SetDllDirectory APIs.

See MSDN for SetDefaultDllDirectories:

https://docs.microsoft.com/en-us/windows/desktop/api/libloaderapi/nf-libloaderapi-setdefaultdlldirectories

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-securityArea: Security (example: address space layout randomization).C-enhancementCategory: An issue proposing an enhancement or a PR with one.O-windowsOperating system: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions