-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Windows executables: only load imported DLLs from System32 #85227
Conversation
Tagging subscribers to this area: @hoyosjs Issue DetailsBy using the /DEPENDENTLOADFLAG While this would not have prevented this month's CVE (see #84637), it could prevent DLL injection bugs from being introduced in native code. To demonstrate the effectiveness of this approach, this PR is split into 3 commits. The first adds a test for DLL injection. The second reverts the delay loading for
|
Leaving this as draft for now to see if it breaks anything. |
8750c21
to
984ee22
Compare
The docs say that this flag is effective on newer Windows 10 RS1+ only. It does not hurt to add it, but I do not think we can depend on it as long as we support Windows Server 2012: https://github.com/dotnet/core/blob/main/release-notes/8.0/supported-os.md#windows. I would expect the tests to fail on Windows Server 2012. |
I finally got a chance to look at the failures. It appears that some tests (like for IJW) are impacted by this change. I think I will rework this to only target the main product DLLs and EXEs, like
Opps, I did not check the minimum server version of Windows. In that case I will revert the changes to delay loading version.dll and let this be a defense-in-depth change before I mark this ready for review. |
d493c5b
to
6e5ccef
Compare
I removed the test because it was pretty hacky. I think the ideal test would enumerate all loaded modules and make sure this flag is set in non-operating-systems module. I'm not 100% sure on how to write such a test. In the absence of tests, I manually verified that the follow executable have the dependent load flag using
Which I think covers the main product executables. |
6e5ccef
to
8d871ba
Compare
8d871ba
to
bd83309
Compare
I wrote a program to check for files missing this flag: https://github.com/AustinWise/CheckDependentLoadFlags I'm satisfied that I've covered the main product DLLs, so I will open this for review. |
I identified some further revision I'd like to do, so I'm marking this as draft again. Sorry for the churn. |
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
By using the /DEPENDENTLOADFLAG
link.exe
flag, we can tell the Windows loader to only look for referenced DLLs in the System32 directory. This prevents DLL injection.While this would not have prevented this month's CVE (see #84637), it could prevent DLL injection bugs from being introduced in native code.
Questions
Is there a better way to apply this flag in the CMake files? Ideally it would be the default and tests that don't work with it would opt out.
When I added this flag, I got this error message from
LINK.exe
:How can this be worked around? Currently I have commented out applying PGO to make the build pass.