Skip to content

fix(libkernel): check high-resolution timer input buffers - #18817

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
THEMANnt:fix/libkernel-equeue-hrtimer-input
Nov 13, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
THEMANnt:fix/libkernel-equeue-hrtimer-input

Conversation

@THEMANnt

Copy link
Copy Markdown
Contributor

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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@JJenkx

JJenkx commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 0e968442bd, merged onto main c65eb46214 (1fbf7ff662, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_equeue_events passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 0e968442bd:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_equeue_event_tests built 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.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4571: guest_equeue_events ..............***Exception: SegFault  0.69 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • 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

@github-actions

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 7492 core/libs/prx/libkernel/Equeue/Equeue.cpp
core/libs/tests/GuestEqueueEvents.cpp
PR 9293 core/libs/prx/libkernel/Equeue/Equeue.cpp
PR 9297 core/libs/prx/libkernel/Equeue/Equeue.cpp
PR 9302 core/libs/prx/libkernel/Equeue/Equeue.cpp

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.json and diff.patch for PR #18817 at head 0e968442bd4d8f205d86d02d77fe7bef84ad8410.
  • 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_patch at 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

Not verified

  • Build and the guest_equeue_events run 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 CopyGuestBytes on the Windows host for an unmapped address. I read only the wrapper.
  • Full text of Equeue.cpp (990 lines) and GuestEqueueEvents.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.

@oneandonlydean
oneandonlydean merged commit fcfb95c into boykopovar:main Nov 13, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants