-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Load handler DLL with load dir on the path #63773
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
Load handler DLL with load dir on the path #63773
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue with DLL loading in the ASP.NET Core Module V2 by modifying the library loading behavior to include the DLL's directory in the search path.
- Replaces
LoadLibrary
withLoadLibraryEx
using specific search flags - Ensures the DLL load directory is included in the search path for dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving to unblock an urgent PR; I assume you've tested this running well on arm64.
LOG_INFOF(L"Loading request handler: '%ls'", handlerDllPath.c_str()); | ||
|
||
hRequestHandlerDll = LoadLibrary(handlerDllPath.c_str()); | ||
hRequestHandlerDll = LoadLibraryEx(handlerDllPath.c_str(), nullptr, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will search 4 places -- current dll, app, System32 and any AddDllDirectory/SetDllDirectory. Do we need all those places?
I see in the code of this dll we may SetDllDirectory to the current directory. Is that relevant?
aspnetcore/src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp
Line 297 in bb2d778
LOG_LAST_ERROR_IF(!SetDllDirectory(currentDirectory.c_str())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering whether it's well defined exactly where it should look and that's something more limited than this range. As far as security goes, I guess we trust app directory/dll directory. We do not necessarily trust current directory, in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the only behavioral difference introduced here is that we now search the directory where the handler DLL is as well. The other places (app dir, system32, etc.) are already being searched with the current LoadLibrary
code.
The inprocessapplication.cpp code you linked to is not yet relevant at this point; that comes later.
/backport to release/10.0 |
Started backporting to release/10.0: https://github.com/dotnet/aspnetcore/actions/runs/17958188973 |
Fix #63772
See that issue for context.
This change updates the handler DLL load call from
LoadLibrary
toLoadLibraryEx
with the flagsLOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR
The handler DLL exports
CreateApplication
as a forwarded export to an architecture-specific DLL. The plainLoadLibrary
does not search the handler’s directory when resolving that forwarder. As a result, the loader fails to locate the arch-specific DLL and the scenario breaks (the user gets a 500 error).