fix(libkernel_sys): validate guest destination buffer in readlink and readlinkat #13286
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13286"
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 Kikoarl on 2026-10-30T11:49:00Z.
What
In
CopyLinkTarget(core/libs/prx/libkernel_sys/Export.cpp),readlinkandreadlinkatpreviously only checked ifbuffer == nullptrbefore copying target link characters viastd::memcpy(buffer, target.data(), count).If a guest program passed an invalid or unmapped destination pointer (e.g. out of bounds address) with non-zero count, the unchecked
std::memcpycaused a host process segmentation fault instead of returningEFAULT(14).This PR:
bufferusingGuestCopyOut_nid_no_patch(buffer, target.data(), count).Fail(GuestEfault)(14) if the destination memory is unmapped or protected against writes.docs/dev/debt/libkernel_sys.md.core/libs/tests/GuestKernelSys.cppasserting thatreadlink_nid_postfixandreadlinkat_nid_postfixreturn-1witherrno == 14when provided an unmapped buffer address (0x800000000000).Tested
guest_kernel_sys): passed 100%.ctest --test-dir /tmp/anyps5_build -R "^guest_kernel_sys$" --output-on-failure.python3 tools/check_conventions.pypassed with 0 errors.Checklist
python3 tools/check_conventions.pyImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T11:51:09Z.
Review: APPROVED
Reviewed — looks good
The change routes non-empty
readlinkandreadlinkatresults through the existing checked guest-memory copy helper and adds invalid-destination regressions at head257b6ee53bc423cd5ace35f8393e892d9ba76ab2.What I ran
Reviewed the exact head above against PR base
8e68a7d7b9f6aeedb0ca03eee115571640555988; the local merge preview against currentmain99f7b51d2b49daa8f07fc822c51252ea704a46f0was clean. Environment: Debian 12 x86-64, Python 3.11.2, Git 2.39.5. I did not compile or run C++ tests.Results
git diff --checkproduced no output.guest_kernel_sysCTestctest --test-dir /tmp/anyps5_build -R "^guest_kernel_sys$" --output-on-failure; I did not run it.Unedited local command output
Findings
Blocking
None found in the reviewed diff.
Non-blocking
The focused C++ test result is author-reported, and hosted checks were still pending at recheck. I verified by source inspection that
GuestCopyOut_nid_no_patchchecks destination accessibility before copying and that the new regression cases exercise invalid buffers through both APIs.Sources
CopyLinkTargetand readlink paths at the reviewed head.readlinkandreadlinkatinvalid-buffer assertions.Not verified
I did not build or run the C++ test locally, test on a console, or observe the pending hosted CI completion. The precheck could not run its ABI and test-quality helper scripts because those scripts are not present in its isolated checkout.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T23:31:42Z.
Review: COMMENTED
Linux run (the thread has a Windows run from maskym; the Tested section doesn't name the OS).
Machine: i7-8700, Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON, Ninja. Head257b6ee53bmerged (--no-commit) ontomain2a1ae91175.guest_kernel_sys^guest_kernel_sys(26 tests)public_headerslibkernel_sys/Export.cppreverted tomain, test keptguest_kernel_syssegfaults 3/3On Linux
GuestCopyOutgoes throughprocess_vm_writev, so this is the path the Windows run doesn't exercise; the three new unmapped-buffer cases returnEFAULTand the successful reads after them still return the 14-byte target.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.