HLE/dstorage: retain IDStorageFile ref and own Request.name on enqueued reads #403

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

@⁠AscilCH on GitHub · 2026-11-25 00:25 UTC · original
AscilCH:fix/dstorage-retain-file-and-name → main · +116 −18 · 1 files · 1 commits · open

Problem

In crates/victory-hle/src/modules/dstorage.rs, enqueue_request copied the caller's Request by value without retaining a COM reference on request.source (Instance<File>) or copying request.name:

  1. IDStorageFile UAF: Unlike enqueue_status (which calls add_ref_instance on the status array and releases it in Status::drop), enqueue_request did not retain request.source for file-backed reads (options & MEMORY_SOURCE == 0). If the title called IDStorageFile::Release() after EnqueueRequest, Instance<File> and its OS File handle were freed immediately before the worker thread ran read_into.
  2. Request::name UAF: request.name (*const c_char) was copied as a raw pointer and dereferenced asynchronously on the worker thread in execute's fail closure, even though DSTORAGE_REQUEST::Name only needs to outlive EnqueueRequest.

Fix

  • Replace Command::Read(Request), Lane::reads entries, and Job::request with an owned QueuedRead that:
    • Copies request.name eagerly via text(request.name) and nulls request.name.
    • Calls add_ref_instance on request.source when options & MEMORY_SOURCE == 0 && !source.is_null().
    • Releases the file reference immediately after execute (before acquiring scheduler.lock() and signaling status completion) and in Drop (covering unstarted reads discarded by Close or a closed queue).
  • Add unit test dstorage::tests::enqueued_request_retains_file_and_copies_name_until_completion.

Verification

  • cargo test -p victory-hle --locked dstorage -- --test-threads=1: 14 passed, 0 failed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings: clean

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 00:25 UTC · [original](https://github.com/fxceless/victory-fork/pull/403) `AscilCH:fix/dstorage-retain-file-and-name` → `main` · +116 −18 · 1 files · 1 commits · open ## Problem In `crates/victory-hle/src/modules/dstorage.rs`, `enqueue_request` copied the caller's `Request` by value without retaining a COM reference on `request.source` (`Instance<File>`) or copying `request.name`: 1. **`IDStorageFile` UAF**: Unlike `enqueue_status` (which calls `add_ref_instance` on the status array and releases it in `Status::drop`), `enqueue_request` did not retain `request.source` for file-backed reads (`options & MEMORY_SOURCE == 0`). If the title called `IDStorageFile::Release()` after `EnqueueRequest`, `Instance<File>` and its OS `File` handle were freed immediately before the worker thread ran `read_into`. 2. **`Request::name` UAF**: `request.name` (`*const c_char`) was copied as a raw pointer and dereferenced asynchronously on the worker thread in `execute`'s `fail` closure, even though `DSTORAGE_REQUEST::Name` only needs to outlive `EnqueueRequest`. ## Fix - Replace `Command::Read(Request)`, `Lane::reads` entries, and `Job::request` with an owned `QueuedRead` that: - Copies `request.name` eagerly via `text(request.name)` and nulls `request.name`. - Calls `add_ref_instance` on `request.source` when `options & MEMORY_SOURCE == 0 && !source.is_null()`. - Releases the file reference immediately after `execute` (before acquiring `scheduler.lock()` and signaling status completion) and in `Drop` (covering unstarted reads discarded by `Close` or a closed queue). - Add unit test `dstorage::tests::enqueued_request_retains_file_and_copies_name_until_completion`. ## Verification - `cargo test -p victory-hle --locked dstorage -- --test-threads=1`: 14 passed, 0 failed - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings`: clean *(AI-assisted; synthetic unit tests only, no game data.)*
`enqueue_request` previously copied `Request` by value without calling
`add_ref_instance` on `request.source` (for file sources) and passed the
caller's raw `request.name` (`*const c_char`) pointer to async worker
threads. Under DirectStorage semantics, titles may call
`IDStorageFile::Release()` and reuse or free the `DSTORAGE_REQUEST::Name`
buffer immediately after `EnqueueRequest` returns, causing workers to
dereference freed `Instance<File>` / closed OS handles in `read_into`
and dangling name strings in `execute`'s `fail` logger.

Wrap enqueued reads in an owned `QueuedRead` that eagerly copies
`request.name` into a `String`, clears `request.name`, retains a COM
reference on `Instance<File>` when `options & MEMORY_SOURCE == 0`, and
releases it right after `execute` completes (outside `scheduler.lock()`)
or in `Drop` when unstarted reads are discarded on `Close`.

Add `dstorage::tests::enqueued_request_retains_file_and_copies_name_until_completion`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:42:42 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-hle/src/modules/dstorage.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/403/head:github-bot/gh-403'
git switch 'github-bot/gh-403'

Merge

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