fix(relinker): validate guest module executable segments against image bounds #5681
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5681"
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 fogydes on 2026-10-14T06:12:50Z.
What
Input Triggers
Tested
Checklist
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T11:57:23Z.
Review: CHANGES_REQUESTED
Thanks for the PR. Points to address:
executable_segmentsalready existed and does not exercise an out-of-bounds segment, an address-range overflow or a relocation table whose size is not a multiple of 24. Please add a C++ test (seecore/relinker/relinker/tests/ElfFixture.hpp, registered incore/relinker/CMakeLists.txt) that builds such a guest module and fails onmainand passes with the change, one case per check.ptrdiff_tcasting for byte vector iterators", but the diff has no such change. Please make the description match the diff.GuestModuleBuilder.cpp:322-330) and relocation table size (GuestModuleBuilder.cpp:380). Split the second into its own PR, or explain why they are one change.Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-15T12:07:44Z.
Thanks for the review @adriadam10! I have addressed all points:
core/relinker/relinker/tests/GuestExecutableSegmentBoundsTests.cppusingElfFixture.hppand registeredguest_executable_segment_bounds_testsincore/relinker/CMakeLists.txt. It verifies:"Guest executable segment exceeds image".2^{64}-1reject with"Guest executable segment range exceeds address space".table->size() % 24 != 0) from this PR to isolate it strictly to guest executable segment bounds.ptrdiff_treference to match the diff.Rebased cleanly onto latest
main(b3f9f89e6).Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T12:10:10Z.
Review: CHANGES_REQUESTED
Thanks for the update. Two problems:
guest_executable_segment_boundsfails on this head (run on the PR merged onto main). Case 1 (offset/size past the end of the file) is rejected withELF range exceeds file: offset=0x4000, size=0x9000, fileSize=0x8000, not withGuest executable segment exceeds image.GuestModuleBuilder.cpp:326-334cannot be reached:GuestImageReader::Readalready runsrange(header.Offset, header.FileSize)for every header (GuestImageReader.cpp:118) and rejectsMemorySize > max - MappedAddressas "Invalid load segment" (GuestImageReader.cpp:120) beforeBuildsees the image. The test's third case would hit that second error too.Unless you can build a module that passes
GuestImageReader::Readand still violates one of the new conditions (and show the test failing onmain), the validation is already there and this PR has nothing to add. If you find such a case, adjust the test to expect it and make the Tested section match what CI actually ran.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:22:18Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-15T12:48:40Z.
Thanks for the detailed review @adriadam10. You're completely right:
GuestImageReader::Readalready validatesrange(header.Offset, header.FileSize)and checksMemorySize > max - MappedAddressfor all headers beforeGuestModuleBuilder::Buildreceives the image, making the checks inGuestModuleBuilderredundant. Closing this PR accordingly.Pull request closed