native_menu: Constrain uxtheme loading to System32 - #2974
Merged
Conversation
lurenjia534
marked this pull request as ready for review
September 5, 2026 19:26
Member
|
Thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Opening a native menu on Windows initializes optional dark-mode APIs by loading
uxtheme.dll. The previous implementation passed only the DLL name toLoadLibraryW, allowing the normal DLL search order to consider a file besidethe application executable before the System32 copy. Under the required loader
conditions, a locally planted DLL could execute code from
DllMainwhen a useropened a native menu or input context menu.
This change uses
LoadLibraryExWwithLOAD_LIBRARY_SEARCH_SYSTEM32, restrictingthe lookup to the operating-system copy. Ordinal resolution, module caching, and
the existing fallback when the optional APIs are unavailable remain unchanged.
Before and after
LoadLibraryW(L"uxtheme.dll")LoadLibraryExW(..., LOAD_LIBRARY_SEARCH_SYSTEM32)DllMainin the application processuxtheme.dllloaded; payload exited with code 77uxtheme.dllloaded; program exited normally with code 42Windows CI passed for this commit. The before/after loader check was performed
under Wine, not native Windows. A native Windows smoke test for light/dark native
menus and input context menus is still pending.
Security impact
This closes the reported application-directory DLL planting path for
uxtheme.dll. Exploitation previously required Windows, a consuming applicationthat uses the native-menu implementation, permission to plant a DLL in an early
search location, and a loader state in which the genuine module was not already
selected.
Suggested severity: medium. Successful exploitation could run native code
with the application's privileges, while the prerequisites are local and
environment-dependent.
Implementation
A short source comment records the security reason for retaining the constrained
search policy.
How to test
uxtheme.dllusing the oldbare-name call.
uxtheme.dllbeside the executable. ItsDllMainshould exitwith a unique code such as 77, and it should export ordinals 133, 135, and
136.
application-directory DLL loads and the process exits with code 77.
LoadLibraryExWcall and leave thesame planted DLL in place.
context menu with the right mouse button. Confirm the menus render and their
actions still dispatch normally.
Validation performed
cargo fmt --all -- --checkgit diff --checkx86_64-pc-windows-msvcagainst the repository'swindows 0.58.0API in an isolated check cratebefore loaded the application-directory DLL and exited 77; after loaded
the System32 DLL and exited 42
cargo testonwindows-latestThe repository's accessibility-driven UI procedure is macOS-specific and cannot
exercise this
cfg(target_os = "windows")load path. This change does not alterthe intended menu interaction or appearance; the pending native Windows smoke
test covers the affected platform behavior.
The full workspace cross-check could not complete on the Linux host because the
gpui-preWindows resource build expects the native MSVC/Windows resourceenvironment. It failed in that dependency's build script before checking this
crate; the isolated Windows-target API check passed.
Breaking changes
None.
Checklist
CONTRIBUTING.mdand followed the existing Windows code style.