Loader: validate TLS pointers and bounds in OwnTls #3367
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3367"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by Arkenoz on 2026-11-26T20:38:46Z.
Tracked in #1633.
Problem
In
crates/victory-loader/src/threads.rs,OwnTls::save()dereferencedTEB.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
save_from(array, dir) -> Option<OwnTls>helper that validates non-nullarray,dir,(*dir).index, and resolvedblock, computes the block length withchecked_sub/checked_add, and returnsNonefor zero-length or invalid bounds.OwnTls::save()to delegate tosave_fromandon_threadto only restore whenSome(saved)is returned.OwnTls::restore()against nullblockor emptysaved.threads::testscovering 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.
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T20:49:49Z.
Review: APPROVED
LGTM — verified on Windows against
origin/main(63bcca4).array,dir,dir.index, andblockfor null and usingchecked_sub/checked_addfor the TLS block length cleanly guardsOwnTls::saveandOwnTls::restoreagainst invalid TLS pointers or overflowing bounds.cargo test -p victory-loader --lib threads:: -- --test-threads=1: 5 passed, 0 failed (includingown_tls_save_rejects_null_pointers,own_tls_save_rejects_invalid_bounds_and_lengths, andown_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).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T21:21:39Z.
Review: APPROVED
Clean defensive validation of
OwnTls::save/OwnTls::restoreincrates/victory-loader/src/threads.rs:301-348.save_fromvalidatesarray,dir,(*dir).index, and resolvedblockfor null, useschecked_sub/checked_addfor(*dir).end - (*dir).start + (*dir).zero_fill, and returnsNoneon zero-length or invalid bounds;on_threadcleanly flattens theOptionandOwnTls::restoreguards against null/empty state.origin/main63bcca43on Windows 11 x64):cargo xtask policy(191 files ok),cargo clippy --locked -p victory-loader --all-targets -- -D warnings(clean), and allvictory-loaderunit + integration tests (38 + 4 passed, 0 failed) pass.OwnTls::save()still succeeds on the real_tls_useddirectory (is_some = true, len = 217) and that a valid BSS-only TLS layout (start == end, zero_fill > 0) is accepted and restored properly.Minor non-blocking note: for completeness in
save_from, checkinglen > isize::MAX as usize(theslice::from_raw_partslength precondition) andslot == u32::MAX as usize(TLS_OUT_OF_INDEXES) would harden synthetic callers further, though neither can happen for a valid linker-emitted_tls_used.LGTM!
Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:44:14Z.
Windows 11,
63bcca4+ this PR:cargo test -p victory-loader: 38 passed / 0 failed (lib; unpatched63bcca4has 35, and +1 of those three is #3256's clzero test if you stack them), plus the integration suites (1 and 2 passed).cargo clippy -p victory-loader --all-targets -- -D warnings: clean.The TLS-pointer and bounds validation tests are in that run; no crash or panic in the loader suite here. Synthetic only. AI-assisted.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.