fix(libkernel): return EFAULT from system version queries for invalid memory #13552
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13552"
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 pushkarreddyy on 2026-10-30T18:05:52Z.
What
In
core/libs/prx/libkernel/System/src/SystemConfiguration.cpp,sceKernelGetSystemSwVersion_nid_postfix,sceKernelGetSystemExVersion,sysKernelGetLowerLimitSysexVersion_nid_postfix, andsysKernelGetLowerLimitUpdVersion_nid_postfixdirectly wrote to caller-provided guest memory pointers (std::memset(version->versionString, ...),*first = '\0',*version = 0). Passing an unmapped or unwritable pointer caused an unhandled host segmentation fault (SIGSEGV) instead of returningSCE_KERNEL_ERROR_EFAULT(or14).This change validates and copies memory using
GuestCopyIn_nid_no_patchandGuestCopyOut_nid_no_patch, returningSCE_KERNEL_ERROR_EFAULT(or14) on copy failure. Also adds regression test coverage incore/libs/tests/GuestSystemConfiguration.cppand updates technical debt documentation indocs/dev/debt/libkernel.md.Fixes #13548.
Tested
Windows 11, unit test suite (
core/libs/tests/GuestSystemConfiguration.cpp) verifying that passing invalid memory pointers (reinterpret_cast<char*>(0x10),reinterpret_cast<std::uint32_t*>(0x10), andreinterpret_cast<SceKernelSystemSwVersion*>(0x10)) cleanly returnsSCE_KERNEL_ERROR_EFAULTor14.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T18:10:58Z.
Review: APPROVED
Reviewed — looks good
I found no blocking defect in the invalid-memory handling on head
6906580bc3f1856f85fe664a10ccd4fbf55ef1b1; the checked-copy paths return the expected errors, and the new cases cover each output pointer.What I ran
PR base:
4bc9e779aa7abb2109c65ee3bca19e1b85df3be8; merge preview against that currentmainwas clean. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0.The precheck's diff and conventions/template checks passed. Its temporary checkout could not find the workspace-local ABI and test-quality helpers; I reran the ABI audit directly, which passed with no findings. The test-quality heuristic warning about registration is a false positive: the CMake target registers
guest_system_configuration. The author reports the Windows unit test passed; I did not independently reproduce it.Sources
Not verified
No local build or CTest was run. At the final refresh, hosted checks were still queued.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T21:31:41Z.
Review: COMMENTED
Linux run of head
6906580bc3, merged ontomain6472c708ae(clean merge). Ubuntu 26.04, i7-8700, GCC 15.2, Release,BUILD_TESTING=ON, Ninja.guest_system_configurationaborts 3/3 on this head. The new EFAULT checks pass. The failure is the existing check right after them:errno is 14 there. On Linux,
GuestCopyIn_nid_no_patch/GuestCopyOut_nid_no_patchuseprocess_vm_readv/process_vm_writev, which leave the host errno at EFAULT on a bad address, and the guest reads the same errno. The Windows path (VirtualQuery+memcpy) doesn't touch errno, which is probably why it passes there. (Requirehere is a barestd::abort(), so I found the line by temporarily adding__LINE__to it.)Fix I verified: save and restore errno around the copies in
SystemConfiguration.cpp, through two small helpers used by the five changed call sites:(plus the same for
GuestCopyIn). With that,guest_system_configurationpasses 3/3, and so doguest_kernel_sys_sdk_versionandguest_kernel_sys_upd_version. If the console sets errno on these EFAULT returns instead, then the test should reset errno after the new checks. Either way, the two hosts should agree. Without the fix, reverting onlySystemConfiguration.cpptomainsegfaults 3/3 on the new0x10checks, so they do protect the change.public_headerspasses.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.