Repository navigation
fix(libkernel): check high-resolution timer input buffers - #18817
Conversation
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 0e968442bd:
- Conventions:
tools/check_conventions.pypassed;git diff --checkclean. - Build:
guest_equeue_event_testsbuilt cleanly. - CTest (
guest_equeue_events):1/1 Test #4571: guest_equeue_events .............. Passed 0.46 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libkernel/Equeue/Equeue.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #4571: guest_equeue_events ..............***Exception: SegFault 0.69 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- core/libs/prx/libkernel/Equeue/Equeue.cpp: verified sceKernelAddHRTimerEvent copies guest memory into local KernelTimespec delay using GuestCopyIn_nid_no_patch before dereferencing, returning SCE_KERNEL_ERROR_EFAULT on null or unmapped pointers.
- core/libs/prx/libkernel/Equeue/Equeue.cpp: verified field validation (delay.tv_sec < 0, delay.tv_nsec < 0, delay.tv_nsec >= 1000000000LL) operates strictly on the local stack snapshot, preventing TOCTOU mutations and returning SCE_KERNEL_ERROR_EINVAL.
- core/libs/prx/libkernel/Equeue/Equeue.cpp: confirmed delayNs and monotonic deadline computation with overflow saturation preserve EVFILT_HRTIMER semantics (EV_ADD | EV_ONESHOT) and forward correctly to EqueueAddEvent_nid_postfix.
- core/libs/tests/GuestEqueueEvents.cpp: verified VerifyPeriodicTimer exercises sceKernelAddHRTimerEvent with an invalid pointer (reinterpret_cast<const KernelTimespec*>(1)), asserting SCE_KERNEL_ERROR_EFAULT.
- core/libs/tests/GuestEqueueEvents.cpp: confirmed the test verifies that failed event addition leaves the queue clean (sceKernelWaitEqueue returns SCE_KERNEL_ERROR_ETIMEDOUT) and that subsequent valid high-resolution timer events trigger normally with EVFILT_HRTIMER.
- Repository rules & conventions: verified compliance with AGENTS.md, confirming zero added code comments, Conventional Commits title formatting, and LP64/LLP64 portability across Linux and Windows targets.
- Note: the AI-assisted checkbox can stay.
Looks Good To Me
|
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.
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed the high-resolution timer input check — no blocking findings
The change copies the timer duration into a local snapshot before validation, so an unreadable duration returns EFAULT without queuing an event, as the description says. Head is 0e968442bd4d8f205d86d02d77fe7bef84ad8410.
What I ran
- Read
description.md,commits.md,manifest.json,files.jsonanddiff.patchfor PR #18817 at head0e968442bd4d8f205d86d02d77fe7bef84ad8410. - Read the house rules sections "Readable reviews", "Accuracy and evidence" and "Standard PR response format" from the ruling file.
- Read the head text of
sceKernelAddHRTimerEvent(Equeue.cpp lines 798–840) and the periodic timer test (GuestEqueueEvents.cpp lines 60–100) with the reader. - Read
GuestCopyIn_nid_no_patchat head (libc/src/General.cpp lines 870–875) to check how it handles a null or unmapped source. - No build and no test run in this review. The reviewer does not build.
Results
| Check | Result | Note |
|---|---|---|
| Diff read | passed | 2 files, changed hunks only |
| Null and unmapped source handling | passed | GuestCopyIn_nid_no_patch returns false for a null source |
| Build and tests | not run | Author reports three passing runs on Windows x64 |
Commands and reader output
python3 repo_read.py search GuestCopyIn_nid_no_patch
python3 repo_read.py cat core/libs/prx/libkernel/Equeue/Equeue.cpp 798 840
python3 repo_read.py cat core/libs/tests/GuestEqueueEvents.cpp 60 100
python3 repo_read.py cat core/libs/prx/libc/src/General.cpp 850 890
General.cpp:871–874 at head:
if (bytes == 0) return true;
const auto start = reinterpret_cast<std::uintptr_t>(source);
if (start == 0 || bytes > UINTPTR_MAX - start) return false;
return CopyGuestBytes(destination, source, bytes);
Findings
Blocking
None.
Non-blocking
None.
Sources
- Equeue.cpp,
sceKernelAddHRTimerEvent - General.cpp,
GuestCopyIn_nid_no_patch - GuestEqueueEvents.cpp, new regression
Not verified
- Build and the
guest_equeue_eventsrun on Windows x64 with WinLibs GCC 15.2. These are author-reported only. - The regression test failing before the fix. Before the fix, address 1 would be dereferenced, so the test would likely crash rather than fail cleanly. I did not run it.
- Behaviour of
CopyGuestByteson the Windows host for an unmapped address. I read only the wrapper. - Full text of
Equeue.cpp(990 lines) andGuestEqueueEvents.cpp(523 lines). I read the changed hunks and nearby ranges only. - The same-file claims for #7492, #9293, #9297 and #9302 in the description.
To get this to a good state
Nothing blocking. If the head changes, re-run guest_equeue_events on the new head.
Files
- Read (partly):
core/libs/prx/libkernel/Equeue/Equeue.cpp(changed hunks and lines 798–840),core/libs/tests/GuestEqueueEvents.cpp(changed hunk and lines 60–100). - Reviewed in
files.json: both files above. None excluded.
What
Copy the timer duration into a checked local snapshot before validating the fields or registering the event. An unreadable duration returns EFAULT.
Tested
Windows x64, WinLibs GCC 15.2, Release. guest_equeue_events passed three consecutive runs. The new regression checks an unmapped duration, verifies it queues no event, and then receives a valid high-resolution timer event. The same-file hunks in #7492, #9293, #9297 and #9302 cover queue wakeups or descriptor event notifications.
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)