Bounds-check audio submit notifications and avoid u32 wrap in pump #460

Closed
ahmetbagci8 wants to merge 660 commits from upstream-pr/460 into main
ahmetbagci8 commented 2026-11-29 20:50:29 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by ahmetbagci8 on 2026-11-29T20:50:29Z.


Problem

In crates/victory-hle/src/modules/audio.rs:

  1. submit() validated
    otification with heap_unmap(notification) (which only checks that 1 byte is in bounds and does not check 4-byte alignment) before executing word.cast::().write_volatile(1). A notification address within the last 3 bytes of a heap block writes up to 3 bytes out of bounds, and an unaligned address triggers unaligned write_volatile UB.
  2. pump() computed let address = context.get(7) as usize + write as usize * BLOCK_BYTES; and cast ddress as u32, silently wrapping past u32::MAX into low APU addresses instead of returning None.
  3. heap_bytes() used unchecked offset + len <= size.

Fix

  • Require 4-byte alignment and full 4-byte bounds via heap_bytes(notification, size_of::()) in submit().
  • Use checked_add + u32::try_from in pump(), and offset.checked_add(len) in heap_bytes().
  • Add unit test submit_notification_requires_aligned_in_bounds_u32 covering both rejected unaligned/OOB notifications and valid aligned writes.

Verification

  • cargo test -p victory-hle --lib audio::tests (9 passed, 0 failed)
  • cargo clippy -p victory-hle --tests (0 warnings)
<!-- greyfinch-sync:TaynanGT/Vice-Tay:issue:5554978374 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/460). Originally posted by [ahmetbagci8](https://github.com/ahmetbagci8) on 2026-11-29T20:50:29Z. --- ## Problem In crates/victory-hle/src/modules/audio.rs: 1. submit() validated otification with heap_unmap(notification) (which only checks that 1 byte is in bounds and does not check 4-byte alignment) before executing word.cast::<u32>().write_volatile(1). A notification address within the last 3 bytes of a heap block writes up to 3 bytes out of bounds, and an unaligned address triggers unaligned write_volatile UB. 2. pump() computed let address = context.get(7) as usize + write as usize * BLOCK_BYTES; and cast ddress as u32, silently wrapping past u32::MAX into low APU addresses instead of returning None. 3. heap_bytes() used unchecked offset + len <= size. ## Fix - Require 4-byte alignment and full 4-byte bounds via heap_bytes(notification, size_of::<u32>()) in submit(). - Use checked_add + u32::try_from in pump(), and offset.checked_add(len) in heap_bytes(). - Add unit test submit_notification_requires_aligned_in_bounds_u32 covering both rejected unaligned/OOB notifications and valid aligned writes. ## Verification - cargo test -p victory-hle --lib audio::tests (9 passed, 0 failed) - cargo clippy -p victory-hle --tests (0 warnings)
TaynanGT commented 2026-11-30 17:05:19 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-30T17:05:19Z.


main has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current main and open a new PR; I'll review it there.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7285699538 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/460#issuecomment-7285699538). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-30T17:05:19Z. --- `main` has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current `main` and open a new PR; I'll review it there.

Pull request closed

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
TaynanGT/Vice-Tay!460
No description provided.