libSceNpCommon: terminating a callout context from its own callback crashes the host after teardown returns #11567
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 lgqdaxia on 2026-10-26T20:31:36Z.
What happens
In a source-linked Windows test, a
libSceNpCommoncallout handler invokessceNpCalloutTermCtxon its own context. The function returns after its self-join reportsEDEADLK, and it destroys the context's condition and mutex. If the caller then releases the context mapping, the handler returns and the same worker unconditionally reads the now-unmapped mutex field, terminating the AnyPS5 host process with access violation0xC0000005.The public SDK contract for terminating a callout context from its own handler is unknown. This report does not claim that the console permits that sequence. The behavior demonstrated here is that AnyPS5 completes and returns from teardown while its worker still uses the caller-owned context.
Title, test or build step
An opt-in mode added to the existing
guest_np_common_runtime_testssource-linked fixture. The exact test-only patch is included below. No retail title or console module was used.AnyPS5 commit
Built and tested at
e0b13f2990f31a949a6da21d81a7789ebdfeaa26, with no production-source changes.I also checked current
mainate61a7c7e2433dfccab7917a68065882deee96aa5. The relevant production files are byte-for-byte identical between the tested commit and currentmain:libSceNpCommon/Runtime.cpp,Export.cpp,include/Api.hpp, and libkernel'sPthread/src/Thread.cppandMutex.cpp. I did not rerun the executable against the newer commit.System
Windows 11 Pro x64, Windows NT
10.0.26200.0, Intel Core i7-12700H, CMake Release, Ninja, MinGW-w64 GCC 15.2.0,BUILD_TESTING=ON. GPU/driver: not involved in this CPU/thread-lifecycle test.Steps to reproduce
core/libs/tests/GuestNpCommonRuntime.cpp.BUILD_TESTING=ONusing the normal supported Windows toolchain.guest_np_common_runtime_tests.core/libs/libs/unpatcheddirectory first onPATH.APS5_NP_CALLOUT_SELF_TERM_UAF=control; it should complete normally.APS5_NP_CALLOUT_SELF_TERM_UAF=positive; on the tested production code it prints that self-termination returned and unmapping succeeded, then terminates with0xC0000005.Test-only patch
Example PowerShell commands for an already configured build tree:
Log
The positive process reaches both post-teardown messages before the worker faults:
The external-termination control completes:
Twenty fresh processes produced:
What was checked
sceNpCalloutInitCtx; the callout is scheduled throughsceNpCalloutStartOnCtxwith zero delay.sceNpCalloutTermCtxand releases the same kind of context mapping.guest_np_common_runtimeCTest still passes (1/1).libSceNpCommon.prx, andlibkernel.prxhashes were recorded before and after the 20-process matrix and did not change. The executable directory contained no competing copies of those PRX files.The code path is visible in current
main:CalloutThreadinvokes the handler without the context mutex and then unconditionally lockscontext->mutexafter the handler returns.sceNpCalloutTermCtxignores the join result and completes teardown. The underlying self-join path returnsEDEADLK.Related work, but not duplicates: #9063 introduced the NpCommon callout worker; #4052 / #4063 cover libkernel's self-join return value; and #5944 fixes an analogous AvPlayer close-from-callback lifecycle, in a different module and implementation.
AI-assisted: Codex