fix(libkernel): avoid semaphore count overflow #315

Merged
RomainROCH merged 1 commit from upstream-pr/315 into main 2026-10-04 01:01:19 +00:00
RomainROCH commented 2026-10-02 04:22:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by RomainROCH on 2026-10-02T04:22:32Z.


What

Check a semaphore signal against the remaining capacity before adding it. The previous signed addition could overflow before the maximum-count check, accepting an excessive signal and corrupting the token count.

The regression covers INT_MAX-1 plus 2 and plus INT_MAX, an exact-limit signal, rejection at full capacity, and an ordinary small limit. Polling the original number of tokens after rejection verifies that the counter is unchanged.

Tested

  • Commit: 74586bab57.
  • Windows, WinLibs GCC 16.1: guest_kernel_errors fails before the fix and passes after it, including the existing queue and mutex checks.
  • Full Linux/Windows Build workflow: https://github.com/RomainROCH/AnyPS5/actions/runs/36964211239 (passed: Linux GCC 13.3 and Windows WinLibs GCC 15.2; full build, libs target and complete CTest suite on both platforms).
  • Synthetic semaphore fixture only; no game or homebrew compatibility tested. No separate focused relinker run.

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 added
  • No new unimplemented paths or silent stubs
  • No investigation notes or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4712650532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/315). Originally posted by [RomainROCH](https://github.com/RomainROCH) on 2026-10-02T04:22:32Z. --- ### What Check a semaphore signal against the remaining capacity before adding it. The previous signed addition could overflow before the maximum-count check, accepting an excessive signal and corrupting the token count. The regression covers INT_MAX-1 plus 2 and plus INT_MAX, an exact-limit signal, rejection at full capacity, and an ordinary small limit. Polling the original number of tokens after rejection verifies that the counter is unchanged. ### Tested - Commit: 74586bab5778c4da9475b175c2ee82787d212f9f. - Windows, WinLibs GCC 16.1: guest_kernel_errors fails before the fix and passes after it, including the existing queue and mutex checks. - Full Linux/Windows Build workflow: https://github.com/RomainROCH/AnyPS5/actions/runs/36964211239 (passed: Linux GCC 13.3 and Windows WinLibs GCC 15.2; full build, libs target and complete CTest suite on both platforms). - Synthetic semaphore fixture only; no game or homebrew compatibility tested. No separate focused relinker run. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code added - [x] No new unimplemented paths or silent stubs - [x] No investigation notes or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!315
No description provided.