Skip to content

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

Open
faycalbaklouti wants to merge 2 commits into
fxceless:mainfrom
faycalbaklouti:fix/shadow-snaps-uaf-flush
Open

faycalbaklouti wants to merge 2 commits into
fxceless:mainfrom
faycalbaklouti:fix/shadow-snaps-uaf-flush

Conversation

@faycalbaklouti

@faycalbaklouti faycalbaklouti commented Nov 25, 2026 •

Copy link
Copy Markdown

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).

@tikD1337

Copy link
Copy Markdown

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.

AlexMiu2083 added a commit to AlexMiu2083/victory-MBT that referenced this pull request Nov 25, 2026
…r runs across the cursor, snapshots flushed before a copy goes, changed runs reused, texture checks side by side, the card-copy census and its write-combining experiment

From fxceless/victory-fork's open pull requests:

- fxceless#911 (douline): a constant buffer view is at most 64 KiB; the title names
  larger ones and NVIDIA removes the device for them.
- fxceless#932 (avt0m4t48): the search for free dynamic descriptor slots finds a run
  that lies across its starting point.
- fxceless#936 (faycalbaklouti): queued snapshots are taken before a host copy is
  dropped (a use after free); its test's imports added for this tree.
- fxceless#925 (alpz1000): changed-byte runs are found into one buffer reused across
  pages, the merge gap joined in the same pass.
- fxceless#768 (KyleS98): a submission's texture checks run several at a time
  (`VICTORY_WIDE_TEXTURES=1`, off by default).
- fxceless#868 (Chipsraine): a census of the card copies (`VICTORY_CENSUS=1`) and an
  EXPERIMENT, off by default: `VICTORY_SKIP_WC_COMPARE=1` leaves copies of
  write-combining title memory out of the compare and the copy-back. Here
  (RTX 4070, first gameplay scene) it took the median from 213 to 186 ms a
  frame, best 150 ms; not exact (the title must never read that memory
  after the card wrote it).

With them gameplay went from a median of 233 to 213 ms a frame here.

Tried and left off: `VICTORY_CARD_REHASH_RUNS=1` (1,735 passes a frame
joined to about 220, no gain).

victory-gpu: 174 tests pass (`inplace::...shows_its_bytes_at_its_offset`
fails now and then, as before these); victory-hle: 99 pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@faycalbaklouti

Copy link
Copy Markdown
Author

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).

e4glevlr added a commit to e4glevlr/victory-fork that referenced this pull request Nov 25, 2026
…APS flush, fxceless#827 skip_frames) + test fixes

- PR fxceless#911: clamp HostHeap::constant_at CBV SizeInBytes to <= 64 KiB via constant_view_size()
- PR fxceless#936: flush SNAPS via take_snapshots() before dropping Shadow to prevent UAF
- PR fxceless#827 (crash-fix part): add opt-in VICTORY_TABLED_SKIP_FRAMES check in HostHeap::tabled_lately (omits copy_or_make VRAM growth and unsafe COPY_FAST)
- Align merged unit tests in shadow.rs, host.rs, indirect.rs, indirect/bench.rs, texture.rs and deduplicate record_print_tests
wolfattack199 added a commit to wolfattack199/victory-fork that referenced this pull request Nov 25, 2026
…t, page arrays waited for, views of at most 64 KiB

- The card's compare takes 64 threads a 64 KiB piece, and fills of upload
  memory are kept in their own lists (fxceless#929 by AlexMiu, d07e1eb).
- Constant tables read on the card in place (VICTORY_TABLE_CBV_DIRECT=1;
  off by default here) (fxceless#929).
- A DirectStorage request whose page array the title fills late waits up to
  100 ms for it (fxceless#929).
- A constant buffer view is at most 64 KiB (fxceless#911 by douline).
- A shadow that goes takes its queued snapshots first (fxceless#936 by
  faycalbaklouti).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants