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

Open
reeledMarek wants to merge 1 commit from upstream-pr/2524 into main
reeledMarek commented 2026-11-25 15:16:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T15:16:40Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5494092753 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2524). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T15:16:40Z. --- ### 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.
Marvisak commented 2026-11-25 16:09:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:54:21Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167417110 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2524#issuecomment-7167417110). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:54:21Z. --- <!-- 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)_
reeledMarek commented 2026-11-25 20:06:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T20:05:21Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7173174733 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2524#issuecomment-7173174733). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T20:05:21Z. --- 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.
upstream-sync changed title from [PR #2524] HLE: bounds-check ACP notification writes and XMA pump address arithmetic to [PR #2524] HLE: bounds-check all four bytes of ACP notification writes in audio::submit 2026-11-25 21:02:31 +00:00
futurepro62 commented 2026-11-26 02:07:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T01:41:13Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7180023830 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2524#issuecomment-7180023830). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T01:41:13Z. --- 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.
fuzeofficlal commented 2026-11-26 02:20:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:20:39Z.

Review: COMMENTED


Reviewed and verified against main (63bcca43) on Windows 11 — clean bounds fix and ready to merge:

  • Switching audio::submit's ACP notification write from heap_unmap to heap_bytes(notification, 4) (crates/victory-hle/src/modules/audio.rs:212-220, 905-909) validates all 4 bytes against block.size (rejecting +13/+14/+15 on a 16-byte block) while supporting valid unaligned addresses safely.

Local verification:

  • cargo test --locked -p victory-hle: 155/155 passed (including acp_notification_checks_all_four_bytes_and_allows_unaligned)
  • cargo clippy --all-targets -- -D warnings (default & --all-features) + cargo xtask policy (191 files ok): 0 warnings
<!-- greyfinch-sync:Marvisak/VIctory:review:6067704487 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2524#pullrequestreview-6067704487). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T02:20:39Z. **Review:** COMMENTED --- Reviewed and verified against `main` (`63bcca43`) on Windows 11 — clean bounds fix and ready to merge: - Switching `audio::submit`'s ACP notification write from `heap_unmap` to `heap_bytes(notification, 4)` (`crates/victory-hle/src/modules/audio.rs:212-220, 905-909`) validates all 4 bytes against `block.size` (rejecting `+13/+14/+15` on a 16-byte block) while supporting valid unaligned addresses safely. **Local verification**: - `cargo test --locked -p victory-hle`: **155/155 passed** (including `acp_notification_checks_all_four_bytes_and_allows_unaligned`) - `cargo clippy --all-targets -- -D warnings` (default & `--all-features`) + `cargo xtask policy` (`191 files ok`): 0 warnings
cloph-dsp commented 2026-11-27 02:05:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-27T02:05:05Z.


Independent CPU-only verification on Windows (Rust 1.100.0/MSVC, worktree-local CARGO_TARGET_DIR, CARGO_BUILD_JOBS=2, no game data).

  • PR head 5d6fbb4, merge base 13f91ca.
  • cargo test --locked -p victory-hle --lib -- modules::audio::tests::acp_notification_checks_all_four_bytes_and_allows_unaligned --exact --test-threads=1 --quiet -> test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 146 filtered out.
  • git diff --check 13f91ca HEAD -> exit 0.
  • Negative control: the real test name in the diff is absent from 13f91ca (git grep -c ... crates/victory-hle/src/modules/audio.rs -> exit 1). The PR body names a different, stale test name.

Note: only the named synthetic test was replayed; the full crate suite was not run. GPU/driver: N/A (CPU-only HLE test). AI-assisted (Hy4 flash). No game data, assets, extracted shaders or DRM involved.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7207817691 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2524#issuecomment-7207817691). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-27T02:05:05Z. --- Independent CPU-only verification on Windows (Rust 1.100.0/MSVC, worktree-local `CARGO_TARGET_DIR`, `CARGO_BUILD_JOBS=2`, no game data). - PR head `5d6fbb4`, merge base `13f91ca`. - `cargo test --locked -p victory-hle --lib -- modules::audio::tests::acp_notification_checks_all_four_bytes_and_allows_unaligned --exact --test-threads=1 --quiet` -> `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 146 filtered out`. - `git diff --check 13f91ca HEAD` -> exit 0. - Negative control: the real test name in the diff is absent from `13f91ca` (`git grep -c ... crates/victory-hle/src/modules/audio.rs` -> exit 1). The PR body names a different, stale test name. Note: only the named synthetic test was replayed; the full crate suite was not run. GPU/driver: N/A (CPU-only HLE test). AI-assisted (Hy4 flash). No game data, assets, extracted shaders or DRM involved.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2524:upstream-pr/2524'
git switch 'upstream-pr/2524'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2524'
git switch 'upstream-pr/2524'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2524'
git switch 'upstream-pr/2524'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2524'
git switch 'main'
git merge --squash 'upstream-pr/2524'
git switch 'main'
git merge --ff-only 'upstream-pr/2524'
git switch 'main'
git merge 'upstream-pr/2524'
git push origin 'main'
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
Marvisak/VIctory!2522
No description provided.