Loader: suspend a thread before reading its TEB; skip bad dump times #221
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/221"
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 AndyLatimer on 2026-11-24T01:35:03Z.
Two fixes in the scheduled stack dumps (
crates/victory-loader/src/stacks.rs,VICTORY_STACKS, diagnostics builds).TEB read of a running thread:
frames_ofaskedNtQueryInformationThreadfor the thread's TEB and read the stack bounds from it, then calledSuspendThread. OurOpenThreadhandle keeps only the thread object alive, not its TEB. A title thread that exits between the query and the read frees its TEB, and the read faults: a crash caused by the diagnostics feature itself. The thread is now suspended before the query, and resumed on every path out (query failure included). The SAFETY comment now matches.Dump times that panic: each time went through
Duration::from_secs_f64(t.max(0.0)), which panics forinf,1e20and other times noDurationcan hold. That kills the dump thread, andlog_crashes_to's hook reports it as a crash. Parsing moved intoschedule, which usesDuration::try_from_secs_f64, leaves out NaN (NaN.max(0.0)is 0, so it used to mean "now"), and sorts theDurations. Negative times still mean now.Not changed: the unwind still runs while the target thread is suspended. If that thread holds ntdll's function-table lock (a DLL load at that moment),
RtlLookupFunctionEntrycan block. Avoiding that would need unwinding over a copy of the stack after resuming it, which is a bigger change for another PR.Testing
cargo test -p victory-loader --features diagnostics: 20 + 2 passed. Includes the existinganother_threads_stack_unwinds_to_its_start, which goes through the reorderedframes_of, and 1 new test,schedules_skip_times_out_of_range.cargo test --workspace: 264 passed, 4 ignored (need external files).cargo clippy -p victory-loader --features diagnostics --all-targets: clean.cargo xtask policy: pass.rustfmt --checkonstacks.rs: clean.🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T05:16:46Z.
Thanks @AndyLatimer for guarding the diagnostic stack-dump schedule against unusable timeout values.
I tested commit
acdcc41687be2ecd2bf2efc43ab7449329483382with the feature that enables this module:The targeted test passed (1 passed, 0 failed; 19 filtered).
schedules_skip_times_out_of_rangechecks that a mixed schedule keeps valid 5- and 30-second entries, skips malformed, negative, infinite, NaN, and extremely large values, and returns an empty schedule for empty input.The same test filter without
--features diagnosticsselected zero tests because this module is feature-gated. The suspend-before-TEB-read path compiles with diagnostics enabled, but this test does not exercise its thread-suspension behavior or races in a live stack dump.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T09:04:57Z.
Review: APPROVED
Tested
acdcc41on Windows 11, RTX 5070, MSVC:cargo test --workspace --no-fail-fastpasses (264 passed, 0 failed), andcargo test -p victory-loader --features diagnostics --libpasses (20), includinganother_threads_stack_unwinds_to_its_startand the newschedules_skip_times_out_of_range.SuspendThreadahead of the TEB query closes a real use-after-free: anOpenThreadhandle doesn't keep the TEB mapped. Every exit path after the suspend now resumes.try_from_secs_f64plus the NaN filter removes the panic oninfor1e20, and the old quirk whereNaN.max(0.0)meant "now". Negative times still mean "now", as documented.No issues found.
AI-assisted (Claude Code).