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

Open
AscilCH wants to merge 1 commit from upstream-pr/403 into main
AscilCH commented 2026-11-25 00:25:33 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T00:25:33Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6594259771 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/403). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T00:25:33Z. --- ## 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.)*
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/403:upstream-pr/403'
git switch 'upstream-pr/403'

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/403'
git switch 'upstream-pr/403'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/403'
git switch 'upstream-pr/403'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/403'
git switch 'main'
git merge --squash 'upstream-pr/403'
git switch 'main'
git merge --ff-only 'upstream-pr/403'
git switch 'main'
git merge 'upstream-pr/403'
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
fxceless/victory-fork!403
No description provided.