fix(libkernel): refuse undefined protection bits in the map calls with EINVAL #11005
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11005"
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 harisibrar1 on 2026-10-25T14:04:16Z.
What
The map calls throw on protection bits outside
0x3F7, where the console returnsEINVAL.@hugodearaujo measured this in #6825: PS5 firmware 13.60, payload process, probe output in that PR's description.
sceKernelMapFlexibleMemoryaccepts every defined bit up to0x3F7, and refuses0x8,0x400,0x800,0x3FFand0xFFFFFFF2with0x80020016:MAPFLEX|req=00000008|rc=80020016MAPFLEX|req=00000400|rc=80020016MAPFLEX|req=000003f7|rc=00000000sceKernelMapDirectMemoryrefuses the same values the same way:MAPDIRECT|req=00000008|rc=80020016,MAPDIRECT|req=fffffff2|rc=80020016.On main all of these reach
LinuxProtFromSce(DirectMemory.cpp). It throwsstd::invalid_argumentthere, and thereturn SCE_KERNEL_ERROR_EINVAL;above the throw is commented out. ThesceKernelMprotect protection bitsdebt entry already records the difference ("here both throw for undefined bits").This adds an
UndefinedProtectioncheck (prot & ~0x3F7) at the start ofsceKernelMapFlexibleMemory,sceKernelMapNamedFlexibleMemory,sceKernelMapDirectMemory,sceKernelMapDirectMemory2andsceKernelMapNamedDirectMemory. Each returnsSCE_KERNEL_ERROR_EINVALbefore any mapping is changed or any flexible memory is used. The named and2forms weren't probed separately; they take the same protection argument as the measured calls.sceKernelMapNamedFlexibleMemoryInternalgoes throughsceKernelMapNamedFlexibleMemory.Left as they are:
sceKernelMtypeprotect(also measured asEINVAL) still throws, to keep clear of theDoMtypeprotectchanges in #9882.The debt sentence now says exactly which calls return
EINVALand which still throw.Tested
Windows 11, WinLibs GCC 15.2.0 r7, full Release build on main
4017310678with this change: no failed steps.guest_memory,guest_protection_reportandguest_kernel_syspass, 3 runs of 3/3.GuestMemory.cpppinned the throw in two places (try { sceKernelMapFlexibleMemory(&undefined, length, 0x400, 0); } catch (const std::invalid_argument&)andCheckStrictMemoryProtectionBits). Both now requireEINVALfrom all five calls, with the address left null and the available flexible size unchanged. The measured0x800and0x3ffare added to the existing list.sceKernelMtypeprotectkeeps its throw check.DirectMemory/Export.cpp,guest_memoryfails (2 runs).tools/check_conventions.py --base origin/mainpasses.Overlap
pr_overlapreports #9882 (@orezraey): it rewrites the neighbouring debt line (136) while this changes 137, so whichever lands second needs a trivial text merge. The other listed PRs (#4449, #6321, #7201, #10550) conflict with main and don't touch these functions or test lines.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)Depends on: #11005and will mergemainkeeping both debt entries🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T14:08:04Z.
Review: APPROVED
Reviewed the firmware 13.60 measurements cited from #6825 and the five map entry points. The early guard matches the existing
LinuxProtFromSceaccepted-bit mask, and the tests verify the invalid-bit cases return EINVAL without changing the output address, flexible-memory availability, or existing mapping state. ThesceKernelMtypeprotectand batch map behavior remains explicitly out of scope as documented. I verifiedgit diff --check, the repository convention script (0 errors; it reports the existing long debt-entry warning), and a local C++20 syntax check ofDirectMemory/Export.cpp. The PR includes Windows full-build and focused runtime results; Linux/macOS product runtime tests were not run here.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T14:43:58Z.
Review: DISMISSED
Requesting merge-order coordination with #9882 before this can be approved. CONTRIBUTING.md says overlapping PR authors should agree which goes first. I fetched both current heads and
git merge-tree --write-treeconfirms a content conflict indocs/dev/debt/libkernel.md. This PR’s checklist saysDepends on: none (debt-line order with #9882 above), but I found no agreement from #9882’s author establishing that order. Please record mutual agreement and the corresponding dependency/order, then rebase or merge the debt text cleanly. The implementation and test review otherwise stands; this is specifically the unresolved contribution-rule blocker.