Repository navigation
xmem: reject null addresses in XMemMapPhysicalPages and XMemMapPhysicalPagesScatter - #7805
MartinIndra02 wants to merge 2 commits into
Conversation
al3xar
left a comment
There was a problem hiding this comment.
Tested de0fb40ab on Windows 11 x64, MSVC 19.44.35230.0 (VS 2022 Build Tools), CMake + Ninja RelWithDebInfo, Windows SDK 10.0.26100.0 (CPU-only, no game files): pass.
- Merges cleanly onto
upstream/main(dde82f27e). - Built
xmem_testwith zero warnings inruntime/shims/xmem.cppandruntime/test/xmem_test.cpp. - PR head (
de0fb40ab):xmem_test.exe->xmem_test: OK (177 checks)(exit 0). - Negative control (
runtime/shims/xmem.cppfromupstream/main, PR test file kept):xmem_test.exe->xmem_test: FAILED (177 checks, 4 failures)(exit 1) on all four new null-address checks. python -I scripts/check_no_game_data.py runtime/shims/xmem.cpp runtime/test/xmem_test.cpp: clean (exit 0).- Diff review: requiring
address != 0inaligned_page_address()cleanly rejectsnullptracross bothXMemMapPhysicalPagesandXMemMapPhysicalPagesScatter(including unmap paths) withERROR_INVALID_PARAMETER.
AI-assisted.
|
Rejecting NULL looks right: the comment at runtime/shims/xmem.cpp:554-556 and docs/xmem_exe_calls.md:74 say every measured call targets an address inside a window XMemVirtualAlloc reserved, and nothing points to a VirtualAlloc(NULL)-style "let the system pick" meaning. A NULL map already failed in find_window (ERROR_INVALID_ADDRESS, :578-582); what changes is that NULL unmap and zero-count calls now set ERROR_INVALID_PARAMETER instead of returning without an error, matching the alignment check (:565, :608). Small requests:
AI-assisted (Claude Code). |
Review follow-up: XMemMapPhysicalPagesScatter checked addresses one entry
at a time inside the mapping loop, so {valid, NULL} mapped entry 0 and then
failed with that mapping left in place. All addresses are now checked up
front, so an invalid address fails the call with nothing changed.
Also rename aligned_page_address to valid_page_address (it now rejects
NULL too) and test map(nullptr, 1, pages), whose error changed from
ERROR_INVALID_ADDRESS to ERROR_INVALID_PARAMETER.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, all three addressed in c179730:
Test run: Environment: Windows 11 x64, MSVC 19.44.35220, NVIDIA GeForce RTX 3080 (driver 621.24 / 32.0.16.2124). AI-assisted (Claude Code). |
|
Tested
Not checked: the retail executable (no game files used). AI-assisted (Claude Code). |
|
Tested Built No game files. AI-assisted (Claude Code). |
Claimed in the coordination issue as: #7694 (comment)
Depends on: none (applies cleanly to
main).What and why
In
runtime/shims/xmem.cpp,aligned_page_address(uintptr_t address)checked(address & (kPhysicalPageSize - 1)) == 0, which returnstruefor0(nullptr):XMemMapPhysicalPages(nullptr, 1, nullptr)andXMemMapPhysicalPages(nullptr, 0, nullptr)entered the unmap path and returnednullptrwithout settingERROR_INVALID_PARAMETER.XMemMapPhysicalPagesScatter([nullptr], 1, nullptr)andXMemMapPhysicalPagesScatter([nullptr], 1, [0])returnedTRUEinstead ofFALSEwithERROR_INVALID_PARAMETER.Changes:
runtime/shims/xmem.cpp: requireaddress != 0inaligned_page_address().runtime/test/xmem_test.cpp: add four regression checks covering all four null-address cases above.Tested
Windows 11 x64, MSVC 19.44.35220 (
RelWithDebInfo, Windows SDK 10.0.26100.0), CPU-only test, no game files:xmem_test.exefailed on all 4 new checks (FAILED (177 checks, 4 failures)).xmem_test.exepassed (xmem_test: OK (177 checks), exit 0).python -I scripts/check_no_game_data.py runtime/shims/xmem.cpp runtime/test/xmem_test.cppandgit diff --check: clean.AI-assisted: yes.
Checklist
CONTRIBUTING.md).