fix(loader,victory): non-atomic Clwb patching without FlushInstructionCache, LoaderLock unwind deadlock, and profiler handle/underflow bugs #321
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: launcher
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
run report
security: hold
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs gpu test
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Androtim--MiniVI#321
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@RUIZ-Enrique-25002136 on GitHub · 2026-12-02 09:14 UTC · original
Summary
Three concurrency, resource-lifetime, and live-patching issues exist in
crates/victory-loaderandapps/victory:FlushInstructionCache(victory-loader):ConsoleOnly::Clwboverwrites live executable bytes byte-by-byte with.fill(0x90)and omitsFlushInstructionCache.apps/victory):LoaderLock::holdleaves the re-entrant lock held forever iff()panics, andLateDlls::loadleaks mapped DLLs / stale registry entries ifbind_importsfails mid-loop.u64underflow in profiler (victory-loader):profile::ThreadlacksDrop(leaking handles on I/O errors inwrite()), andcpu()ignoresGetThreadTimesfailure, riskingu64underflow inchoose()andwrite().Evidence (
file:line& Code Proof)1. Non-Atomic
ConsoleOnly::ClwbPatching WithoutFlushInstructionCachecrates/victory-loader/src/console_insn.rs:425-438(emulate):Unlike
Monitorx/MwaitxandClzeroLoop(which usepatch(), executing atomiccmpxchg16b+FlushInstructionCache),ConsoleOnly::Clwbexecutes: Other threads executingripconcurrently can fetch a torn instruction (partial0x90prefix + tail bytes of the multi-byteclwbinstruction) or stale I-cache bytes.2.
LoaderLock::holdUnwind Deadlock &LateDlls::loadPartial-Failure Leakapps/victory/src/run.rs:769-787(LoaderLock::hold):owner.1 += 1is incremented beforelet result = f();and decremented/notified only afterf()returns normally (no RAII drop guard). Iff()unwinds, every subsequent dynamicLoadLibrarydeadlocks forever waiting onself.free.apps/victory/src/run.rs:715-726(LateDlls::load):If
dll.bind_imports(&resolver, self.policy)?fails on any DLL innew,?returns early beforemapped.extend(...)and bypasses the rollback loop (744-752), leaking WindowsLoadLibraryExWmodules,threads::IMAGESregistrations, andIMAGE_PATHSentries.3. Profiler Win32 Handle Leak &
u64Underflowcrates/victory-loader/src/profile.rs:51-59(cpu),134-138(choose),150-162(write):Threadhas noDropimpl;CloseHandle(t.handle)only runs insidewrite()afterFile::create(file)?and earlierwriteln!calls, so any I/O error leaks remaining open thread handles. Furthermore,cpu()ignores theBOOLreturn value ofGetThreadTimes(returning0on failure), andt.now - t.last(136) /t.now - t.first(157) use unchecked subtraction (panicking in debug or wrapping in release).AI-Ready Fix Specification
crates/victory-loader/src/console_insn.rs: RouteConsoleOnly::Clwbthroughpatch()(atomiccmpxchg16b+FlushInstructionCache), falling back to emulation without patching if the instruction crosses a 16-byte boundary orcmpxchg16bis unsupported.apps/victory/src/run.rs:LoaderLock::holdwith an RAII drop guard that decrementsowner.1, clearsowner.0at 0, and callsself.free.notify_one().LateDlls::load, roll back every already-loaded DLL innew(forget_image+dll.unload(), and clean upIMAGE_PATHSif needed) whenbind_importsfails.crates/victory-loader/src/profile.rs:Drop for Threadto callCloseHandle(self.handle)when non-null (and remove manualCloseHandlefromwrite()).GetThreadTimes(...) != 0incpu()(returningOption<u64>) and usesaturating_subfort.now.saturating_sub(t.last)andt.now.saturating_sub(t.first).cargo clippy --workspace --all-targets --locked -- -D warningsandcargo test --workspace --exclude victory-gpu --exclude victory-shader --lockedon Windows CI.github-bot referenced this issue2026-12-02 15:06:47 +00:00