Loader: validate TLS pointers and bounds in OwnTls #3367

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

@⁠Arkenoz on GitHub · 2026-11-26 20:38 UTC · original
Arkenoz:fix/own-tls-validation → main · +161 −10 · 1 files · 1 commits · open

Tracked in #1633.

Problem

In crates/victory-loader/src/threads.rs, OwnTls::save() dereferenced TEB.ThreadLocalStoragePointer (gs:[0x58]), (*dir).index, and *array.add(slot) without null checks, and computed the TLS block length with unchecked arithmetic ((*dir).end - (*dir).start + (*dir).zero_fill as usize).

Changes

  • Extracted a private save_from(array, dir) -> Option<OwnTls> helper that validates non-null array, dir, (*dir).index, and resolved block, computes the block length with checked_sub/checked_add, and returns None for zero-length or invalid bounds.
  • Updated OwnTls::save() to delegate to save_from and on_thread to only restore when Some(saved) is returned.
  • Guarded OwnTls::restore() against null block or empty saved.
  • Added unit tests in threads::tests covering null pointers, invalid bounds/overflow/zero length, and synthetic TLS save/restore round-trip.

Verification

  • cargo test -p victory-loader (38 unit + 4 integration tests passed)
  • cargo clippy -p victory-loader --all-targets (0 warnings)

AI-assisted with Gemini.

**@⁠Arkenoz** on GitHub · 2026-11-26 20:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/3367) `Arkenoz:fix/own-tls-validation` → `main` · +161 −10 · 1 files · 1 commits · open Tracked in #1633. ### Problem In `crates/victory-loader/src/threads.rs`, `OwnTls::save()` dereferenced `TEB.ThreadLocalStoragePointer` (`gs:[0x58]`), `(*dir).index`, and `*array.add(slot)` without null checks, and computed the TLS block length with unchecked arithmetic (`(*dir).end - (*dir).start + (*dir).zero_fill as usize`). ### Changes - Extracted a private `save_from(array, dir) -> Option<OwnTls>` helper that validates non-null `array`, `dir`, `(*dir).index`, and resolved `block`, computes the block length with `checked_sub`/`checked_add`, and returns `None` for zero-length or invalid bounds. - Updated `OwnTls::save()` to delegate to `save_from` and `on_thread` to only restore when `Some(saved)` is returned. - Guarded `OwnTls::restore()` against null `block` or empty `saved`. - Added unit tests in `threads::tests` covering null pointers, invalid bounds/overflow/zero length, and synthetic TLS save/restore round-trip. ### Verification - `cargo test -p victory-loader` (38 unit + 4 integration tests passed) - `cargo clippy -p victory-loader --all-targets` (0 warnings) AI-assisted with Gemini.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:43:33 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 20:49 UTC · original · approved these changes

LGTM — verified on Windows against origin/main (63bcca4).

  • Validating array, dir, dir.index, and block for null and using checked_sub / checked_add for the TLS block length cleanly guards OwnTls::save and OwnTls::restore against invalid TLS pointers or overflowing bounds.
  • cargo test -p victory-loader --lib threads:: -- --test-threads=1: 5 passed, 0 failed (including own_tls_save_rejects_null_pointers, own_tls_save_rejects_invalid_bounds_and_lengths, and own_tls_save_and_restore_preserves_state).
  • cargo clippy -p victory-loader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 20:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/3367#pullrequestreview-6080349875) · **approved these changes** LGTM — verified on Windows against `origin/main` (`63bcca4`). - Validating `array`, `dir`, `dir.index`, and `block` for null and using `checked_sub` / `checked_add` for the TLS block length cleanly guards `OwnTls::save` and `OwnTls::restore` against invalid TLS pointers or overflowing bounds. - `cargo test -p victory-loader --lib threads:: -- --test-threads=1`: 5 passed, 0 failed (including `own_tls_save_rejects_null_pointers`, `own_tls_save_rejects_invalid_bounds_and_lengths`, and `own_tls_save_and_restore_preserves_state`). - `cargo clippy -p victory-loader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3367'
git switch 'github-bot/gh-3367'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3367'
git switch 'github-bot/gh-3367'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3367'
git switch 'main'
git merge --squash 'github-bot/gh-3367'
git switch 'main'
git merge --ff-only 'github-bot/gh-3367'
git switch 'main'
git merge 'github-bot/gh-3367'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3367
No description provided.