Repository navigation
fix(libkernel): return 0 from sceKernelMprotect and sceKernelMtypeprotect for a zero length - #7033
Conversation
…tect for a zero length mprotect already returns 0 for a zero length. The sceKernel entry points passed it to DoMprotect, which throws for an empty range. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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.
|
|
Windows run in #7023 (comment): guest_mprotect_unmapped 3/3. A small note: FreeBSD's sys_mprotect aligns addr down and rounds len + pageoff up, so a zero length at an unaligned address covers that page there. This PR (like main's mprotect) returns 0 for any zero length. It doesn't block. Written with Claude Code assistance (validation by a subagent, reviewed in this session). |
|
Right, thanks @screamm. FreeBSD's AI-assisted: yes (Claude Code) |
fogydes
left a comment
There was a problem hiding this comment.
Native Windows x86-64 build and verification on exact head cbf006cb4b1ce82d6f0d065fc607bac0205fe00d applied on main 6a32550fd1.
Environment: Windows 11 (build 26300), 13th Gen Intel Core i7-13700HX, MinGW GCC 15.2.0, Ninja Release, BUILD_TESTING=ON.
guest_mprotect_unmappedpasses cleanly:ctest -R "^guest_mprotect_unmapped$" --repeat until-fail:20(20/20 runs passed).- Negative test verification: Reverting
core/libs/prx/libkernel/DirectMemory/Export.cpptomain's implementation reproduces the abort on Windows as expected:With this PR applied, empty range protections forsceKernelMprotect threw: Invalid guest memory protection range FATAL: abort() (SIGABRT)sceKernelMprotectandsceKernelMtypeprotectsucceed without modifying page permissions. python tools/check_conventions.py --base origin/main: passed with 0 findings.python tools/pr_overlap.py --branch pr-7033-review: 0 confirmed collisions.
Written with AI assistance (Claude Code). I ran the builds and tests above locally on my Windows machine.
|
Thanks @fogydes, the 20-of-20 run and the negative control on Windows are added to the description. AI-assisted: yes (Claude Code) |
What
mprotectreturns 0 for a zero length without looking at the address.sceKernelMprotectandsceKernelMtypeprotectpassed a zero length on toDoMprotect, which throwsstd::invalid_argument(Invalid guest memory protection range) for an empty range. Both now return 0 for a zero length, asmprotectdoes, and change nothing.On FreeBSD 11,
sys_mprotectrounds the range to pages and passes it tovm_map_protect, which returns success for an empty range. So a zero length at a page-aligned address succeeds whether or not anything is mapped there. Not checked on a console.I don't know of a title that hits this. I found it while going through the throw sites in libkernel.
Tested
Ubuntu 24.04, GCC 13.3, Release, on
main6a32550.guest_mprotect_unmapped: new checks that a zero length succeeds and changes nothing, on a mapped page, on an unmapped page and at address 0, forsceKernelMprotect,sceKernelMtypeprotectandmprotect. Withmain'sExport.cppthe test aborts on the first of these (sceKernelMprotect threw: Invalid guest memory protection range). With this change it passes 3 of 3.ctest -R '^guest_|libc': 401 of 401 pass, with this and one other small libkernel fix applied together.tools/check_conventions.pypasses.tools/pr_overlap.pyfinds no conflicting lines. It couldn't compare against feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021, test: organize library tests and label CTest suites #6044 and Macos m4 #6222, which conflict withmain. None of their diffs touchessceKernelMprotectorsceKernelMtypeprotect. fix(libkernel): keep a protected host stack's guard page, and protect the Linux main stack #6443 changesDoMprotectitself, which this PR leaves alone.main's behaviour. (series run by @screamm)main6a32550:guest_mprotect_unmappedpasses 20 of 20, and withmain'sExport.cppit aborts onInvalid guest memory protection range(review by @fogydes).Not checked: macOS, a console.
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)🤖 Generated with Claude Code