GPU: initialize title-memory page tables to null entries and guard range overflow #2542

Closed
reeledMarek wants to merge 1 commit from upstream-pr/2544 into main
reeledMarek commented 2026-11-25 15:33:48 +00:00 (Migrated from github.com)

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


Problem

  1. memory::Shared::new() allocated the upload buffer for a heap's title-memory page table without initializing level 1 and block 0 to [self.null, 0]. If a title bound title memory on a new heap and released the heap before submitting the list, memory::prepare could not run rewrite(), leaving shaders reading an all-zero page table that pointed to descriptor heap slot 0 instead of self.null.
  2. memory::table() checked start + len > 1 << 40 with unchecked addition, which panics in debug or wraps in release for overflowing ranges.

Fix

  • Populate level 1 and block 0 of newly created page tables with table(&[], &[], null) in Shared::new().
  • Use start.checked_add(len) in memory::table().

Testing

  • Added overflowing_copy_ranges_are_ignored_and_empty_table_routes_to_null in crates/victory-gpu/src/memory.rs.
  • Verified cargo test -p xtask --locked passes asset policy.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6608065294 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2544). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T15:33:48Z. --- ### Problem 1. `memory::Shared::new()` allocated the upload buffer for a heap's title-memory page table without initializing level 1 and block 0 to `[self.null, 0]`. If a title bound title memory on a new heap and released the heap before submitting the list, `memory::prepare` could not run `rewrite()`, leaving shaders reading an all-zero page table that pointed to descriptor heap slot `0` instead of `self.null`. 2. `memory::table()` checked `start + len > 1 << 40` with unchecked addition, which panics in debug or wraps in release for overflowing ranges. ### Fix - Populate level 1 and block 0 of newly created page tables with `table(&[], &[], null)` in `Shared::new()`. - Use `start.checked_add(len)` in `memory::table()`. ### Testing - Added `overflowing_copy_ranges_are_ignored_and_empty_table_routes_to_null` in `crates/victory-gpu/src/memory.rs`. - Verified `cargo test -p xtask --locked` passes asset policy.
Marvisak commented 2026-11-25 19:06:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T18:35:11Z.


Automated triage for the maintainers.

Two changes in victory-gpu/src/memory.rs:

  1. table() uses checked_add. The ranges come only from Shadow::range() of registered host copies (Shared::rewrite), so start + len cannot overflow a u64. This guards a case that can't happen, and the test only exercises it with made-up ranges. Please drop it unless you can show a caller that passes such a range.
  2. Shared::new fills the page table with null entries. bind creates the table, and every submission that uses it runs prepare, which rewrites it (generation starts at u64::MAX). So the zeroed table is only ever read if the title's heap has already been released when the list is submitted. That is invalid use of the heap anyway, and the null pair lives in that same heap. The fill is cheap and harmless, but it needs a concrete case where it changes behaviour: a log or a sequence of title calls showing a list submitted after its heap was released.

With (1) removed and (2) motivated, this could go in as a small hardening change. CI checks: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171112296 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2544#issuecomment-7171112296). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T18:35:11Z. --- <!-- victory-triage v1 head=ae0d9f674459c4b33888db25310b042ab07eba35 verdict=needs-work at=2026-11-25T18:35:00Z --> Automated triage for the maintainers. Two changes in `victory-gpu/src/memory.rs`: 1. **`table()` uses `checked_add`.** The ranges come only from `Shadow::range()` of registered host copies (`Shared::rewrite`), so `start + len` cannot overflow a `u64`. This guards a case that can't happen, and the test only exercises it with made-up ranges. Please drop it unless you can show a caller that passes such a range. 2. **`Shared::new` fills the page table with null entries.** `bind` creates the table, and every submission that uses it runs `prepare`, which rewrites it (`generation` starts at `u64::MAX`). So the zeroed table is only ever read if the title's heap has already been released when the list is submitted. That is invalid use of the heap anyway, and the null pair lives in that same heap. The fill is cheap and harmless, but it needs a concrete case where it changes behaviour: a log or a sequence of title calls showing a list submitted after its heap was released. With (1) removed and (2) motivated, this could go in as a small hardening change. CI checks: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
reeledMarek commented 2026-11-25 20:06:30 +00:00 (Migrated from github.com)

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


Closing per triage — Shadow::range() cannot overflow and prepare() always populates the page table before valid use. Thanks for the review!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7173181528 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2544#issuecomment-7173181528). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T20:05:39Z. --- Closing per triage — `Shadow::range()` cannot overflow and `prepare()` always populates the page table before valid use. Thanks for the review!
upstream-sync closed this pull request 2026-11-25 21:02:34 +00:00

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
Marvisak/VIctory!2542
No description provided.