Repository navigation
fix(libkernel): refuse single-bit flexible map flags with EINVAL as measured - #16489
Merged
Merged
Conversation
…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.
Contributor
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
|
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.
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.
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
sceKernelMapFlexibleMemorythrewstd::invalid_argument("Unsupported memory mapping flags 0x..") for single flag bits, andsceKernelMapNamedFlexibleMemorythrew for0x8000, where a PS5 returnsEINVAL.Source: the
sceKernelMapFlexibleMemoryentry indocs/dev/debt/libkernel.md(line 113 on917bf9f144) and #10305, measured on a retail PS5 (firmware 13.60) throughlibkernel_sys.sprxfrom a payload process (console log in the gist linked from #10305):sceKernelMapFlexibleMemoryfailed every single flag from0x1to0x100000except0x80withEINVAL(0x10was not tried), andsceKernelMapNamedFlexibleMemoryfailed0x8000withEINVAL.Change, in
core/libs/prx/libkernel/DirectMemory/Export.cpp(platform independent, before any mapping or accounting):sceKernelMapFlexibleMemory(:338) returnsSCE_KERNEL_ERROR_EINVAL, leaving the output address untouched, whenflagsis exactly one of0x1 0x2 0x4 0x8 0x20 0x40 0x100 0x200 0x400 0x800 0x1000 0x2000 0x4000 0x10000 0x20000 0x40000 0x80000 0x100000, listed inRefusedFlexibleFlag(:65), not as a range.sceKernelMapNamedFlexibleMemory(:352) returnsEINVALforflags == 0x8000.sceKernelMapNamedFlexibleMemoryInternalstrips0x8000first and is unaffected.0x8000stays accepted insceKernelMapFlexibleMemory(PPSA22520 passes it, fix(libkernel): accept flag 0x8000 in sceKernelMapFlexibleMemory #4859), as does0x10(untried on the console) and0x80.0x100000other than the supported0x400000, and every other flag of the named call (only0x8000was measured there).Same shape as #11005 (undefined protection bits refused with
EINVALas measured). The debt entry drops the now-false "those flags throw" text and keeps what still throws.Tested
-j2, headdca5752e1bonmain917bf9f144:ctest --test-dir build -R '^guest_memory$'passes, 3 runs of 3.CheckFlexibleMappingRefusesMeasuredFlagsincore/libs/tests/GuestMemory.cpp: for each of the 18 bits,sceKernelMapFlexibleMemoryreturnsEINVALwith a null output and with a sentinel output left unchanged, andsceKernelAvailableFlexibleMemorySizeis unchanged;sceKernelMapNamedFlexibleMemorywith0x8000returnsEINVALwith the output null and the budget unchanged. The old0x20000throw assertion inCheckFlexibleMappingIgnoresFlag8000is replaced by this loop; the Internal variant's0x20000check is unchanged.main'sDirectMemory/Export.cppand this test,guest_memoryaborts: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; onedebt-lengthwarning (entry is 1140 characters, 988 onmain).guest_memory,guest_mmap_executableandguest_mmap_fixed_anonymous3 of 3 passing on Windows 11 with GCC 15.2 UCRT, headdca5752e1bmerged ontoc9c04df940(comment).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-treeof this head against the head of every open PR that touchesDirectMemory/Export.cpp,core/libs/tests/GuestMemory.cppordocs/dev/debt/libkernel.mdshows no conflict thatmaindoes not already have with that PR:DirectMemory/Export.cpp: fix(libkernel): accept any sceKernelDirectMemoryQuery size and refuse flags 2 and 4 as the console does #16378, fix(libkernel): return EFAULT from sceKernelMmap for an unusable output pointer #16198, fix(libkernel): check sceKernelMapDirectMemory2's flags and alignment as firmware 13.42 does #16174, test(agc): cover idle publication through dma-buf imports #14330, fix(libkernel): return EACCES for unknown ranges on direct-memory release paths #7105. fix(libkernel): accept any sceKernelDirectMemoryQuery size and refuse flags 2 and 4 as the console does #16378, fix(libkernel): check sceKernelMapDirectMemory2's flags and alignment as firmware 13.42 does #16174 and test(agc): cover idle publication through dma-buf imports #14330 merge cleanly; fix(libkernel): return EFAULT from sceKernelMmap for an unusable output pointer #16198 conflicts only inlibkernel.md, fix(libkernel): return EACCES for unknown ranges on direct-memory release paths #7105 inDirectMemory/Export.cppand others, both identical to their conflicts withmain.GuestMemory.cpp: fix(libkernel): validate the alignment of a fixed direct memory map before replacing mappings #16333 (adds tests near line 941) merges cleanly, as do feat(libc): arm compared and resident guest memory under APS5_ARM_COMPARED and APS5_ARM_RESIDENT #16372, perf(libc, libkernel): keep aliased direct memory on the Linux write watch and collect stores through every alias #12452 and feat(agc): publish completed native color snapshots #6989.docs/dev/debt/libkernel.md: 113 open PRs touch the file; none conflicts with this head that does not already conflict withmain(45 conflict withmaintoo).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)