Skip to content

fix(libkernel): return EFAULT for a null virtual range name - #12986

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
Oscar45397:test/libkernel-virtual-range-name
Oct 30, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
Oscar45397:test/libkernel-virtual-range-name

Conversation

@Oscar45397

@Oscar45397 Oscar45397 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What

sceKernelSetVirtualRangeName with a null name returned SCE_KERNEL_ERROR_EINVAL. KytyPS5 (src/kernel/memory.cpp, KernelSetVirtualRangeName) and shadPS4 (src/core/libraries/kernel/memory.cpp, sceKernelSetVirtualRangeName) both return SCE_KERNEL_ERROR_EFAULT (0x8002000e) for it, so it now does too, checked before the other arguments as in both.

  • CheckVirtualRangeNames in guest_memory, on a 16 KiB flexible mapping: a null name returns EFAULT and leaves the range unnamed; naming the range twice keeps the second name; clearing it empties the name.
  • The null-address, zero-length and past-the-end checks this PR first asserted are dropped: no console measurement or reference backs their EINVAL. They are recorded as unknown in docs/dev/debt/libkernel.md, together with the 32-byte name limit, where shadPS4 returns ENAMETOOLONG and this library cuts the name to 31 characters.

Tested

Windows 11 Home 26200, Ryzen 9 5900X, WinLibs GCC 15.2.0 r7, Release, on main 556547d.

  • ctest --test-dir build -R '^guest_memory$' --repeat until-fail:3: passes 3 of 3 runs.
  • Red control: with a null name returning EINVAL again, guest_memory fails at the null-name check (GuestMemory.cpp:201). Restored, it passes again.
  • python tools/check_conventions.py --base upstream/main: passed.

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

🤖 Generated with Claude Code

@JJenkx

JJenkx commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Windows run of this head (968028c2ba), merged onto main 58b2753d74 (clean merge, local only). Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON, no Vulkan driver visible.

  • guest_memory, guest_mmap_executable, guest_mmap_fixed_anonymous pass 3 of 3 (ctest --repeat until-fail:3), none skipped.
  • This PR changes tests only, so there is no source to revert for a negative control.

AI-assisted: yes (Claude Code).

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

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 4449 core/libs/tests/GuestMemory.cpp
PR 4630 docs/dev/debt/libkernel.md
PR 5021 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 6321 core/libs/tests/GuestMemory.cpp
PR 6936 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7105 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7135 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7192 docs/dev/debt/libkernel.md
PR 7447 docs/dev/debt/libkernel.md
PR 7464 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7631 core/libs/tests/GuestMemory.cpp
PR 7804 docs/dev/debt/libkernel.md
PR 8605 docs/dev/debt/libkernel.md
PR 9156 docs/dev/debt/libkernel.md
PR 9242 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 9843 docs/dev/debt/libkernel.md
PR 9938 docs/dev/debt/libkernel.md
PR 10025 docs/dev/debt/libkernel.md
PR 10442 docs/dev/debt/libkernel.md
PR 10552 docs/dev/debt/libkernel.md
PR 10645 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 11939 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 12925 docs/dev/debt/libkernel.md
PR 12965 docs/dev/debt/libkernel.md
PR 12970 docs/dev/debt/libkernel.md

@rooklz rooklz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 968028c (base 5dc9aa3, which is in main fd9b3f6).

  • git merge-tree against main fd9b3f6 is clean, git diff --check is clean, and tools/check_conventions.py --base upstream/main passes.
  • tools/pr_overlap.py: 5 PRs share core/libs/tests/GuestMemory.cpp (#4449, #5021, #6321, #7105, #7631). All 5 already conflict with main, so this PR adds no new merge-order problem.
  • clang++ -fsyntax-only (x86_64, macOS 15): the only error is the CMake-supplied GUEST_MEMORY_MODULE define, which was already missing before this PR. The new code has no errors.
  • Harness: I copied main's sceKernelSet/ClearVirtualRangeName, EraseRangeNames and ApplyRangeName verbatim into a standalone file with the new check body, built with clang++ -std=c++20 and ASan+UBSan. Head passes, and all 12 mutants fail the check:
    • Set accepts a null address / zero length / null name: KILLED at the matching rows.
    • Set without the overflow guard: KILLED.
    • Set returns -1 instead of EINVAL: KILLED.
    • Clear accepts a null address / zero length, or has no overflow guard: KILLED.
    • Clear does nothing: KILLED at the final empty-name row.
    • Set keeps the first name (no erase before insert): KILLED at the "second" row.
    • A refused Set (overflow or zero length) still names the range: KILLED at the empty-name row before the first successful Set.
  • Not blocking: the EINVAL contract (null address, zero length, null name, overflow) comes from the #50 model. No console measurement backs it, and #50's body doesn't cite one. If a measurement exists, citing it would help. Leaving the over-31-character name case out, as the PR does, is the right call.

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test. The pass/fail mechanics look fine, but the expected values come from our own implementation rather than a reference, and one contradicts the references:

  • core/libs/tests/GuestMemory.cpp:204: sceKernelSetVirtualRangeName(mapping, length, nullptr) == einval. Both KytyPS5 (src/kernel/memory.cpp, KernelSetVirtualRangeName) and shadPS4 (src/core/libraries/kernel/memory.cpp, sceKernelSetVirtualRangeName) return EFAULT (0x8002000e) for a null name. Either change the library and test to EFAULT, or show a measurement that the console returns EINVAL.
  • Lines 202, 203, 205-208: null address, length 0 and UINT64_MAX returning EINVAL. Neither reference validates these (shadPS4's Clear doesn't validate anything), so the test pins behaviour nothing here supports. Please cite where each comes from (console measurement, prospero-win, SDK header/doc), or drop the cases that have no source and note them as unknown in docs/dev/debt/libkernel.md.

The replace-then-clear checks (lines 210-214) are fine as they are.

Oscar45397 and others added 2 commits October 30, 2026 17:44
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KytyPS5 and shadPS4 return EFAULT for a null name. The test keeps that
and the rename and clear checks, and drops the null address, zero length
and past-the-end cases that no reference covers; the debt entry records
them as unknown, with the 32-byte name limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Oscar45397
Oscar45397 force-pushed the test/libkernel-virtual-range-name branch from 968028c to 287f43e Compare October 30, 2026 16:47
@Oscar45397 Oscar45397 changed the title test(libkernel): cover sceKernelSetVirtualRangeName argument errors fix(libkernel): return EFAULT for a null virtual range name Oct 30, 2026
@Oscar45397

Copy link
Copy Markdown
Contributor Author

@adriadam10 thanks, agreed on both points. Updated in 287f43e004 (rebased onto main 556547d):

  • A null name now returns EFAULT (0x8002000e) in the library and the test, as in KytyPS5 and shadPS4 (shadPS4 src/core/libraries/kernel/memory.cpp checks it first, before anything else).
  • The null-address, zero-length and UINT64_MAX cases are dropped from the test. They are recorded as unknown in docs/dev/debt/libkernel.md, along with the name length: shadPS4 returns ENAMETOOLONG for 32 or more bytes, where this library cuts the name to 31 characters.
  • The replace-then-clear checks are unchanged.

guest_memory passes 3 of 3; with EINVAL put back for a null name it fails at that check. Since the PR now changes the library, the title is fix(libkernel): ... and the body is updated.

AI-assisted: yes (Claude Code).

@adriadam10
adriadam10 merged commit 7ad4f3b into boykopovar:main Oct 30, 2026
12 of 13 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the null-name EFAULT against KytyPS5 and shadPS4, the test (fails without the change), and the debt entry for the cases without a source; merged.

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.

4 participants