fix(libkernel): copy timespec outputs safely in clock_gettime and clock_getres #24641
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24641"
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 Sheikh-Bilal65 on 2026-11-20T21:45:09Z.
What
Drop
Stdio.cpp(sceKernelFutimeslanded inmain), and keep checkedKernelTimespecoutput copying incore/libs/prx/libkernel/Time/Time.cpp(clock_gettime_nid_postfixandclock_getres_nid_postfix) viaGuestCopyOut_nid_no_patch, preservingerrnoand returning-1withGUEST_EFAULTon unwritable output pointers. Updatedocs/dev/debt/changes/libkernel-guest-pointers.mdto referenceTime.cpp, and extendcore/libs/tests/GuestKernelClock.cppto cover unwritable output pointers (0x10, read-only memory, guard pages) andclock_getresinvalid clock IDs.Tested
python tools/debt_fold.py --checkpassed on Windows 11.python tools/guest_pointer_audit.py libkernelreported 0 findings inTime.cpp.python -u tools/check_conventions.py --base upstream/mainpassed (All conventions checks passed.).g++ -std=c++23 -Wall -Wextra -fsyntax-onlypassed oncore/libs/prx/libkernel/Time/Time.cppandcore/libs/tests/GuestKernelClock.cpp(only 2 pre-existing-Wunused-parameterwarnings inTime.cpp).ctestexecution deferred to CI (no CMake/Ninja toolchain installed locally).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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T01:00:57Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge:
sceKernelFutimesmust preserve the caller pointer when checking the result ofCopyInTimes.What I ran
Reviewed head
69f82d62b06c06ef13241a353131238f99bb7ef1usingrepo_read.pyfor targeted source reads. No tests or builds were run. The author reports convention checks and unit tests on Windows 11; I did not independently verify them.Results
Findings
Blocking
core/libs/prx/libkernel/File/src/Stdio.cpp:2202:CopyInTimestakes its pointer argument by reference and, on success with non-null input, rebinds it tolocal. BecausesceKernelFutimespasses itstimesparameter directly, the pointer is then always non-null, even when the original argument was null. Consequently the subsequentif (times != nullptr)validation readslocal[0]andlocal[1]uninitialized for a null input, and the native call at line 2211 receives those uninitialized values instead ofnullptr. Preserve the original nullness separately, or perform the copy through a separate pointer variable.Non-blocking
None.
Not verified
core/libs/tests/GuestKernelClock.cppwas excluded by the review bundle rule; its contents were not read.review/manifest.json, and all three full texts were available. I read the changed portions ofStdio.cppandTime.cpp, helper context inStdio.cpp, and the complete five-line debt note. Other portions of those source files were not read.To get this to a good state
times == nullptrstate intact while copying, then validate and callNativeFutimeswithlocalonly when the original argument was non-null.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T01:18:57Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
69f82d62b0:tools/check_conventions.pypassed.guest_kernel_clock_testsbuilt cleanly.guest_kernel_clock):core/libs/prx/libkernel/File/src/Stdio.cpp,core/libs/prx/libkernel/Time/Time.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T11:31:28Z.
Review: COMMENTED
Reviewed — no blocking findings
The reviewed changes safely copy guest time structures before host operations; I did not run the author-reported checks, so a formal approval is not justified.
What I ran
Reviewed head
30b5fc5bd89f4215ef9ce61a0228f0fe801f11cbusingrepo_read.pyto inspect the prepared diff, changed-file inventory, affected functions, and guest-memory copy implementation. No tests or builds were run.Results
Findings
Blocking
None.
Non-blocking
docs/dev/debt/changes/libkernel-guest-pointers.md:5links toTime.cppforsceKernelFutimes, but that function is inFile/src/Stdio.cpp. Update the link to point to the file containing that function.Not verified
core/libs/tests/GuestKernelClock.cppwas excluded by the review preparation rule and was not read.To get this to a good state
Nothing is required. Optional: correct the
sceKernelFutimesdocumentation link.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T12:44:58Z.
Review: COMMENTED
Reviewed — comments
The changed code has no verified blocking defect, but I did not run the reported Windows checks.
What I ran
Reviewed head
da527326d5239d0b75e95c6bef9ae0ea9c0fccb5usingrepo_read.pyreader calls. No tests or build commands were run. The author reports convention checks and unit tests on Windows 11; I did not independently verify them.Results
Negative control
Not run; no test command was run.
Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed changed lines in
core/libs/prx/libkernel/File/src/Stdio.cppandcore/libs/prx/libkernel/Time/Time.cpp, plusdocs/dev/debt/changes/libkernel-guest-pointers.md. Also inspected theGuestCopyOut_nid_no_patchimplementation incore/libs/prx/libc/src/General.cppfor context.Not verified
The Windows 11 convention checks and unit tests reported by the author were not run here.
core/libs/tests/GuestKernelClock.cppwas excluded by rule, as stated in the review description.To get this to a good state
Nothing is required. Optional: provide the Windows 11 check output for independent review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T14:18:15Z.
Review: COMMENTED
Built the changed file and clock units with the branch's
GuestKernelClockfixture against the existing Linux runtime. The focused fixture passed. I traced the change through the checked copy of both timeval elements before conversion and the host file-time operation.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-04T14:24:34Z.
Review: COMMENTED
Actionable comments
8a36961e-0841-4a08-ae0e-1f3208154d77Reviewing files that changed from the base of the PR and between
2c878a2d00andd6c8a50b0c.core/libs/prx/libkernel/Time/Time.cppcore/libs/tests/GuestKernelClock.cppdocs/dev/debt/changes/libkernel-guest-pointers.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T14:39:00Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
d6c8a50b0cb1a040dd1d411433f6778d72f56042against basemain; no merged-preview check was run. I inspected the prepared review files and targeted source usingrepo_read.pyin the review shell. No build or test was run.Results
Negative control
Could not run a negative control because no tests were run.
Findings
Blocking
None.
Non-blocking
timevalstructures insceKernelFutimes, while the diff changestimespecoutputs forclock_gettimeandclock_getres. Please update the title and description to match the change. The changed code and debt note identify the clock functions andtimespecoutputs (Time.cpp line 730, debt note line 5).Sources
Not verified
core/libs/tests/GuestKernelClock.cppwas excluded by the prepared review rules, so its test coverage was not inspected. The description's report of Windows 11 checks was not independently verified.core/libs/prx/libkernel/Time/Time.cpp(targeted ranges) anddocs/dev/debt/changes/libkernel-guest-pointers.md(all lines). Both files listed underreviewedinfiles.jsonwere read. The excluded test file was not read.To get this to a good state
Nothing is required. Please consider correcting the PR title and description to reflect the clock output change.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-04T15:21:04Z.
Review: COMMENTED
Actionable comments
95d1bd10-f107-4499-86ed-9f2952c5b9daReviewing files that changed from the base of the PR and between
d6c8a50b0cand91d7f46e35.core/libs/tests/GuestKernelClock.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T15:41:57Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected implementation checks both timespec output writes and maps failures to
EFAULT; the supplied diff excludes the test file described by the author, so I cannot complete a formal approval.What I ran
Reviewed head
91d7f46e3524ad2c13f2b053c336458d7e033746. Read the prepared description, commit list, manifest, diff, and file exclusions. Usedrepo_read.pyto inspect the changed implementation and relevant copy-out and wrapper context. No tests or build commands were run.Read changed lines in
core/libs/prx/libkernel/Time/Time.cppand all ofdocs/dev/debt/changes/libkernel-guest-pointers.md. Also read targeted context inGeneral.cpp,GuestArena.hpp,Time.cpp, andGuestKernelClock.cpp. The supplied diff excludescore/libs/tests/GuestKernelClock.cpp.Results
Negative control
Not run; no tests were executed.
Findings
Blocking
None.
Non-blocking
None in the inspected implementation and documentation.
Sources
Time.cppat the reviewed commitGuestCopyOut_nid_no_patchimplementation at the reviewed commitNot verified
The test file’s changes and runtime behavior are not verified: its full text at the head was inspected for context, but its diff was excluded from the supplied review materials. No tests were run. The author-reported checks were not independently run.
To get this to a good state
Nothing is required. To complete review of the described test coverage, include the test file’s diff in the review materials.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.