Skip to content

fix(libkernel): drop undefined protection bits in sceKernelBatchMap's protect operation, as sceKernelMprotect does - #22051

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
brajankw:fix/libkernel-batch-map-protect-drops-undefined-bits
Dec 3, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
brajankw:fix/libkernel-batch-map-protect-drops-undefined-bits

Conversation

@brajankw

Copy link
Copy Markdown
Contributor

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. sceKernelMprotect drops those bits, as a PS5 (firmware 13.60) does (the sceKernelMprotect protection bits entry in docs/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.

Tested

Linux (Debian 13, GCC 14.2.0, Release), on main ec7369ecb8.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: fix(libkernel): refuse undefined protection bits in sceKernelBatchMap's map operations, as a PS5 does #22040
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

brajankw and others added 2 commits November 17, 2026 03:27
…'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 PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 393aaeab12:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_kernel_batch_map_guest_pointers built 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.cpp reverted to main and the new tests kept, the suite fails:
    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
    
    Restoring the change makes it pass again.
  • 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

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 21569 core/libs/prx/libkernel/DirectMemory/Export.cpp
PR 28264 core/libs/prx/libkernel/DirectMemory/Export.cpp

AltewamaPrime added a commit to AltewamaPrime/AnyPS5 that referenced this pull request Nov 20, 2026
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.
@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 393aaeab12, applied with git apply (with -C1, context shifted) on main fd4aeed483 together with the other 26 PRs of one batch (#24498, #24665, #17297, #21499, #21726, #22534, #12900, #17843, #22075, #23087, #23206, #23222, #23227, #13147, #17482, #21935, #17477, #18272, #22858, #22929, #23028, #23295, #23916, #24179, #24706, #12619). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
guest_kernel_batch_map_guest_pointers (1 test, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6525 tests) on the RTX 3080 has 8 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. Traced to other PRs of the batch, each by reverting it and testing again: #18272 (guest_audio_out), #12900 (guest_user_service_initial_user_bounds); none is in this PR's area. Failing tests I could not trace to a single PR (reverting the likely candidates did not clear them): guest_content_search. The 2125 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 0x09 via sceKernelBatchMap, while the change is in sceKernelBatchMap2's protect operation. sceKernelBatchMap delegates to sceKernelBatchMap2, so the path is covered, but a direct sceKernelBatchMap2 protect 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 ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@oneandonlydean
oneandonlydean merged commit ad31d98 into boykopovar:main Dec 3, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants