victory-gpu(shadow): flush SNAPS before dropping Shadow to prevent use-after-free #936

Open
github-bot wants to merge 2 commits from github-bot/gh-936 into main AGit
Owner

@⁠faycalbaklouti on GitHub · 2026-11-25 13:14 UTC · original
faycalbaklouti:fix/shadow-snaps-uaf-flush → main · +21 −0 · 1 files · 2 commits · open

Target upstream: fxceless/victory-fork (note: SNAPS / VICTORY_WIDE_BACK is specific to fxceless/victory-fork and does not exist in Marvisak/VIctory or Belobug/VIctory-Belobug-AMD)

Problem

When VICTORY_WIDE_BACK=1 is enabled, Shadow::writing queues raw pointer tuples (data_ptr, snapshot_ptr, len) into the global SNAPS queue for deferred parallel copying in take_snapshots(). If a Shadow is dropped while SNAPS still holds pointers into its backing mapping or pooled snapshot buffer, the subsequent take_snapshots() call reads/writes freed memory (use-after-free).

Solution

  • In impl Drop for Shadow, flush any queued entries in SNAPS via take_snapshots() before releasing the Shadow's resources.
  • Add unit test take_snapshots_flushes_queued_snaps_before_release.

Verification

  • git apply --check passes cleanly on fxceless/victory-fork main.

About our fork & censorship-resistant preservation effort:
This fix comes from gta6-vi-port, our open-source Linux (GE-Proton) + NVIDIA RTX 4090 fork of VIctory and peer-to-peer Radicle archival effort (mirroring 92+ community porting repositories across public Radicle seeds so open-source porting research survives centralized takedowns; open-source code only, no game files/keys/binaries).

**@⁠faycalbaklouti** on GitHub · 2026-11-25 13:14 UTC · [original](https://github.com/fxceless/victory-fork/pull/936) `faycalbaklouti:fix/shadow-snaps-uaf-flush` → `main` · +21 −0 · 1 files · 2 commits · open **Target upstream:** `fxceless/victory-fork` (note: `SNAPS` / `VICTORY_WIDE_BACK` is specific to `fxceless/victory-fork` and does not exist in `Marvisak/VIctory` or `Belobug/VIctory-Belobug-AMD`) ## Problem When `VICTORY_WIDE_BACK=1` is enabled, `Shadow::writing` queues raw pointer tuples `(data_ptr, snapshot_ptr, len)` into the global `SNAPS` queue for deferred parallel copying in `take_snapshots()`. If a `Shadow` is dropped while `SNAPS` still holds pointers into its backing mapping or pooled snapshot buffer, the subsequent `take_snapshots()` call reads/writes freed memory (use-after-free). ## Solution - In `impl Drop for Shadow`, flush any queued entries in `SNAPS` via `take_snapshots()` before releasing the `Shadow`'s resources. - Add unit test `take_snapshots_flushes_queued_snaps_before_release`. ## Verification - `git apply --check` passes cleanly on `fxceless/victory-fork` `main`. --- **About our fork & censorship-resistant preservation effort:** This fix comes from **[gta6-vi-port](https://github.com/go2afri/gta6-vi-port)**, our open-source Linux (GE-Proton) + NVIDIA RTX 4090 fork of VIctory and peer-to-peer Radicle archival effort (mirroring 92+ community porting repositories across public Radicle seeds so open-source porting research survives centralized takedowns; open-source code only, no game files/keys/binaries). - **Canonical Radicle repo:** https://radicle.network/nodes/rosa.radicle.network/rad:z39ofPhQC1siudH9BF3xsmAMmUqxc (`rad:z39ofPhQC1siudH9BF3xsmAMmUqxc`) - **Live 1080p development stream:** https://vdo.ninja/?view=gta6rtx4090live1080p60 (Tor v3 `.onion` VP9+Opus viewer: `http://kwnoaeecpmxd6eetqfa7fxlymvxnh5du2i6wxr44t4mc7cgch5pw23id.onion/`)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:54:13 +00:00
Author
Owner

@⁠tikD1337 on GitHub · 2026-11-25 13:50 UTC · original

Thanks for the fix. On main @ a253706 (Windows 11, RTX 4070 Ti SUPER, Rust 1.98.1), the library builds, but the test target does not:

error[E0425]: cannot find function `pooled` in this scope
   --> crates\victory-gpu\src\shadow.rs:1936:23
error[E0425]: cannot find value `SNAPS` in this scope
error[E0425]: cannot find function `take_snapshots` in this scope

The new test sits in mod merge_tests, which only imports PIECE, back_piece, changed_runs. One line fixes it:

use super::{give_back, pooled, take_snapshots, SNAPS};

With that line: take_snapshots_flushes_queued_snaps_before_release passes, and cargo test --release -p victory-gpu --lib -- --test-threads=1 gives 170 passed, 1 failed. The failure is the known flaky indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields that #849 fixes.

**@⁠tikD1337** on GitHub · 2026-11-25 13:50 UTC · [original](https://github.com/fxceless/victory-fork/pull/936#issuecomment-7164376122) Thanks for the fix. On `main` @ `a253706` (Windows 11, RTX 4070 Ti SUPER, Rust 1.98.1), the library builds, but the test target does not: ``` error[E0425]: cannot find function `pooled` in this scope --> crates\victory-gpu\src\shadow.rs:1936:23 error[E0425]: cannot find value `SNAPS` in this scope error[E0425]: cannot find function `take_snapshots` in this scope ``` The new test sits in `mod merge_tests`, which only imports `PIECE, back_piece, changed_runs`. One line fixes it: ```rust use super::{give_back, pooled, take_snapshots, SNAPS}; ``` With that line: `take_snapshots_flushes_queued_snaps_before_release` passes, and `cargo test --release -p victory-gpu --lib -- --test-threads=1` gives 170 passed, 1 failed. The failure is the known flaky `indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields` that #849 fixes.
Author
Owner

@⁠faycalbaklouti on GitHub · 2026-11-25 14:18 UTC · original

Good catch, thanks for testing it! Added use super::{give_back, pooled, take_snapshots, SNAPS}; to mod merge_tests in c00ac40 and verified the victory-gpu Windows test target compiles cleanly (cargo xwin test --target x86_64-pc-windows-msvc -p victory-gpu --no-run).

**@⁠faycalbaklouti** on GitHub · 2026-11-25 14:18 UTC · [original](https://github.com/fxceless/victory-fork/pull/936#issuecomment-7165067637) Good catch, thanks for testing it! Added `use super::{give_back, pooled, take_snapshots, SNAPS};` to `mod merge_tests` in c00ac40 and verified the `victory-gpu` Windows test target compiles cleanly (`cargo xwin test --target x86_64-pc-windows-msvc -p victory-gpu --no-run`).
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/shadow.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-936'
git switch 'github-bot/gh-936'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-936'
git switch 'github-bot/gh-936'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-936'
git switch 'main'
git merge --squash 'github-bot/gh-936'
git switch 'main'
git merge --ff-only 'github-bot/gh-936'
git switch 'main'
git merge 'github-bot/gh-936'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.