Repository navigation
fix(libkernel): copy virtual range names through a checked guest copy - #21565
Merged
oneandonlydean merged 1 commit intoNov 16, 2026
Merged
oneandonlydean merged 1 commit into
oneandonlydean merged 1 commit into
Conversation
sceKernelSetVirtualRangeName and the named-mapping calls read the name in place with strnlen, so an unreadable name crashed the host. The name is now copied through CopyGuestString_nid_no_patch, page by page and stopping at the terminator. An unreadable name returns EFAULT from sceKernelSetVirtualRangeName, as a null one does, leaves a named mapping unnamed, and throws in sceKernelMapNamedSystemFlexibleMemory, as a null name does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PrivacyOnion
approved these changes
Nov 16, 2026
PrivacyOnion
left a comment
Contributor
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against eb715598d7:
- Conventions:
tools/check_conventions.pypassed;git diff --checkclean. - Build:
guest_memory_testsbuilt cleanly. - CTest (
guest_memory,guest_mmap_fixed_anonymous,guest_mmap_executable):1/3 Test #5367: guest_mmap_executable ............ Passed 0.01 sec 2/3 Test #5366: guest_mmap_fixed_anonymous ....... Passed 0.01 sec 3/3 Test #5365: guest_memory ..................... Passed 1.74 sec 100% tests passed, 0 tests failed out of 3 - Negative control: with
core/libs/prx/libkernel/DirectMemory/Export.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/3 Test #5367: guest_mmap_executable ............ Passed 0.01 sec 2/3 Test #5366: guest_mmap_fixed_anonymous ....... Passed 0.01 sec 3/3 Test #5365: guest_memory .....................***Exception: SegFault 0.14 sec 67% tests passed, 1 tests failed out of 3 - Code reading:
- Verified
CopyRangeNameandCopyMappedNameincore/libs/prx/libkernel/DirectMemory/Export.cppsave and restoreerrnoaroundCopyGuestString_nid_no_patchandGuestCopyIn_nid_no_patch. - Verified
sceKernelSetVirtualRangeNamechecksnamefornullptr(SCE_KERNEL_ERROR_EFAULT), mapsENAMETOOLONG(63) for strings of 32 bytes or more toSCE_KERNEL_ERROR_ENAMETOOLONGand unreadable memory toSCE_KERNEL_ERROR_EFAULTbefore modifying range names. - Verified
CopyMappedNamehandles strings up to 30 bytes viaCopyRangeName(name, 31, copy)and truncates strings of 31+ bytes viaGuestCopyIn_nid_no_patch(bytes, name, 31), leaving the mapped range unnamed on unreadable memory inNameMappedRange. - Verified
sceKernelMapNamedSystemFlexibleMemoryvalidateslen, checksname == nullptr, and throwsstd::runtime_erroronerror == 63(32+ bytes) orerror != 0(unreadable name) prior to mapping. - Verified thread safety of
NameVirtualRangelockingg_rangeNameLockacrossEraseRangeNamesandg_rangeNames.emplaceafter guest string copy completes. - Verified unit tests in
core/libs/tests/GuestMemory.cppcover unreadable pointer0x10,errnopreservation, page boundary NUL-terminated and unterminated strings withsceKernelMprotect, and truncation/unreadable names insceKernelMapNamedFlexibleMemory.
- Verified
Looks Good To Me
12 tasks done
|
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.
|
12 tasks done
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
Four exports read a guest name in place with
strnlen:sceKernelSetVirtualRangeName, which checks the length;NameVirtualRange, which copies up to 31 bytes forsceKernelMapNamedFlexibleMemory,sceKernelMapNamedFlexibleMemoryInternalandsceKernelMapNamedDirectMemory;sceKernelMapNamedSystemFlexibleMemory, which checks the length.So an unreadable name crashed the host.
The name is now copied with
CopyGuestString_nid_no_patch. It reads page by page, stops at the terminator and never reads past the length limit, so a short name that ends right before an unreadable page still works.errnois kept. What happens with an unreadable name:sceKernelSetVirtualRangeNamereturnsEFAULT(0x8002000e), as it already does for a null name, and keeps the earlier name.sceKernelMapNamedSystemFlexibleMemorythrows before mapping, as it does for a null name. That case is unmeasured.What stays the same:
ENAMETOOLONGfor 32 bytes or more insceKernelSetVirtualRangeName, the throw in the system call, and the named-mapping calls still cut a longer name to 31 bytes.The two libkernel debt entries now say how an unreadable name is handled.
Overlap: three open PRs change the same lines and will conflict textually with this one, though none of them copies the name. Whichever merges second needs a rebase.
sceKernelMapNamedDirectMemoryandsceKernelMapNamedSystemFlexibleMemoryhandle long and empty names, from PS5 measurements.sceKernelSetVirtualRangeName.If #16945 or #17718 lands first, the copy here moves into their name checks unchanged.
Tested
Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release,
-DBUILD_TESTING=ON:guest_memorygains these cases:sceKernelSetVirtualRangeNamewith an unmapped (0x10) name returnsEFAULT, keepserrnoat 71, and the earlier name stays.PROT_NONE(sceKernelMprotect):"edge"with its terminator on the last readable byte is set."xxx"without a terminator before the boundary returnsEFAULT.sceKernelMapNamedFlexibleMemorywith an unmapped name maps, and the range is unnamed.guest_memory,guest_system_flexible_memoryandguest_virtual_query_argumentspass, 3 runs of 3.main'sExport.cppand the new cases,guest_memoryends infatal SIGSEGV (code 1) at address 0x0000000000000010.tools/check_conventions.pypasses on the branch and this body. The fragment folds;tools/debt_fold.py --checkfails only onmain's owndocs-nkwebkit-drop-readded-count-lines.md, which docs(libSceNKWebKit): drop the unmatched 5933 count removal from the debt fragment #21458, docs(libSceNKWebKit): drop the count-line remove main already applied #21512 and docs(libSceNKWebKit): remove obsolete inventory-count selector #21531 fix.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)