fix(libkernel): refuse undefined protection bits in sceKernelBatchMap's map operations, as a PS5 does #22040

Merged
brajankw merged 1 commit from upstream-pr/22040 into main 2026-12-03 17:39:05 +00:00
brajankw commented 2026-11-17 03:05:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-17T03:05:49Z.


What

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 sceKernelMprotect protection bits entry in docs/dev/debt/libkernel.md, which listed the batch map calls as throwing).

  • The batch map's direct and flexible map operations check the same bits and stop with EINVAL at that entry, reporting the entries processed before it. Only the single map calls were measured; the batch calls are taken to refuse them the same way.
  • GuestKernelBatchMapGuestPointers.cpp: a flexible entry with 0x0b after a good one stops with EINVAL and 1 processed; a direct entry with 0x08 stops with EINVAL and 0 processed.
  • #19183 rewrites the end of the same debt sentence (for sceKernelMtypeprotect); whichever lands second merges the wording.

Tested

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

  • ctest -R '^guest_kernel_batch_map_guest_pointers$': passed.
  • Negative control: with main's Export.cpp and this branch's test, guest_kernel_batch_map_guest_pointers aborts with Unsupported memory protection bits: 11.
  • Full ctest (5896 tests, -j 12) with this branch and my other twelve branches of this round merged onto main 521fb7fec4: 5880 passed. The 16 failures are the set that fails on main in the same environment: six agc_driver cases (agc_driver_image_table_packed_guards passes when run on its own) and ten that need a .git directory, 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 #16945, #17718, #17936 and #21569, which conflict with main; none of their diffs touches sceKernelBatchMap2.
  • Not tested on Windows or macOS. No title.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5349746399 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22040). Originally posted by [brajankw](https://github.com/brajankw) on 2026-11-17T03:05:49Z. --- ### What 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 `sceKernelMprotect protection bits` entry in `docs/dev/debt/libkernel.md`, which listed the batch map calls as throwing). - The batch map's direct and flexible map operations check the same bits and stop with `EINVAL` at that entry, reporting the entries processed before it. Only the single map calls were measured; the batch calls are taken to refuse them the same way. - `GuestKernelBatchMapGuestPointers.cpp`: a flexible entry with 0x0b after a good one stops with `EINVAL` and 1 processed; a direct entry with 0x08 stops with `EINVAL` and 0 processed. - #19183 rewrites the end of the same debt sentence (for `sceKernelMtypeprotect`); whichever lands second merges the wording. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux (Debian 13, GCC 14.2.0, Release), on `main` `ec7369ecb8`. - `ctest -R '^guest_kernel_batch_map_guest_pointers$'`: passed. - Negative control: with `main`'s `Export.cpp` and this branch's test, `guest_kernel_batch_map_guest_pointers` aborts with `Unsupported memory protection bits: 11`. - Full `ctest` (5896 tests, `-j 12`) with this branch and my other twelve branches of this round merged onto `main` `521fb7fec4`: 5880 passed. The 16 failures are the set that fails on `main` in the same environment: six `agc_driver` cases (`agc_driver_image_table_packed_guards` passes when run on its own) and ten that need a `.git` directory, 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 #16945, #17718, #17936 and #21569, which conflict with `main`; none of their diffs touches `sceKernelBatchMap2`. - Not tested on Windows or macOS. No title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-17 03:14:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T03:14:21Z.

Review: APPROVED


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

  • 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 #5530: guest_kernel_batch_map_guest_pointers ...   Passed    0.03 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 #5530: guest_kernel_batch_map_guest_pointers ...Subprocess aborted***Exception:   0.41 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Checked core/libs/prx/libkernel/DirectMemory/Export.cpp:733 for correct validation order, verifying that entry.operation == OpMapDirect || entry.operation == OpMapFlexible is checked prior to invoking DoMapDirect and DoMapFlexible.
    • Verified that UndefinedProtection(static_cast<uint8_t>(entry.protection)) checks bits outside 0x3F7 and returns SCE_KERNEL_ERROR_EINVAL immediately, halting batch processing at that entry and updating the processed count correctly.
    • Verified that docs/dev/debt/changes/fix-libkernel-batch-map-undefined-protection.md properly documents the debt change for sceKernelMprotect protection bits in accordance with AGENTS.md debt fragment requirements.
    • Verified that core/libs/tests/GuestKernelBatchMapGuestPointers.cpp CheckUndefinedProtection exercises both flexible mapping (with 0x0b) and direct mapping (with 0x08) batch operations, checking partial processing counts and error return values.
    • Verified that no forbidden comments, made-up stubs, or unauthorized file modifications were introduced.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5932177166 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22040#pullrequestreview-5932177166). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T03:14:21Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `b0f39f3a37`: - **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 #5530: guest_kernel_batch_map_guest_pointers ... Passed 0.03 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 #5530: guest_kernel_batch_map_guest_pointers ...Subprocess aborted***Exception: 0.41 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Checked core/libs/prx/libkernel/DirectMemory/Export.cpp:733 for correct validation order, verifying that entry.operation == OpMapDirect || entry.operation == OpMapFlexible is checked prior to invoking DoMapDirect and DoMapFlexible. - Verified that UndefinedProtection(static_cast<uint8_t>(entry.protection)) checks bits outside 0x3F7 and returns SCE_KERNEL_ERROR_EINVAL immediately, halting batch processing at that entry and updating the processed count correctly. - Verified that docs/dev/debt/changes/fix-libkernel-batch-map-undefined-protection.md properly documents the debt change for sceKernelMprotect protection bits in accordance with AGENTS.md debt fragment requirements. - Verified that core/libs/tests/GuestKernelBatchMapGuestPointers.cpp CheckUndefinedProtection exercises both flexible mapping (with 0x0b) and direct mapping (with 0x08) batch operations, checking partial processing counts and error return values. - Verified that no forbidden comments, made-up stubs, or unauthorized file modifications were introduced. Looks Good To Me
MarcZX10 commented 2026-11-23 01:46:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T01:46:26Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the review evidence supports merging.

What I ran

Reviewed head b0f39f3a37381c4eea052cb912f6dd9e502002b9 using the prepared diff and pinned reader. No commands or tests were run by me; the PR description reports Linux tests and convention checks.

Results

Check Result Note
Changed code review passed All three changed files read
Tests run by reviewer not run Author-reported results are not reviewer runs
Context review passed Guard, mapping functions, and batch completion path read

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run independently. Windows and macOS behavior, console behavior, and the author-reported tests were not independently verified. Read: core/libs/prx/libkernel/DirectMemory/Export.cpp, core/libs/tests/GuestKernelBatchMapGuestPointers.cpp, and docs/dev/debt/changes/fix-libkernel-batch-map-undefined-protection.md. The prepared bundle lists all three changed files as included; no changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015714535 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22040#pullrequestreview-6015714535). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T01:46:26Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the review evidence supports merging. ## What I ran Reviewed head `b0f39f3a37381c4eea052cb912f6dd9e502002b9` using the prepared diff and pinned reader. No commands or tests were run by me; the PR description reports Linux tests and convention checks. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | All three changed files read | | Tests run by reviewer | not run | Author-reported results are not reviewer runs | | Context review | passed | Guard, mapping functions, and batch completion path read | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests were run independently. Windows and macOS behavior, console behavior, and the author-reported tests were not independently verified. Read: `core/libs/prx/libkernel/DirectMemory/Export.cpp`, `core/libs/tests/GuestKernelBatchMapGuestPointers.cpp`, and `docs/dev/debt/changes/fix-libkernel-batch-map-undefined-protection.md`. The prepared bundle lists all three changed files as included; no changed files were excluded. ## To get this to a good state Nothing is required.
Plyxen commented 2026-12-03 14:08:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T14:08:16Z.

Review: APPROVED


I read the diff at b0f39f3a37. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into main at 6c6b29320fe together with other open PRs (so not an isolated build).

  • guest_kernel_batch_map_guest_pointers: pass on both.
  • Control (the same tree with only this PR's source change taken out): on Windows it stops with "Unsupported memory protection bits: 11". On Linux, with the changed sources of the tested CPU PRs put back to main's, the same test fails too.

Not checked: a console.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6171377936 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22040#pullrequestreview-6171377936). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-03T14:08:16Z. **Review:** APPROVED --- I read the diff at `b0f39f3a37`. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into `main` at `6c6b29320fe` together with other open PRs (so not an isolated build). - `guest_kernel_batch_map_guest_pointers`: pass on both. - Control (the same tree with only this PR's source change taken out): on Windows it stops with "Unsupported memory protection bits: 11". On Linux, with the changed sources of the tested CPU PRs put back to `main`'s, the same test fails too. Not checked: a console. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 15:12:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T15:12:48Z.

Review: COMMENTED


I compiled and ran GuestKernelBatchMapGuestPointers from this branch on Linux against the existing runtime libraries. It passed the direct-map rejection and partial-progress checks. #22051 changes the same mapping path and also covers the protect operation, so please coordinate the merge order for the shared change.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6172592260 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22040#pullrequestreview-6172592260). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T15:12:48Z. **Review:** COMMENTED --- I compiled and ran `GuestKernelBatchMapGuestPointers` from this branch on Linux against the existing runtime libraries. It passed the direct-map rejection and partial-progress checks. #22051 changes the same mapping path and also covers the protect operation, so please coordinate the merge order for the shared change. AI-assisted: yes.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!22040
No description provided.