fix(libkernel): fail a fixed no-overwrite map over a reservation with ENOMEM #27445
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27445"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Herolias on 2026-11-26T11:55:33Z.
What
sceKernelMapDirectMemory,sceKernelMapFlexibleMemoryandsceKernelReserveVirtualRangewithMAP_FIXED | MAP_NO_OVERWRITE(0x90) over reserved pages ended the process with an unhandledstd::runtime_error,fixed mapping ... overlaps a registered guest allocation .... They now returnSCE_KERNEL_ERROR_ENOMEMand leave the reservation in place. The named, system-flexible and batch map calls that shareDoMapDirectandMapAnonymouschange with them.sceKernelMemoryPoolReservesharesDoReserveVirtual. It returnedSCE_KERNEL_ERROR_EINVALfor the same call, because it turns any exception intoEINVAL; it now returnsENOMEMtoo.FixedNoOverwriteConflict(e9c8664d43) leaves reserved ranges out of the conflict, but nothing after it takes them:RemapFixedIntoRegisteredrefuses no-overwrite, andReplaceFixedOverlapandDoReserveVirtualthen callRequireAvailable, which throws on any registered overlap. The carve-out is now gone. The only calls it let through were ones that went on to throw, so no call that succeeded before changes. Filemmapalready returnedENOMEMhere, because it catches the exception, and still does.5095176ccd(#10192) already meantsceKernelReserveVirtualRangeto returnENOMEMon a no-overwrite conflict "instead of terminating the process", and the libkernel debt entry "Fixed reservations outside the guest arena" says it does. Over a reservation it did not.DoMapDirectandMapAnonymousthe check now runs beforePlaceHintInReservation, so that it sees the caller's flags. A no-overwrite hint withoutMAP_FIXEDinside a reservation is therefore unchanged: it still throws, because no source here says where the console puts it.Sources:
MapMemoryTest, lines 465-481 maps a range with0x110(void and fixed, a reservation; line 186 sayssceKernelReserveVirtualRangeuses the void flag internally), then expectsENOMEMfromsceKernelMmapwith0x1090over it, over part of it included. Its author states that the tests of that pull request pass on a firmware 12.02 PS4 Pro.MapMemoryrequires a free area for fixed no-overwrite and returnsENOMEMotherwise. ItssceKernelMemoryPoolReservegoes through it.FW170TestsayssceKernelMemoryPoolReservereaches themmapsyscall too.check_fixed, whiche9c8664d43followed, lets reserved ranges through. This follows the console measurement.sceKernelMmapon a PS4. Applying it to the other calls, and to a PS5, is an inference; the debt entry says so.Not in this PR:
sceKernelMmapwith no-overwrite, the exact call the PS4 test makes, returnsEOPNOTSUPPonmainand still does.Overlap:
tools/pr_overlap.py --branchexits 2 (at9415030dfe).DirectMemory.cpp(DoMapDirectandMapAnonymous). It does not change this behaviour. The resolution is to keep its lines and move itsFixedNoOverwriteConflictcall above itsPlaceHintInReservationcall in both functions. A local merge of its current head, resolved that way on the older basef924e4f454, built, and 26 memory, APR and AMPR tests passed, its new tests included. Whichever merges second needs that rebase.DirectMemory.cpp) and #21569 (GuestMemory.cpp), which conflict withmain.git merge-treegives the same conflict hunks in this branch's files againstmainas against this branch.Tested
Fedora Linux 44, GCC 16.2.1, CMake 4.3.0, Ninja 1.13.2, Release build with
-DBUILD_TESTING=ON, onmainat9415030dfe. No title, no console and no Windows host.CheckNoOverwriteRefusesReservationinguest_memory: direct, flexible, reserve, memory pool reserve and file maps with no-overwrite at the start, middle and end of a reservation returnENOMEM; the reservation keeps its extent and uncommitted state; a fixed map without no-overwrite still replaces part of it; a range straddling the reservation and that mapping is refused; after unmapping, the same no-overwrite map succeeds. The file-map assertions pass onmaintoo.sceKernelMemoryPoolReservewith0x90over a reservation returns0x80020016withmain's library and0x8002000con this branch.DirectMemory.cpponmainis the same on those bases as on this one):main's library (at199cb26112), the direct, flexible and reserve calls ended in the exception, and so did a no-overwrite hint withoutMAP_FIXEDon the direct and flexible calls;f924e4f454), the three calls returnENOMEMand the two hints still end in the exception.guest_memory, with the new check moved to the start of the test'smainfor the run so that older checks cannot catch them first. The new check aborts when the reservation is excluded from the conflict again, when the conflict is never reported, and when the check is removed fromDoMapDirect, fromMapAnonymousor fromDoReserveVirtual. Moving the check back afterPlaceHintInReservationin either function passes: that order only matters for the no-overwrite hint, which throws and which no test pins. These ran before one assertion on the pool call's output pointer was removed from the check.guest_memorypassed 30 runs in a row.tools/select_tests.pyselects 6131 of 7011 tests: 6042 passed, 68 skipped themselves and 21 failed.main'sDirectMemory.cppbuilt in:ngs2_core_routingand 19 socket tests (guest_net_*,guest_sce_net_*,guest_curl_sockets,guest_socket_address_length,guest_kernel_sockname_truncation_bounds). IPv6 is disabled on this machine, the likely cause of the socket failures; I did not trace each one.guest_kernel_sys_paths_readlinkat_limits_patchedfailed once in the parallel run, at a symlink read check (GuestKernelSysPaths.cppline 234). It passed withmain's file built in, 200 times in a row on this branch, and in 100 rounds of theguest_kernel_sys_pathstests. The test calls none of the changed functions; I did not find the cause.ctest -R '^(guest_memory|guest_memory_lifetime|guest_memory_pool_stats|guest_flexible_memory_.*|guest_system_flexible_memory|guest_ampr.*|guest_apr.*|patched_self_imports)$': 28 of 28 pass.x86_64-w64-mingw32-g++16.2.1 (Fedora MinGW)-fsyntax-onlywith-D_UCRT -D__MSVCRT_VERSION__=0xE00passes forDirectMemory.cppandGuestMemory.cpp(the latter with placeholder module-path macros). Nothing ran on Windows.python3 tools/check_conventions.py --base origin/mainandpython3 tools/debt_fold.py --checkpass.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T12:35:46Z.
Review: APPROVED
Reviewed — looks good
The reviewed changes at head
3341ee9846d0a3625ee31cd4a0e08b5c92f70245returnENOMEMfor fixed no-overwrite conflicts with registered reservations; no blocking defect was found in the changed code read.What I ran
Read the prepared description, commit list, manifest, diff, and all changed lines in the three changed files. Read targeted source context in
DirectMemory.cppandGuestMemory.cppusingrepo_read.py. No build or tests were run in this review; test results in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests were run during this review. The review-folder
files.jsonwas unavailable;manifest.jsonlists three changed files, all included, and each changed line was read. The PR description notes that PS5 behavior is unmeasured; that claim was not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T20:50:35Z.
Review: APPROVED
Reviewed — looks good
Nothing in the changed paths I inspected shows a verified blocking defect; the behavior beyond the described PS4
sceKernelMmapcase remains partly unmeasured.What I ran
a4d3850e87318fe675d00294f9e838f57efb68b5using the prepared diff and pinned reader. No build or tests were run in this review.Results
Findings
Blocking
None verified.
Non-blocking
sceKernelMmapis described as measured on console. Behavior for the other APIs and on PS5 remains an inference, as the debt note states.Not verified
description.md,commits.md,manifest.json,diff.patch, the three changed files, and targeted ranges inDirectMemory.cppandGuestMemory.cpp. All three changed files listed in the manifest were read.files.jsonwas not available through the reader, so excluded-file status is not verified. The manifest lists all three changed files as included.To get this to a good state
Nothing is required. Consider measuring the changed APIs on PS5 to confirm the documented inference.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T10:15:48Z.
Review: COMMENTED
I ran guest_memory and guest_mmap_fixed_anonymous on Linux with this head. The added reservation cases cover direct, flexible, file and memory-pool paths, and check that the reservation remains intact when the map returns ENOMEM.
AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.