Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
brajankw:fix/libkernel-memory-pool-batch-protect-drops-undefined-bits
Nov 17, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
brajankw:fix/libkernel-memory-pool-batch-protect-drops-undefined-bits

Conversation

@brajankw

Copy link
Copy Markdown
Contributor

What

sceKernelMemoryPoolBatch passed a protect entry's protection to DoMprotect unmasked. A bit outside 0x3F7, such as 0x08, made the host protection conversion throw, and the batch's guard turned that into SCE_KERNEL_ERROR_EINVAL. sceKernelMprotect drops those bits, as a PS5 (firmware 13.60) does; see the sceKernelMprotect protection bits entry in docs/dev/debt/libkernel.md, and FreeBSD 11.4 masks the argument in sys/vm/vm_mmap.c. A pool batch protect is the same change of protection, so it now masks with the same 0x3F7 (DefinedProtection). The console was measured only through sceKernelMprotect, so applying this to the pool batch is an inference. The commit and type-protect operations are unchanged, and unlike sceKernelMprotect the batch still refuses a zero length and needs a mapped start.

Tested

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

  • ctest -R '^(guest_kernel_batch_map_guest_pointers|guest_memory.*)$': 5 passed.
  • Negative control: on main, the new check aborts at the sceKernelMemoryPoolBatch call, which does not return 0.
  • Full ctest (6000 tests, -j 12) on this branch and my other five branches of this round, merged onto main 47b33132f9: 5985 passed. All 15 failures also fail on main in the same environment:
    • nine need a .git directory, network access or a passwd entry for the user: conventions_git_errors, test_script_registration, web_library_assets, title_run, title_run_identity, guest_kernel_sys_login, guest_net_ctl, guest_getlogin and guest_getlogin_no_session;
    • six are agc_driver cases (agc_driver_image_table_packed_guards passes when run on its own).
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch: no overlap with open pull requests.
  • 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

…Batch's protect operation, as sceKernelMprotect does

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 535808524b:

  • 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 #5632: 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/MemoryPoolExport.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5632: guest_kernel_batch_map_guest_pointers ...Subprocess aborted***Exception:   0.60 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified sceKernelMemoryPoolBatch entry op=3 masking e.protect.prot & DefinedProtection (0x3F7) in MemoryPoolExport.cpp:92 matches DefinedProtection constant and FreeBSD 11.4 vm_mmap.c / sceKernelMprotect masking conventions
    • Verified technical debt fragment format and file location at docs/dev/debt/changes/fix-libkernel-memory-pool-batch-protect-drops-undefined-bits.md matches repo guidelines
    • Verified GuestKernelBatchMapGuestPointers.cpp test CheckPoolProtectDropsUndefinedBits allocates flexible memory, exercises batch protect op with undefined bits 0x09 and 0x0B, checks protection via sceKernelVirtualQuery, and cleans up via sceKernelMunmap
    • Verified 64-bit/32-bit types, integer sign/masking behavior, concurrency, and lack of code comments in MemoryPoolExport.cpp

Looks Good To Me

@oneandonlydean
oneandonlydean merged commit 4ba9461 into boykopovar:main Nov 17, 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.

3 participants