fix(kernel): sceKernelMtypeprotect refuses memory types 10, 127 and -1 and undefined protection bits #19183
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19183"
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 xXPBSXx on 2026-11-12T22:58:00Z.
What
sceKernelMtypeprotectaccepted every memory type and threw for a protection with bits outside0x3F7. On a PS5 (firmware 11.60, payload process) the types 0 to 9, 11, 15 and 16 are set (run 1, lines 5 to 14 and 16 to 18 of the raw output), type 10 returnsEACCES(0x8002000d, line 15), and the types 127 and -1 returnEINVAL(0x80020016, lines 19 and 20); after a refusal the memory type the mapping had is unchanged (the probe read it back each time). A protection of 0x400 returnsEINVAL(run 1, line 21), and so do 0x8, 0x800, 0x3ff, 0xffffff00, 0xffffff7f, 0xffffff80, 0xfffffff2 and 0xffffffff (run 2, lines 6 to 13); 0x80000000 returns 0 (run 1, line 22; run 2, line 14). This returnsEACCESfor the type 10 andEINVALfor a type below 0 or of 127, andEINVALfor a protection with undefined bits instead of throwing, in each case before the mapping or its type is changed. A protection of 0x80000000 still throws here, because the console accepted it and what it does to the protection bits was not measured. The two entries forsceKernelMtypeprotectand for the protection bits indocs/dev/debt/libkernel.mdstate the measurements.Not measured, and unchanged: the types 12 to 14 and 17 to 126 (accepted here), the order in which the console checks the type and the protection, and
sceKernelBatchMap2operation 4 and the memory pool batch, which use the same path without these refusals. 2 of the 53 titles checked importsceKernelMtypeprotect, with 11 call sites: PPSA20612 passes the type 12 at all 10 of its sites, and PPSA01325 maps its input 0 to 12 and 3 or 10 to 11 and passes any other value through; the protections passed are 0xf2, 0x32 and 0x2, and none is 0x400, 0x80000000 or another bit outside0x3F7. The type 12 of the title cases was not measured, so no title is shown to pass a changed case; this is a read of the call sites, not a run. A title process was not measured.Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), in two runs on 2026-11-12 at 17:25 UTC (run 1) and 19:25 UTC (run 2). A title process may differ. The first comment has the probe source and raw output of each run; the line numbers are those of the run named.mainbeforeEACCES, type unchanged (run 1, line 15)EACCES, type unchangedEINVAL, type unchanged (run 1, lines 19, 20)EINVAL, type unchangedEINVAL(run 1, line 21)EINVALEINVAL(run 2, lines 6 to 13)EINVALThe test commit pins type 10, 127 and -1, the protection 0x400 and the eight values of run 2 other than 0x80000000 (as -256, -129, -128, -14, -1, 8, 0x800 and 0x3ff), that the memory type and protection of the mapping are unchanged after a refusal, and that the types 0, 1, 9, 11, 15 and 16 are accepted. On
main09ab49de964, Linux (WSL, Release), which contains the base of this branch and does not differ from it in the files this change touches, built for the targetguest_memorywithninjareturning 0 for each commit: with only the test commitguest_memoryaborts in 1 run, and with the fix and with the documentation commit it passes in 3 of 3 runs each. The documentation commit was changed afterwards in one sentence of the entry for the protection bits (no code or test), and the tests were not run again for that version.tools/check_conventions.pypasses with no error on each of the three commits, with onedebt-lengthwarning on the last: the entry for the protection bits is 1299 characters, up from 994 (the entry forsceKernelMtypeprotectis 734, up from 503). The probe sources and raw outputs are in the first comment. Not tested: Windows, macOS, the CI runner, a title process, any other firmware, and the cases listed above as not measured.Overlap: the 99 other open pull requests that change
DirectMemory/Export.cpp,GuestMemory.cppordocs/dev/debt/libkernel.md(found by reading the changed files of all 1649 open pull requests at about 21:30 UTC) were merged on 2026-11-12 at about 21:40 UTC againstmain59f3a64cf6(the branch is based on6907cfb864); the branch merges into it without a conflict. 60 of them already conflict withmainwithout this change and still conflict with it; 38 merge cleanly with and without it. #17794 (keep direct-memory aliases consistent across retype, release and remap, which also changessceKernelMtypeprotectinDirectMemory.cppand its entry indocs/dev/debt/libkernel.md) conflicts only with this change, inGuestMemory.cppand the debt file; its added test callssceKernelMtypeprotectwith the type 5 and the protection 3, which this change still accepts, so the two do not contradict each other; whichever of the two merges second needs a small rebase.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)AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-13T01:05:18Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
b0f761b3ae83604c9528d35605ec7e8518089ed7, basemain.Results
sceKernelMtypeprotectas stateddebt-lengthwarningmainFindings
Blocking
None.
Non-blocking
core/libs/prx/libkernel/DirectMemory/Export.cpp:538refuses only negative types and 127, anddocs/dev/debt/libkernel.md:117lists only 12 to 14 and 17 to 126 as not measured. Add 128 and above to that list, or measure them.Not verified
diff.patch. Head context was read only forExport.cpplines 60 to 70 and 520 to 560, andGuestMemory.cpplines 330 to 362 and 1150 to 1185.docs/dev/debt/libkernel.mdwas read only in its two hunks, not at the head. No file was read in full. No file was excluded.To get this to a good state
Nothing is required.
Optional: state what the console does with types 128 and above in
docs/dev/debt/libkernel.md, next to the 17 to 126 entry.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T03:18:42Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
b0f761b3ae:tools/check_conventions.pypassed;git diff --checkclean.guest_memory_testsbuilt cleanly.guest_memory_pool_stats,guest_memory_resource,guest_memory_lifetime,guest_memory,guest_mmap_fixed_anonymous,guest_mmap_executable):core/libs/prx/libkernel/DirectMemory/Export.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Generated withfooter from the description; the AI-assisted checkbox can stay.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T04:26:14Z.
Review: APPROVED
Reviewed — looks good
The change adds the measured
sceKernelMtypeprotectrefusals, matching tests and debt documentation; I found no verified blocking defect in the three changed files.What I ran
Reviewed head
6aa3592c3ae6838523c90fb7c779a7ea075cd7e7. Read the prepared description, commit list, manifest, diff, and full head text for all three changed files throughrepo_read.py. I did not run commands or tests.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported PS5 measurements and reported Linux test runs were supplied in the description and were not independently reproduced. Windows, macOS, CI, title-process behavior, and unmeasured memory types and call paths were not verified. The changed files reviewed were
core/libs/prx/libkernel/DirectMemory/Export.cpp,core/libs/tests/GuestMemory.cpp, anddocs/dev/debt/libkernel.md;files.jsonwas not available through the reader, so excluded-file details were not verified.To get this to a good state
Nothing is required.