Repository navigation
fix(libkernel): drop undefined protection bits in sceKernelBatchMap's protect operation, as sceKernelMprotect does - #22051
Conversation
…'s map operations, as a PS5 does A batch map entry whose protection had an undefined bit (0x08) threw from the host protection conversion. The console refuses undefined protection bits in the map calls with EINVAL before mapping, as the five single flexible and direct map calls here already do. The batch map's direct and flexible map operations now check the same bits and stop with EINVAL at that entry, reporting the entries processed before it. The protect and type-protect operations are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… protect operation, as sceKernelMprotect does A batch map protect entry with a protection bit outside 0x3F7 threw from the host protection conversion. sceKernelMprotect drops those bits, as a PS5 (firmware 13.60) does, and the batch protect operation is the same change of protection, so it now drops them too. The map operations refuse them, and the type-protect operation still throws. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 393aaeab12:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_kernel_batch_map_guest_pointersbuilt cleanly. - CTest (
guest_kernel_batch_map_guest_pointers):1/1 Test #5529: guest_kernel_batch_map_guest_pointers ... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libkernel/DirectMemory/Export.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #5529: guest_kernel_batch_map_guest_pointers ...Subprocess aborted***Exception: 0.45 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified core/libs/prx/libkernel/DirectMemory/Export.cpp: sceKernelBatchMap2 validates UndefinedProtection for OpMapDirect and OpMapFlexible returning SCE_KERNEL_ERROR_EINVAL before dispatch.
- Verified core/libs/prx/libkernel/DirectMemory/Export.cpp: OpProtect masks static_cast<uint8_t>(entry.protection) with 0x3F7 matching sceKernelMprotect behavior and debt documentation.
- Verified core/libs/prx/libkernel/DirectMemory/Export.cpp: OpTypeProtect is kept unchanged and continues delegating directly without masking, consistent with PS5 mtypeprotect behavior.
- Verified core/libs/tests/GuestKernelBatchMapGuestPointers.cpp: CheckUndefinedProtection and CheckProtectDropsUndefinedBits verify rejection on map operations and masking down to 0x1 via sceKernelVirtualQuery for OpProtect with 0x09.
- Verified technical debt documentation in docs/dev/debt/changes/fix-libkernel-batch-map-undefined-protection.md properly documents the behavior and follows AGENTS.md debt fragment conventions.
Looks Good To Me
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
A batch map type-protect entry passed its protection to DoMtypeprotect, whose protection validation throws std::invalid_argument for bits outside 0x3F7, so an undefined bit ended the title instead of returning an error. The entry now answers SCE_KERNEL_ERROR_EINVAL (0x80020016) through the existing UndefinedProtection() helper, before its range is looked at, and leaves the range untouched. The single sceKernelMtypeprotect change and the batch protect masking are left to boykopovar#19183 and boykopovar#22051.
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — comments
The mapped code applies the existing protection-bit mask consistently to batch protect operations; the host test results and console behavior were not independently verified.
What I ran
Read the prepared diff and all three changed files at head 393aaeab12eed1d23e822e98fd1c091869bbf22e, plus the protection-mask helper and the existing sceKernelMprotect implementation in Export.cpp. No commands or tests were run.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | All changed files read |
| Tests | not run | Only author-reported results available |
| Windows/macOS and console | not run | No independent verification |
Findings
Blocking
None.
Non-blocking
- The regression test exercises
0x09viasceKernelBatchMap, while the change is insceKernelBatchMap2's protect operation.sceKernelBatchMapdelegates tosceKernelBatchMap2, so the path is covered, but a directsceKernelBatchMap2protect case would make the test more explicit (core/libs/tests/GuestKernelBatchMapGuestPointers.cpp:141).
Not verified
- Author-reported Linux test, negative-control, full-suite, convention-check, and overlap-check results were not run independently.
- Windows, macOS, and physical-console behavior were not independently verified.
- Files read:
core/libs/prx/libkernel/DirectMemory/Export.cpp,core/libs/tests/GuestKernelBatchMapGuestPointers.cpp,docs/dev/debt/changes/fix-libkernel-batch-map-undefined-protection.md. No changed files were excluded; all three were marked included in the manifest.
To get this to a good state
Nothing is required. The direct sceKernelBatchMap2 test case is optional.
ligmaSec
left a comment
There was a problem hiding this comment.
I compiled and ran GuestKernelBatchMapGuestPointers from this branch on Linux against the existing runtime libraries. It passed the partial-progress checks for rejected map protections and the virtual-query check for protections applied by the protect operation. This overlaps the map-protection change in #22040. Please coordinate the merge order for the shared change.
AI-assisted: yes.
What
Builds on #22040, which this branch contains; review its last commit. A batch map protect entry with a protection bit outside 0x3F7 threw from the host protection conversion.
sceKernelMprotectdrops those bits, as a PS5 (firmware 13.60) does (thesceKernelMprotect protection bitsentry indocs/dev/debt/libkernel.md), and the batch protect operation is the same change of protection, so it drops them too. The map operations refuse them (#22040) and the type-protect operation still throws.GuestKernelBatchMapGuestPointers.cpp: protecting a mapped page with 0x09 through the batch call succeeds and leaves protection 1.Tested
Linux (Debian 13, GCC 14.2.0, Release), on
mainec7369ecb8.ctest -R '^guest_kernel_batch_map_guest_pointers$': passed.Export.cppand this branch's test,guest_kernel_batch_map_guest_pointersaborts withUnsupported memory protection bits: 9.ctest(5896 tests,-j 12) with this branch and my other twelve branches of this round merged ontomain521fb7fec4: 5880 passed. The 16 failures are the set that fails onmainin the same environment: sixagc_drivercases (agc_driver_image_table_packed_guardspasses when run on its own) and ten that need a.gitdirectory, network or a passwd entry for the user.python3 tools/check_conventions.py --base origin/main: passed.python3 tools/pr_overlap.py --branch: failed closed on fix(libkernel): sceKernelMapNamedDirectMemory returns ENAMETOOLONG for a 32 character name and EFAULT for a NULL name #16945, fix(libkernel): sceKernelMapNamedSystemFlexibleMemory maps and then rejects a name of 32 characters or a null name #17718, fix(libkernel_sys): answer sceKernelGetPhysPageSize for the mapping holding an address #17936 and fix(libkernel): bound virtual range names as the console does #21569, which conflict withmain; none of their diffs touchessceKernelBatchMap2. Otherwise no overlap besides fix(libkernel): refuse undefined protection bits in sceKernelBatchMap's map operations, as a PS5 does #22040, which it builds on.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)