Uh oh!
There was an error while loading. Please reload this page.
Windows executables: only load imported DLLs from System32 - #89311
Conversation
ghost
commented
Jul 21, 2023
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov Issue DetailsBy 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, like #87495 recently fixed. This covers the main CoreCLR product DLLs and EXEs:
QuestionsIs there a better way to apply this flag in the CMake files? Initially I tried adding this to all executables by defining the flag in 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.
|
vitek-karas
commented
Jul 21, 2023
@elinor-fung as our inhouse DLL loading expert :-) |
elinor-fung
commented
Aug 14, 2023
For the binaries under src/native/corehost, you could put the option under exe.cmake and lib.cmake, which will be used by product executables/libraries but not tests. Do you recall which tests these were? If it is an isolated set, you could have them explicitly remove the option. We do something like that for IJW tests: runtime/eng/native/ijw/IJW.cmake Line 3 in 2470610
I believe this is because the data files used for PGO optimization need to be collected/applied withbinaries that use identical options. One option would be to do this in two stages:
@jkoritzinsky / @agocke do you know if there's a better way to do this? |
jkoritzinsky
commented
Aug 14, 2023
Generally when we change options in an instrumenting-incompatible way, we just disable PGO optimization as part of the change until new data has been generated and flows back into the runtime. Your idea actually sounds nicer than our usual approach. I think we should at least wait until after the snap (so wait until tomorrow) before taking a PGO-incompatible change just to simplify code flow. |
elinor-fung
commented
Aug 15, 2023
Agreed. |
AustinWise
commented
Aug 19, 2023
Thanks for the pointer to the IJW file. I will try to do something like that for tests that break when this linker flag is applied globally. I'll un-draft this PR once it get everything building again. |
70dd9da to
547fdc6Compare547fdc6 to
355b455CompareAustinWise
commented
Aug 20, 2023
It looks like it was just the IJW tests in |
elinor-fung
commented
Aug 21, 2023
elinor-fung
commented
Aug 21, 2023
This looks good to me. I just want to make sure we are in a good position to get updated PGO data and re-enable PGO once this goes in. @DrewScoggins - we haven't gotten new PGO data in over a month. It looks like the internal dotnet-optimization builds have been failing or timing out. Do you know if this is a known issue or something that still needs to be investigated? |
DrewScoggins
commented
Aug 21, 2023
It is currently being investigated. The current issue I am working through is related a dependency of the repo using an insecure version of a dependency. I will keep things updated as we work through the issues. |
DrewScoggins
commented
Aug 22, 2023
The scenario issue is fixed, but now we are seeing an internal runtime error when doing collection. I have created the issue below to track it. |
elinor-fung
commented
Aug 29, 2023
Thanks @DrewScoggins. I see dotnet-optimization is back up and we are taking updates (#91171) again - yay! |
elinor-fung
commented
Aug 29, 2023
Thanks, @AustinWise! Merging this. |
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, like #87495 recently fixed.
This covers the main CoreCLR product DLLs and EXEs:
Questions
Is there a better way to apply this flag in the CMake files? Initially I tried adding this to all executables by defining the flag ineng/native/, but some tests broke because they rely on loading DLLs from places other than System32.EDIT: I moved the setting to
eng/native/configurecompiler.cmakeand disabled the linker flag for IJW tests.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.EDIT: We can leave the application of PGO commented out until updated PGO files are available.