Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRestrict Windows DLL search path as a precaution against DLL pre-loading attacks #56056
Comments
This comment has been minimized.
This comment has been minimized.
SoniEx2
commented
Nov 19, 2018
|
would this cause issues with e.g. steam overlay? |
csmoe
added
the
O-windows
label
Nov 19, 2018
This comment has been minimized.
This comment has been minimized.
|
I feel that this specific change is out-of-scope for the Rust’s standard library. The standard library consciously avoids dealing with dynamic library loading. Therefore, the only DLLs that will be loaded without bringing in a crate (or calling winapi APIs directly) will be those that were dynamically linked to as part of building. Those libraries will not be affected by To me it seems that the more appropriate location to do this would be in libraries that wrap/implement dynamic library loading or, in case winapi APIs are being called directly, by the caller. |
This comment has been minimized.
This comment has been minimized.
|
@nagisa I disagree. |
This comment has been minimized.
This comment has been minimized.
|
All normal DLL dependencies are loaded and their symbols resolved before Having Rust implicitly call
// SetDefaultDllDirectories is always available on Windows 8 and above. It
// is also available on Windows Vista, Windows Server 2008, and
// Windows 7 when MS KB2533623 has been applied.This doesn't quite sound like always present. |
This comment has been minimized.
This comment has been minimized.
|
Could Rust run |
This comment has been minimized.
This comment has been minimized.
|
The order of C++ static initializers is not well defined, so there's no guarantee that an initializer in one compilation unit will run before an initializer in a different compilation unit. |
This comment has been minimized.
This comment has been minimized.
mirh
commented
Jan 12, 2019
|
SetDefaultDllDirectories is not a security feature. |
cpeterso commentedNov 19, 2018
•
edited
Windows' standard DLL search path contains directories that can be vulnerable to DLL pre-loading attacks. An application can use the
SetDefaultDllDirectoriesAPI 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
AddDllDirectoryorSetDllDirectoryAPIs.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
AddDllDirectoryorSetDllDirectoryAPIs.See MSDN for
SetDefaultDllDirectories:https://docs.microsoft.com/en-us/windows/desktop/api/libloaderapi/nf-libloaderapi-setdefaultdlldirectories