fix(linux): enter the guest entry on a main stack at the console's address #7532
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7532"
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 hugodearaujo on 2026-10-18T12:38:25Z.
What
On Linux the relinked executable entered the title's entry point on the host process stack, near the top of the address space (
0x7ffc...). On the console a process's main thread stack sits inside the user area: a payload on a PS5 (FW 13.60) reports its main thread stack at0x7eedfc000-0x7eeffc000throughpthread_attr_get_np, right above a worker thread's stack at0x7eede8000-0x7eedf8000.When the executable loads
libkernel.prx, its Linux entry stub now callsEnterGuestMainStack_nid_no_patch(libkernel) through aGLOB_DATslot, with the initial stack pointer and the entry point.0x7eeffc000, moved by the arena's offset in ASan builds). Below it is a 16 KiB guard. Its size is the host'sRLIMIT_STACK(8 MiB when unlimited, at most 1 GiB).sceKernelIsStackand the main thread's attributes report that range.libkernel.prxkeeps the stub as it was.#3965 does the same on Windows, with a helper in libc that is built only there.
Title
Assassin's Creed Mirage (PPSA13960, 01.007.000) first stops on
mainat a kevent read event, which #6343 implements. With #6343 applied, it stops with SIGSEGV on the main thread 6 s after start, with nothing in the log.pointer >> 28(eboot0x570b9c1-0x570b9ec).0x7fffffff42c8gives index0x7ffff, so the lookup reads past the table and dereferences what it finds there (0x8232f00).0x7eeffc000, which gives index0x7e.With this PR and #6343 it passes that point and goes through its start-up screens (photosensitivity warning, Ubisoft logo, intro video, disclaimer, autosave notice; screenshots from two runs) to the next unimplemented path:
Tested
mainf91137142emerged in (67658c0cbd): only the debt file conflicted, wheremainadded an entry next to this PR's; both are kept. The same test set passes 93 of 93.maina5939f10a8merged in (003002a852):EntryStubBuilder.cppconflicted with #12554, which checks the entry call's rel32 throughSignedDistanceso an entry point more than 2^63 away is rejected instead of wrapping. The resolution keeps this PR's stub (thelea/indirect call through the helper slot when there is one) and runs its sharedappendRel32throughSignedDistance, so both rel32 fields get #12554's check; #12554's new test passesstd::nulloptfor the slot. The same test set as below passes 93 of 93.mainbb04a4f1eamerged in (7348d46be0):core/libs/prx/libkernel/CMakeLists.txtconflicted with #12126, which registers the macOS-onlyguest_main_stack_movetest next to this PR's Linux-onlyguest_main_stack; both registrations are kept. With the same test set as below (ctest -j8 --output-on-failure),mainbb04a4f1eapasses 91 of 91 and this head 93 of 93, the two extra tests beingguest_main_stackandlinux_main_stack_entry.main74acfad65bmerged in (0c55cfcc6a), without conflicts: the overlaps with #7417's trace-import symbol, relocation and prologue inLinuxElfPatcher::Patchand with the entries #8061, #9059 and #9461 indocs/dev/debt/libkernel.mdwere already resolved in the earlier merge (both undefined symbols and bothGLOB_DATrelocations are kept, the trace import's first, and the trace prologue falls through to this entry stub). The PR's own diff is unchanged.PS5 (FW 13.60): a payload prints the address of a local in
main, itspthread_attr_get_npstack range, a worker thread's range, and amallocand anmmapaddress:Linux (Arch, kernel 7.2.11, GCC 16.2.1, Release), on
main74acfad65band on this head,ctest -j8 --output-on-failureofguest_main_stack,linux_main_stack_entry,entry_stub,public_headersand its 64 compile batches,guest_kernel_is_stack,guest_kernel_stack_protect,guest_pthread_attr,guest_pthread_attr_stack,guest_pthread_stack,guest_pthread_start,guest_module_argsand thelinux_*relinker tests (linux_trace_importsamong them):mainpasses 90 of 90 and this head 92 of 92, the two more being the new tests.guest_main_stackenters a test entry through the helper and checks the argument; thatsceKernelIsStackreports a range ending at0x7eeffc000that holds the entry's locals; the guard page below it; that a guest thread created there gets a separate stack; and that an entry over an existing guest mapping is refused and leaves the mapping as it was. WithHostStackLimitsas onmainit fails atGuestMainStack.cpp:67, the check that the reported range ends at0x7eeffc000.linux_main_stack_entryrelinks an executable that loadslibkernel.prxand one that does not, and checks the stub and the imports of both. On Linux x86-64 it also runs the first with a testlibkernel.prxwhose helper calls the entry point; the entry exits with itsargcplus 41. With thelibkernel.prxcheck forced off, the first executable gets noDT_RELAentry for the helper's slot and the test fails (KeyError: 7inhelper_slots).entry_stubchecks both stubs.Full CTest with
-j8,ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1on the same machine (AMD Radeon RX 9070 XT, RADV GFX1201, Mesa 26.2.5):main74acfad65bpasses 2396 of 2431 tests and this head 2398 of 2433. On both, the same 34 tests are skipped andagc_driver_tessellationsegfaults (#5444).Reported by milescoviello on this PR (Linux, RTX 4070 Ti,
main750cf6cf48with #12436): ProsperoCraft (PPSA99874 01.000.117), a Java launcher whose HotSpot runtimemprotects guard pages at the bottom of each thread's stack, aborts at start-up on the primordial thread (Native memory allocation (mprotect) failed to protect 49152 bytes), whose stack is the host process's. With this PR (head0c55cfcc6a) the primordial thread gets past it, and with #9684 as well, which does the same for the threads the title creates, it runs the full 120 s.Earlier heads, not repeated on this base:
main0d078f75d, each title relinked twice from the same ELF with the same options, with this PR's relinker (for A built with thelibkernel.prxcheck forced off, so the stub ismain's) and this PR's runtime libraries. Assassin's Creed Mirage, with #6343'sKqueue.cppchange: A stops with SIGSEGV 6 s after start, as onmain; B reaches the cube texture error above 120 s after start. Hades (PPSA03355, 01.003.000), CONTROL Resonant (PPSA34547, 01.300.300), Alan Wake 2 (PPSA02572, 01.200.007) and ASTRO BOT (PPSA21567, 01.018.000) reach the same screens in A and B.main137a8fab89merged in (deec037e97), Assassin's Creed Mirage, 20 s runs: onmain, 7 of 22 runs stop with SIGSEGV 3 s after start at eboot0x570b9ec, and 12 of 12 with this PR get past start-up.BUILD_TESTING=ON, onmain0d078f75d: of 1479 tests, 924 pass, 554 are skipped (the VM has no GPU) andguest_positioned_closefails, as it does intermittently onmainthere (5 of 30 runs). Windows does not use this stub.tools/check_conventions.py --base origin/mainpasses andgit diff --checkis clean. Of the overlaps the earlier description discussed, #7417 and #6443 are merged and part of this base; #3965's head 8029f87e58 still merges with this branch without conflicts, and #7594 rebases after this one, as agreed on #7594.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 oneandonlydean on 2026-10-18T18:23:13Z.
Thanks, the design looks right, and the stub, the 16-byte alignment and the bounds query all check out. One small safety change before merge:
EnterGuestMainStackmaps the stack withDoMapAnon(&mapping, bytes, 3, GUEST_MAP_FIXED)andexclusive = false, soReplaceFixedOverlapsilently replaces anything already registered in[top - bytes, top). With a largeRLIMIT_STACK(up to 1 GiB) that range reaches well below the console stack. Nothing should be there at entry, but a collision would be clobbered rather than reported. Could it passexclusive = true, so an overlap fails with ENOMEM and a named error?On order: as discussed on #7594, this lands first and #7594 rebases with its MXCSR set before
call [rip+slot].Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-18T18:29:30Z.
I reproduced Dean's collision concern and tested the requested exclusive call locally on exact head
51e5eae15b432788ec554811a80c60ad74337e97. Ubuntu 24.04, kernel7.0.0-38-generic, GCC 13.3, Release.With soft
RLIMIT_STACK=1 MiB, an external probe registers a 16 KiB RW anonymous guest mapping throughDoMapAnon(..., exclusive=true), fills every dword with0xa55a1234, then calls the realEnterGuestMainStackhelper:top - 0x10000top - 0x104000top - 0x108000The local production change is only:
Both refused cases report
EnterGuestMainStack: cannot map the guest main stackbefore entry. This fits the mapping path: without exclusivity, the partial overlap reaches fixed-overlap replacement; with it,mutation.Overlapsreturns ENOMEM before any replacement/protection change. The adjacent-page control rules out blanket refusal of nearby registered mappings.Boundary/guard checks, on both the submitted head and the local proposal: an extension of
GuestMainStack.cppchanges the soft limit after process startup and verifies these reported usable spans:All 14 processes pass. Every reported upper bound is
0x7eeffc000; each run also forks a child with core dumps disabled/default SIGSEGV handling, and an actual read one byte below usable stack is terminated by SIGSEGV. The parent creates/joins a guest worker and keeps the original separate-stack assertions.guest_main_stack,linux_main_stack_entryandentry_stubpass (3/3) with the proposal. Separately, restoring only the originalHostStackLimitshost-query behavior makes the stock test fail its upper-bound assertion at line 68. Restoring the exact PR source and rebuilding returns the three tests to passing.I restored the submitted source; the worktree is clean. The exclusive call above is a tested local proposal, not a pushed change. Generated-input/runtime-helper checks only: no Mirage/title, Windows, ASan-offset or full-suite result.
Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-19T15:52:58Z.
@oneandonlydean Sorry for the slow reply, I missed this comment. Done in
cdfddff83, on top of the existing head:EnterGuestMainStackmaps the stack withDoMapAnon(&mapping, bytes, 3, GUEST_MAP_FIXED, PS5_PAGE_SIZE, true), so an overlap returns ENOMEM before anything is replaced, and entry stops withEnterGuestMainStack: the guest main stack [low, top) overlaps a guest mapping. Any other mapping failure keeps the old message.guest_main_stackhas a case for it: it maps 16 KiB of flexible memory attop - 0x10000, fills it with a pattern, and checks that entry is refused with that message, that the page keeps its RW protection and its pattern, and that the normal entry still works once the page is unmapped. With the old non-exclusive call the case fails (entry goes ahead over the page).Linux (Arch, kernel 7.2.11, GCC 16.2.1, Release, RX 9070 XT with RADV, Mesa 26.2.5): full CTest 1439 of 1440, the failure being
agc_driver_tessellation(#5444);guest_main_stack,linux_main_stack_entryandentry_stubpass.@simonbbby Thanks for reproducing it and testing the exclusive call; the new case is your in-stack sentinel row.