Skip to content

fix(libkernel): refuse single-bit flexible map flags with EINVAL as measured - #16489

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
sherySJ:agent/anyps5-mapflex
Nov 11, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
sherySJ:agent/anyps5-mapflex

Conversation

@sherySJ

@sherySJ sherySJ commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What

sceKernelMapFlexibleMemory threw std::invalid_argument ("Unsupported memory mapping flags 0x..") for single flag bits, and sceKernelMapNamedFlexibleMemory threw for 0x8000, where a PS5 returns EINVAL.

Source: the sceKernelMapFlexibleMemory entry in docs/dev/debt/libkernel.md (line 113 on 917bf9f144) and #10305, measured on a retail PS5 (firmware 13.60) through libkernel_sys.sprx from a payload process (console log in the gist linked from #10305): sceKernelMapFlexibleMemory failed every single flag from 0x1 to 0x100000 except 0x80 with EINVAL (0x10 was not tried), and sceKernelMapNamedFlexibleMemory failed 0x8000 with EINVAL.

Change, in core/libs/prx/libkernel/DirectMemory/Export.cpp (platform independent, before any mapping or accounting):

  • sceKernelMapFlexibleMemory (:338) returns SCE_KERNEL_ERROR_EINVAL, leaving the output address untouched, when flags is exactly one of 0x1 0x2 0x4 0x8 0x20 0x40 0x100 0x200 0x400 0x800 0x1000 0x2000 0x4000 0x10000 0x20000 0x40000 0x80000 0x100000, listed in RefusedFlexibleFlag (:65), not as a range.
  • sceKernelMapNamedFlexibleMemory (:352) returns EINVAL for flags == 0x8000. sceKernelMapNamedFlexibleMemoryInternal strips 0x8000 first and is unaffected.
  • 0x8000 stays accepted in sceKernelMapFlexibleMemory (PPSA22520 passes it, fix(libkernel): accept flag 0x8000 in sceKernelMapFlexibleMemory #4859), as does 0x10 (untried on the console) and 0x80.
  • Still throwing: flag sets of several bits, flags above 0x100000 other than the supported 0x400000, and every other flag of the named call (only 0x8000 was measured there).

Same shape as #11005 (undefined protection bits refused with EINVAL as measured). The debt entry drops the now-false "those flags throw" text and keeps what still throws.

Tested

  • Linux x86-64, GCC 16.2.1, Release, -j2, head dca5752e1b on main 917bf9f144: ctest --test-dir build -R '^guest_memory$' passes, 3 runs of 3.
  • New CheckFlexibleMappingRefusesMeasuredFlags in core/libs/tests/GuestMemory.cpp: for each of the 18 bits, sceKernelMapFlexibleMemory returns EINVAL with a null output and with a sentinel output left unchanged, and sceKernelAvailableFlexibleMemorySize is unchanged; sceKernelMapNamedFlexibleMemory with 0x8000 returns EINVAL with the output null and the budget unchanged. The old 0x20000 throw assertion in CheckFlexibleMappingIgnoresFlag8000 is replaced by this loop; the Internal variant's 0x20000 check is unchanged.
  • Negative control: with main's DirectMemory/Export.cpp and this test, guest_memory aborts: terminate called after throwing an instance of 'std::invalid_argument' what(): Unsupported memory mapping flags 0x1. With the change it passes.
  • python3 tools/check_conventions.py --base origin/main: 0 errors; one debt-length warning (entry is 1140 characters, 988 on main).
  • Windows: @JJenkx ran guest_memory, guest_mmap_executable and guest_mmap_fixed_anonymous 3 of 3 passing on Windows 11 with GCC 15.2 UCRT, head dca5752e1b merged onto c9c04df940 (comment).
  • Not run: tools/pr_overlap.py.

Overlap

Base 917bf9f144. claims.py check-branch HEAD (synced against 1884 open PRs) reports no open PR touching these lines. git merge-tree --write-tree of this head against the head of every open PR that touches DirectMemory/Export.cpp, core/libs/tests/GuestMemory.cpp or docs/dev/debt/libkernel.md shows no conflict that main does not already have with that PR:

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
  • 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

…easured

sceKernelMapFlexibleMemory threw std::invalid_argument ("Unsupported memory
mapping flags") for single flag bits, and sceKernelMapNamedFlexibleMemory
threw for 0x8000, where a PS5 returns EINVAL.

Source: docs/dev/debt/libkernel.md (the sceKernelMapFlexibleMemory entry) and
boykopovar#10305, a PS5 payload run on firmware 13.60: sceKernelMapFlexibleMemory failed
every single flag from 0x1 to 0x100000 except 0x80 with EINVAL (0x10 was not
tried), and sceKernelMapNamedFlexibleMemory failed 0x8000 with EINVAL.

sceKernelMapFlexibleMemory now returns EINVAL, leaving the address untouched,
for exactly 0x1 0x2 0x4 0x8 0x20 0x40 0x100 0x200 0x400 0x800 0x1000 0x2000
0x4000 0x10000 0x20000 0x40000 0x80000 0x100000. 0x8000 stays accepted there
(PPSA22520 passes it, boykopovar#4859). sceKernelMapNamedFlexibleMemory returns EINVAL
for 0x8000; the Internal variant strips it first and is unaffected. Flag sets
of several bits and unmeasured flags still throw.

Test: GuestMemory.cpp CheckFlexibleMappingRefusesMeasuredFlags loops over the
18 bits asserting EINVAL, the output untouched and the flexible budget
unchanged, plus the named 0x8000 case. The old throw check for 0x20000 in
CheckFlexibleMappingIgnoresFlag8000 is replaced by the loop.
@JJenkx

JJenkx commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Windows check of head dca5752e1b, merged onto main c9c04df940 (097e12dd90, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_memory passes in 3 of 3 runs, none skipped, on a fresh merge and build. guest_mmap_executable and guest_mmap_fixed_anonymous pass in 3 of 3 too. main at c9c04df940 also passes guest_memory 3 of 3 here.
  • Resolved (my test harness): the first-run failure in guest_memory was caused by how I invoked it, not by this change. My batch loop fed a file to the tests as stdin, so descriptor 0 was a real readable file. The reject checks that call mmap with fd 0 and expect a failure then got a successful mapping. Confirmed on main: ctest -R ^guest_memory$ with a regular file as stdin fails, and with /dev/null it passes. My runs now always use /dev/null.

AI-assisted: yes.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 17794 docs/dev/debt/libkernel.md L116-117

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 5021 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 6149 docs/dev/debt/libkernel.md
PR 6936 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7447 docs/dev/debt/libkernel.md
PR 7464 docs/dev/debt/libkernel.md
PR 9156 docs/dev/debt/libkernel.md
PR 9199 docs/dev/debt/libkernel.md
PR 9293 docs/dev/debt/libkernel.md
PR 9297 docs/dev/debt/libkernel.md
PR 9302 docs/dev/debt/libkernel.md
PR 9389 docs/dev/debt/libkernel.md
PR 9557 docs/dev/debt/libkernel.md
PR 9566 docs/dev/debt/libkernel.md
PR 9938 docs/dev/debt/libkernel.md
PR 10442 docs/dev/debt/libkernel.md
PR 11215 docs/dev/debt/libkernel.md
PR 11628 docs/dev/debt/libkernel.md
PR 11661 docs/dev/debt/libkernel.md
PR 11689 docs/dev/debt/libkernel.md
PR 11698 docs/dev/debt/libkernel.md
PR 11896 docs/dev/debt/libkernel.md
PR 12682 docs/dev/debt/libkernel.md
PR 12688 docs/dev/debt/libkernel.md
PR 12700 docs/dev/debt/libkernel.md
PR 12965 docs/dev/debt/libkernel.md
PR 14108 docs/dev/debt/libkernel.md
PR 14128 docs/dev/debt/libkernel.md
PR 14212 docs/dev/debt/libkernel.md
PR 14497 docs/dev/debt/libkernel.md
PR 14756 docs/dev/debt/libkernel.md
PR 15037 docs/dev/debt/libkernel.md
PR 15524 docs/dev/debt/libkernel.md
PR 15567 docs/dev/debt/libkernel.md
PR 15571 docs/dev/debt/libkernel.md
PR 17216 docs/dev/debt/libkernel.md
PR 17220 docs/dev/debt/libkernel.md
PR 17222 docs/dev/debt/libkernel.md
PR 17223 docs/dev/debt/libkernel.md
PR 17228 docs/dev/debt/libkernel.md
PR 17257 docs/dev/debt/libkernel.md
PR 17584 docs/dev/debt/libkernel.md
PR 17585 docs/dev/debt/libkernel.md
PR 17897 docs/dev/debt/libkernel.md
PR 17908 docs/dev/debt/libkernel.md
PR 18197 docs/dev/debt/libkernel.md
PR 18515 docs/dev/debt/libkernel.md

@oneandonlydean oneandonlydean self-assigned this Nov 9, 2026
@oneandonlydean
oneandonlydean merged commit 8ee20ce into boykopovar:main Nov 11, 2026
15 checks passed
chitters2004 added a commit to chitters2004/AnyPS5 that referenced this pull request Nov 11, 2026
Conflict in docs/dev/debt/libkernel.md only: main's boykopovar#16489 rewrote the
sceKernelMapFlexibleMemory line next to this branch's sceKernelMtypeprotect
line. Kept main's sceKernelMapFlexibleMemory line and this branch's
sceKernelMtypeprotect line; nothing else changed on either side.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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