Skip to content

Conversation

adityamandaleeka
Copy link
Member

@adityamandaleeka adityamandaleeka commented Sep 23, 2025

Fix #63772

See that issue for context.

This change updates the handler DLL load call from LoadLibrary to LoadLibraryEx with the flags
LOAD_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 plain LoadLibrary 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).

@Copilot Copilot AI review requested due to automatic review settings September 23, 2025 02:04
Copy link
Contributor

@Copilot Copilot AI left a 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 with LoadLibraryEx using specific search flags
  • Ensures the DLL load directory is included in the search path for dependencies

Copy link
Member

@DeagleGross DeagleGross left a 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);
Copy link
Member

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?

LOG_LAST_ERROR_IF(!SetDllDirectory(currentDirectory.c_str()));

Copy link
Member

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.

Copy link
Member Author

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.

@danmoseley danmoseley added the Servicing-consider Shiproom approval is required for the issue label Sep 23, 2025
@adityamandaleeka
Copy link
Member Author

/backport to release/10.0

Copy link
Contributor

Started backporting to release/10.0: https://github.com/dotnet/aspnetcore/actions/runs/17958188973

@adityamandaleeka adityamandaleeka merged commit a20b616 into dotnet:main Sep 23, 2025
31 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 11.0-preview1 milestone Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions Servicing-consider Shiproom approval is required for the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Out-of-process hosting is broken on arm64
3 participants