fix(libkernel): check the module load and unload arguments as firmware 13.42 does #15556
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15556"
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 BunnyFl on 2026-11-03T18:48:24Z.
What
sceKernelLoadStartModuleandsceKernelStopUnloadModuleignored theirflagsandoptarguments, andsceKernelStopUnloadModuletreated handle 0 like any unknown handle. Firmware 13.42 refuses these with0x80020016(EINVAL) before it does anything else, and this change does the same:sceKernelLoadStartModule: nonzeroflagsor a non-nulloptreturns0x80020016, andresis left alone.sceKernelStopUnloadModule: nonzeroflags, a non-nulloptor handle 0 returns0x80020016, andresis left alone.sceKernelLoadStartModuleForSysmoduleforwardsflagsas 0. The firmware export adds0x10000toflagsand jumps past the public entry'sflagscheck, so a sysmodule load with flags still loads. A non-nulloptis refused on both paths.Firmware 13.42
system/common/lib/libkernel_sys.sprx(sha2563d361753f6c472cd5442bf92652b4a1dee04051297a0155fe197ede0c2002d4a), read from disassembly, not run on a console:The debt file gains the gap this doesn't close.
sceKernelStopUnloadModulenever runs the module'smodule_stopand stores 0 inres. At0x36657firmware callsmodule_stopwithargsandargpand stores its result inres(0x36663). It skips that call while a count at+0x6cis above 1 (0x364b1–0x36557), which reads like a load count. It returns0x80020010on a path (0x3648d–0x36583) that appears to cover another thread still starting the module. The loader reads a start entry and initializers from the guest lifecycle metadata (core/libs/prx/libkernel/Module/src/DynamicLoader.cpp:221and:318) but no stop entry, so a follow-up needs the relinker to record one. On Windows it also reads the metadata's dependency and sweep name lists (DeferredListNames,core/libs/prx/libkernel/Module/src/DynamicLoader.cpp:271).Tested
d164e44244(main5f2e6336edmerged in):guest_dynamic_loader,guest_kernel_sys_module_internaland the eightguest_deferred_module_*tests pass (10 of 10, none Not Run), with their three test executables rebuilt at this head.core/libs/tests/GuestDynamicLoader.cppload the test system module withflags1 and with anoptblock (refused,resuntouched), then load it, refuse to unload it withflags1, with anoptblock and as handle 0, call into it, and unload it. New rows incore/libs/tests/GuestKernelSysModuleInternal.cppcheck thatsceKernelLoadStartModuleForSysmodulewithflags0x10000still reaches the missing-file error, and that anoptblock is refused.main'score/libs/prx/libkernel/Module/src/Module.cppandcore/libs/prx/libkernel_sys/Export.cppabort (0xc0000409, 2 of 2 failed;guest_dynamic_loaderstops atGuestDynamicLoader.cpp:209, theflagsrow).guest_runtime_lifecycleandguest_dynamic_loader_fixed_base_testsare registered on Linux only, and I didn't run them. Both passflags0 and a nullopt.tools/check_conventions.py --base upstream/mainon the committed headd164e44244: all checks pass.main5f2e6336edconflicted once, indocs/dev/debt/libkernel_sys.md:mainreworded thescePthreadMutexIsowned, utrace and tcsetsidentry below this branch's new sysmoduleflagsentry. That entry takesmain's wording and theflagsentry is unchanged.5ee657294b, had adebt-lengthwarning (thelibkernel_sys.mdmodule info entry reached 1186 characters). I had run the check before committing, and it reads committed Git objects (CONTRIBUTING.md, "reads pull request Git objects"), so it didn't see the debt change. The second commit moves the sysmoduleflagsnote into its own entry, which fixes it.tools/pr_overlap.py --branch, run at the earlier headcaca1e4031: the code-file overlaps are #13486, #15037, #15115, #5021, #6149, #9097 and #9389. In their diffs only #6149 names one of these functions, in a debt line about LinuxDT_INITarguments, and none changes them. The many debt-file overlaps are other entries.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)🤖 Generated with Claude Code