HLE: bounds-check all four bytes of ACP notification writes in audio::submit #2524

Open
github-bot wants to merge 1 commit from github-bot/gh-2524 into main AGit
Owner

@⁠reeledMarek on GitHub · 2026-11-25 15:16 UTC · original
reeledMarek:fix/hle-audio-bounds-and-wrap → main · +47 −3 · 1 files · 1 commits · open

Problem

  1. In audio::submit, ACP notification writes used heap_unmap(notification) (which only verifies 1 byte inside an APU heap block) and unconditionally executed word.cast::<u32>().write_volatile(1). A notification address in the last 1–3 bytes of a block writes past the end of the heap allocation, and any non-4-byte-aligned address triggers misaligned volatile write UB.
  2. In audio::pump, context.get(7) as usize + write as usize * BLOCK_BYTES cast back as u32 silently wrapped 32-bit device addresses near u32::MAX.
  3. heap_bytes performed unchecked offset + len.

Fix

  • Validate ACP notification writes with heap_bytes(notification, 4) and bytes.as_ptr().cast::<u32>().is_aligned().
  • Use checked_mul / checked_add for XMA output ring address computation in pump and checked_add in heap_bytes.

Testing

  • Added synthetic unit tests acp_notification_rejects_out_of_bounds_and_unaligned_addresses and pump_ignores_wrapping_output_ring_address in crates/victory-hle/src/modules/audio.rs.
  • Verified cargo test -p xtask --locked passes asset policy.
**@⁠reeledMarek** on GitHub · 2026-11-25 15:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2524) `reeledMarek:fix/hle-audio-bounds-and-wrap` → `main` · +47 −3 · 1 files · 1 commits · open ### Problem 1. In `audio::submit`, ACP notification writes used `heap_unmap(notification)` (which only verifies 1 byte inside an APU heap block) and unconditionally executed `word.cast::<u32>().write_volatile(1)`. A notification address in the last 1–3 bytes of a block writes past the end of the heap allocation, and any non-4-byte-aligned address triggers misaligned volatile write UB. 2. In `audio::pump`, `context.get(7) as usize + write as usize * BLOCK_BYTES` cast back `as u32` silently wrapped 32-bit device addresses near `u32::MAX`. 3. `heap_bytes` performed unchecked `offset + len`. ### Fix - Validate ACP notification writes with `heap_bytes(notification, 4)` and `bytes.as_ptr().cast::<u32>().is_aligned()`. - Use `checked_mul` / `checked_add` for XMA output ring address computation in `pump` and `checked_add` in `heap_bytes`. ### Testing - Added synthetic unit tests `acp_notification_rejects_out_of_bounds_and_unaligned_addresses` and `pump_ignores_wrapping_output_ring_address` in `crates/victory-hle/src/modules/audio.rs`. - Verified `cargo test -p xtask --locked` passes asset policy.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:08:11 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:54 UTC · original · edited 2026-11-25 20:23 UTC

Automated triage for the maintainers.

Merge candidate. In submit (crates/victory-hle/src/modules/audio.rs), the ACP notification word was written through heap_unmap, which only checks that its first byte is inside a heap block. It is now written through heap_bytes(notification, 4), which requires all four bytes in one block, with copy_from_slice(&1u32.to_le_bytes()). A notification at the last 1–3 bytes of a block no longer writes past it. An unaligned in-bounds notification is still written, now without the misaligned write_volatile. The new test covers the tail cases (nothing written), an unaligned write at +1 and an aligned write at +12.

Reply to the author: both points from the last triage are addressed. Unaligned notifications are written instead of dropped, and the pump/heap_bytes overflow guards and their test are gone. The PR description still lists the dropped changes and the old test names, so please update it before merge.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2524#issuecomment-7167417110) · edited 2026-11-25 20:23 UTC <!-- victory-triage v1 head=5d6fbb4ee00cbd5653900d062ed564074a387fa6 verdict=merge-candidate at=2026-11-25T20:22:45Z --> Automated triage for the maintainers. **Merge candidate.** In `submit` (`crates/victory-hle/src/modules/audio.rs`), the ACP notification word was written through `heap_unmap`, which only checks that its first byte is inside a heap block. It is now written through `heap_bytes(notification, 4)`, which requires all four bytes in one block, with `copy_from_slice(&1u32.to_le_bytes())`. A notification at the last 1–3 bytes of a block no longer writes past it. An unaligned in-bounds notification is still written, now without the misaligned `write_volatile`. The new test covers the tail cases (nothing written), an unaligned write at +1 and an aligned write at +12. Reply to the author: both points from the last triage are addressed. Unaligned notifications are written instead of dropped, and the `pump`/`heap_bytes` overflow guards and their test are gone. The PR description still lists the dropped changes and the old test names, so please update it before merge. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠reeledMarek on GitHub · 2026-11-25 20:05 UTC · original

Updated to address the triage feedback:

  • Kept the 4-byte bounds check via heap_bytes(notification, 4) in submit and switched to bytes.copy_from_slice(&1u32.to_le_bytes()) so unaligned in-bounds notifications still complete instead of being silently dropped.
  • Dropped the speculative overflow guards in pump/heap_bytes and pump_ignores_wrapping_output_ring_address.
  • Updated the unit test to verify both out-of-bounds tail rejection and unaligned/aligned in-bounds writes.
**@⁠reeledMarek** on GitHub · 2026-11-25 20:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2524#issuecomment-7173174733) Updated to address the triage feedback: - Kept the 4-byte bounds check via `heap_bytes(notification, 4)` in `submit` and switched to `bytes.copy_from_slice(&1u32.to_le_bytes())` so unaligned in-bounds notifications still complete instead of being silently dropped. - Dropped the speculative overflow guards in `pump`/`heap_bytes` and `pump_ignores_wrapping_output_ring_address`. - Updated the unit test to verify both out-of-bounds tail rejection and unaligned/aligned in-bounds writes.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 01:41 UTC · original

Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head 5d6fbb4 (on its base 13f91ca).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 774 passed, 0 failed, 9 ignored.
  • The new tests ran and passed: acp_notification_checks_all_four_bytes_and_allows_unaligned.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-26 01:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2524#issuecomment-7180023830) Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `5d6fbb4` (on its base `13f91ca`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **774 passed, 0 failed, 9 ignored**. - The new tests ran and passed: `acp_notification_checks_all_four_bytes_and_allows_unaligned`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2524/head:github-bot/gh-2524'
git switch 'github-bot/gh-2524'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2524'
git switch 'github-bot/gh-2524'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2524'
git switch 'github-bot/gh-2524'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2524'
git switch 'main'
git merge --squash 'github-bot/gh-2524'
git switch 'main'
git merge --ff-only 'github-bot/gh-2524'
git switch 'main'
git merge 'github-bot/gh-2524'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2524
No description provided.