Fix fault counter overflow in FaultManager #869

Closed
github-bot wants to merge 1 commit from gh-pr/869/head into gh-pr/869/base
Owner

@⁠Hamadshu on GitHub · 2026-09-27 17:54 UTC · original
Hamadshu:fix-fault-manager-overflow → main · +13 −1 · 1 files · 1 commits · closed without merging

Summary

Fixes a buffer over-read in FaultManager::ProcessFaultBuffer.

The compute shader fault_buffer_process.comp stops writing fault entries
once store_index >= MAX_PAGE_FAULTS, but it keeps incrementing the counter
in download_buffer[0]. The host then reads faults[0] entries contiguously
starting at faults[1], which walks past the end of the current fault area
and into the next area's bytes.

Root cause

fault_buffer_process.comp:

const uint store_index = atomicAdd(download_buffer32[0], 1u) + 1u;
if (store_index >= MAX_PAGE_FAULTS) {
    return;  // stops writing, not incrementing
}

faultManager.cpp:

const auto count = static_cast<uint32_t>(faults[0]);
for (uint32_t index = 1; index <= count; ++index) {
    fault_ranges.Add(faults[index], ...);  // reads past MAX_PAGE_FAULTS - 1
}

Fix

Clamp the counter on the host side before reading. The shader is intentionally
left as-is because changing it would require reworking the counter to be
atomic-safe across workgroups, and the host fix is a one-line change that
covers every driver and every shader revision.

Changes

  • faultManager.cpp: clamp faults[0] to MaxPageFaults - 1 and log
    overflow at yellow level.

Testing

Built the emulator locally with this change. No counter overflow is
observed in normal runs; the clamp only fires when the shader's counter
genuinely exceeds capacity.

**@⁠Hamadshu** on GitHub · 2026-09-27 17:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/869) `Hamadshu:fix-fault-manager-overflow` → `main` · +13 −1 · 1 files · 1 commits · closed without merging ## Summary Fixes a buffer over-read in `FaultManager::ProcessFaultBuffer`. The compute shader `fault_buffer_process.comp` stops *writing* fault entries once `store_index >= MAX_PAGE_FAULTS`, but it keeps incrementing the counter in `download_buffer[0]`. The host then reads `faults[0]` entries contiguously starting at `faults[1]`, which walks past the end of the current fault area and into the next area's bytes. ## Root cause `fault_buffer_process.comp`: const uint store_index = atomicAdd(download_buffer32[0], 1u) + 1u; if (store_index >= MAX_PAGE_FAULTS) { return; // stops writing, not incrementing } `faultManager.cpp`: const auto count = static_cast<uint32_t>(faults[0]); for (uint32_t index = 1; index <= count; ++index) { fault_ranges.Add(faults[index], ...); // reads past MAX_PAGE_FAULTS - 1 } ## Fix Clamp the counter on the host side before reading. The shader is intentionally left as-is because changing it would require reworking the counter to be atomic-safe across workgroups, and the host fix is a one-line change that covers every driver and every shader revision. ## Changes - `faultManager.cpp`: clamp `faults[0]` to `MaxPageFaults - 1` and log overflow at yellow level. ## Testing Built the emulator locally with this change. No counter overflow is observed in normal runs; the clamp only fires when the shader's counter genuinely exceeds capacity.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:35:37 +00:00
github-bot closed this pull request 2026-11-26 09:35:37 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-27 17:59 UTC · original

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 10fc8280-5f25-4112-9abb-c58f16636719

📥 Commits

Reviewing files that changed from the base of the PR and between 421684e75f and 43345a76b4.

📒 Files selected for processing (1)
  • src/graphics/host_gpu/renderer/cache/faultManager.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

FaultManager::ProcessFaultBuffer now caps the number of fault entries it processes at MaxPageFaults - 1. When the raw counter exceeds this limit, it logs both the raw and clamped counts.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 43345

The clamp preserves every valid fault entry while preventing reads beyond the buffer. No concrete merge-blocking risk is established.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 43345

The host now limits fault-entry reads to the allocated area without adding a new entrypoint or expanding access. The remaining risk is low, though external reachability and broader security coverage are not established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated memory-safety effect is confined to host consumption of one fault area: an overflowing counter no longer makes this loop read entries from the next area.

Trust Boundaries and Controls

  • observed — The host treats the shader-produced count as potentially greater than the number of written entries and applies a capacity bound before dereferencing entries. External attacker reachability was not established.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description directly explains the fault counter overflow, the resulting buffer over-read, and the host-side clamp introduced by the changeset.
Title check ✅ Passed The title clearly and concisely identifies the main change: preventing fault counter overflow in FaultManager.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-27 17:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/869#issuecomment-5858347962) <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/869"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `10fc8280-5f25-4112-9abb-c58f16636719` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 421684e75f75e6d1a2c4b0817ca573a2e800f748 and 43345a76b46c99f86aad6438856a1a3aa7fda897. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/graphics/host_gpu/renderer/cache/faultManager.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough `FaultManager::ProcessFaultBuffer` now caps the number of fault entries it processes at `MaxPageFaults - 1`. When the raw counter exceeds this limit, it logs both the raw and clamped counts. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"43345a76b46c99f86aad6438856a1a3aa7fda897" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `43345` <!-- final_review_risk_coverage:{"sourceCommitId":"43345a76b46c99f86aad6438856a1a3aa7fda897","coveredCommitId":"43345a76b46c99f86aad6438856a1a3aa7fda897","kind":"reviewed"} --> The clamp preserves every valid fault entry while preventing reads beyond the buffer. No concrete merge-blocking risk is established. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🔵 Low_ · up to `43345` The host now limits fault-entry reads to the allocated area without adding a new entrypoint or expanding access. The remaining risk is low, though external reachability and broader security coverage are not established. **Retained concerns** No architecture-level concerns identified. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — The demonstrated memory-safety effect is confined to host consumption of one fault area: an overflowing counter no longer makes this loop read entries from the next area. **Trust Boundaries and Controls** - _observed_ — The host treats the shader-produced count as potentially greater than the number of written entries and applies a capacity bound before dereferencing entries. External attacker reachability was not established. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------- | | Description check | ✅ Passed | The description directly explains the fault counter overflow, the resulting buffer over-read, and the host-side clamp introduced by the changeset. | | Title check | ✅ Passed | The title clearly and concisely identifies the main change: preventing fault counter overflow in FaultManager. | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=869)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.