fix(libkernel_sys): reject parent-directory components in symlink targets #6200
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6200"
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 valenciana-nc on 2026-10-15T02:37:39Z.
What
symlink_nid_postfixincore/libs/prx/libkernel_sys/Export.cpprejected absolute symlink targets, but it stored relative targets verbatim without checking for..components. The guest path resolver (ResolveHostPathincore/libs/prx/libc/src/General.cpp) accepts a symlink component as-is, and the host OS follows it when the link is later opened. So two calls escape the guest sandbox:The fix rejects any
..component in the target. This is deliberately conservative:a/../bis also rejected even when it would stay inside the root.Per maintainer review, the absolute-target check now rejects any target with a root name or root directory (
has_root_name() || has_root_directory()) instead of only a leading/. Windows targets such asC:/or\\server\shareare therefore rejected too. Guest tests (CheckSymlinkTargetRestrictionsincore/libs/tests/GuestKernelSys.cpp) cover:..,../x,a/../b,a/../../xand/abs, plusC:/and a UNC path on Windows.sub/dir,a..band..., created as real links. The test reads each target back throughreadlink_nid_postfixand removes the link.The test now uses
readlinkbecause MinGW'sstd::filesystem::symlink_statusdoes not report symlinks, so the earlieris_symlinkchecks failed on Windows. Left in place, the accepted links also made the test's finalstd::filesystem::remove_allthrow on Windows.Tested
Each build is this branch merged onto
maina373e85e5, Release,BUILD_TESTING=ON.guest_*tests registered undercore/libs: all pass, the same asmain.guest_video_out_wqhd_detection_no_vulkanis skipped on both.guest_kernel_sysruns the accepted-link cases.Export.cppfrommain,guest_kernel_sysfails at the..rejection check.guest_*tests pass, includingguest_kernel_sys. The two failures,guest_system_load_exec_standard_errorandguest_named_shm_concurrency, fail onmainin the same container too; it runs as root.Export.cppfrommain,guest_kernel_sysfails at the..rejection check.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 github-actions[bot] on 2026-10-15T02:37:58Z.
Thank you for your contribution! Authors with no pull requests merged into
maincan have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T23:27:08Z.
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.
core/libs/prx/libkernel_sys/Export.cppcore/libs/tests/GuestKernelSys.cppcore/libs/tests/GuestKernelSys.cppcore/libs/prx/libkernel_sys/Export.cppcore/libs/prx/libkernel_sys/Export.cppcore/libs/tests/GuestKernelSys.cppcore/libs/prx/libkernel_sys/Export.cppImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T23:57:55Z.
Thanks for finding this. The escape is real on current
main:ResolveHostPathlets the host follow a relative symlink out of the guest root, and this PR closes the..route. The PR merges cleanly into currentmain, and the changedExport.cppcompiles there. Two things before it can go in:1. Windows root names still get through. On Windows, a target such as
C:/Users,C:\Windowsor\\server\sharehas a root name, sostd::filesystem::pathtreats it as absolute. It doesn't start with/and has no..component, so it passes both the existing check and the new one, andCreateSymbolicLinkWgets an absolute host target. That is the same escape:(I haven't run this on Windows; it follows from how
std::filesystemparses root names. On Linux,C:/xis just a relative name inside the root, so only Windows is affected.)Rejecting any target with a root name or a root directory covers
/,C:,C:/and UNC paths in one place, for example:That can replace the existing
*target == '/'check.2. Please add a test. The PR has no test yet. A guest test that calls
symlink_nid_postfixshould cover:..,../x,a/../b,a/../../x,/abs, and under_WIN32alsoC:/and\\server\sharesub/dir,a..b,...Registering it in the existing libkernel_sys tests is fine. The test must fail on current
mainfor the..cases.Keeping the conservative behaviour (rejecting
a/../beven when it would stay inside the root) is fine.Imported from boykopovar/AnyPS5. Originally posted by valenciana-nc on 2026-10-18T21:22:18Z.
Both points addressed in
84d77798c:The absolute-target check is now your suggested
has_root_name() || has_root_directory()form, replacing the leading-/check, soC:/,\\server\shareand other root-named targets are rejected too. The latercontentsdeclaration was folded into it. Conservative..rejection (includinga/../b) kept.Added
CheckSymlinkTargetRestrictionstocore/libs/tests/GuestKernelSys.cpp: rejects..,../x,a/../b,a/../../x,/abs(plusC:/and UNC paths under_WIN32); accepts and creates real links forsub/dir,a..b,.... Verified the test aborts on unpatchedmainat the..check and that the fullguest_kernel_sys_testssuite passes with the fix on Linux.check_conventions.pypasses. (Built outside CMake since submodules are uninitialized here — details in the PR body.)This change was written with AI assistance, as disclosed in the PR body.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T01:22:05Z.
Thanks for the update. The checks themselves work on Windows: in our full CI the
C:/and UNC cases pass. The new test still fails on Windows, but for a test-only reason:(at the merge with current main). Line 111 is
Require(std::filesystem::is_symlink(std::filesystem::symlink_status(nested)));inCheckSymlinkTargetRestrictions. The Windows CI build uses MinGW GCC with libstdc++, and libstdc++'sstd::filesystemdoesn't recognise symlinks on Windows:symlink_statusreports the link as a plain file or directory, andcreate_symlinkfails. That's why the existing Windows block in this test checksFILE_ATTRIBUTE_REPARSE_POINTandreadlink_nid_postfix, and only usesis_symlinkunder#else. Here,symlink_nid_postfixreally does create the link (it returns 0), and only the check fails.Suggested fix: check what was stored through
readlink, which works on both platforms and also tests the target text, e.g.and the same for
a..b(4 bytes) and...(3 bytes) in place of the threeis_symlinkchecks.Imported from boykopovar/AnyPS5. Originally posted by valenciana-nc on 2026-10-19T01:37:04Z.
I ran the test in the CMake builds on Windows and Linux; before, it had only been built outside CMake on Linux.
On Windows the accepted-target cases failed, because MinGW's
std::filesystem::symlink_statusdoes not report symlinks.1a200a1e1fixes the test:readlink_nid_postfix.remove_allthrow on Windows.Both platforms pass now. With
Export.cppfrommain, the test fails at the..check on both.