fix(agc): read unaligned guest words through a one-byte-aligned type in the ASan copy #10973
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10973"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T11:44:14Z.
What
In an
ANYPS5_ENABLE_ASANbuild,GuestMemory::CopyGuestBytes(core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp) reads the guest source eight bytes at a time through aconst volatile std::uint64_t*. The source has no alignment guarantee, so those loads are undefined behavior. UBSan reports them fromagc_driver_pm4,agc_driver_graphicsandagc_driver_graphics_maps_fallback:The words are now read through a local alias of
std::uint64_twith[[gnu::aligned(1), gnu::may_alias]]. GCC still emits a single unaligned 8-byte load per word (movq), and builds withoutANYPS5_ENABLE_ASAN, which usememcpy, are unchanged.Two commits: fix, test.
agc_copy_guest_bytescopies 0 to 80 bytes from each of the eight source offsets and checks the copied bytes and the bytes on both sides of the destination.agc_driver_graphicsandagc_driver_graphics_maps_fallbackget past this load with the fix but then stop on a different report,Graphics/src/DepthSurface.cpp:730:76: runtime error: reference binding to null pointer of type 'struct TextureDetiler', which this pull request does not change.Tested
Linux x86-64 (Debian 12, GCC 12),
-DANYPS5_ENABLE_ASAN=ONwith-fsanitize=undefinedandUBSAN_OPTIONS=halt_on_error=1:agc_copy_guest_bytesfails on currentmainwith the misaligned load and passes with the fix, andagc_driver_pm4passes with the fix after failing the same way.python3 tools/check_conventions.py --base upstream/main --head HEADandgit diff --check upstream/mainpass. Following AGENTS.md,agc_driver_pm4,agc_driver_graphicsandagc_driver_graphics_maps_fallbackwere also run onmainand on this change withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(ctest -R <pattern> -V, Khronos validation layer 1.3.239 installed, UBSan reporting without halting): all three pass in both runs, the misaligned-load reports go from 3 onmainto 0, and no VUID is reported in either run. In this build these tests do not load the Vulkan loader (VK_LOADER_DEBUG=allprints nothing), so the validation layer had nothing to check; the change only affects CPU reads of guest memory. The new test was not built withoutANYPS5_ENABLE_ASAN, on Windows or macOS, and no hardware was run.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T12:04:06Z.
Review: COMMENTED
Reviewed exact head
c5bf7899b491e49dc0d73d08423064647aae5bbc. The ASan-only copy now uses a one-byte-aligned, may-alias word type for the 8-byte source loads, avoiding the reported misaligneduint64_taccess while preserving the existing non-ASanmemcpypath. The new test covers all source offsets modulo 8 and lengths through 80 bytes, checks both destination canaries, and is registered in the test list. I verified the diff and local convention checks against currentupstream/main; both passed. The hosted eligibility, intake, conventions, labels, and report checks pass; hosted build jobs were skipped. I have not independently run the UBSan reproducer or AGC tests, so the failure-on-main/pass-on-change results are based on the author’s report. The author also documents the later, separateTextureDetilernull-reference report in two graphics tests.