mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:35:53 +01:00
[PR #1868] d3d12_xs: fix list-values relay UAF, overwritten WriteGroup relay, and pump start/stop races (RT-LIST-VALUES-RELAY-LIFECYCLE) #1880
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1880
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1868
Author: @ambroseautomation
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/rt-list-values-relay-lifecycle📝 Commits (1)
078dcc9RT-LIST-VALUES-RELAY-LIFECYCLE: fix relay UAF, overwritten WriteGroup relay, and pump start/stop races📊 Changes
4 files changed (+340 additions, -27 deletions)
View changed files
📝
runtime/CMakeLists.txt(+2 -0)📝
runtime/shims/d3d12_xs_device.cpp(+2 -2)📝
runtime/shims/d3d12_xs_list_values.h(+58 -25)📝
runtime/test/xs_proxy_mock_test.cpp(+278 -0)📄 Description
Coordination item:
RT-LIST-VALUES-RELAY-LIFECYCLE(claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163941870).Problem
Four safety and concurrency bugs in the console list-values subsystem (
runtime/shims/d3d12_xs_list_values.h,runtime/shims/d3d12_xs_device.cpp):ID3D12Fence*inPump::relay()(d3d12_xs_list_values.h:410,d3d12_xs_device.cpp:3548-3550):Pump::relay()looked up a matching in-flightWriteGroupundermutex_, handed out a raw pointergroup.queue->written, and releasedmutex_without retaininggroup.queue(std::shared_ptr<QueueValues>) or callingAddRef(). If the writer queue proxy was released while its write group was in flight, the pump thread could pop and land that group and destroyQueueValues(callingwritten->Release()) beforeValueSubmission::stand_at()finishedqueue->Wait(fence, value).Pump::relay()(d3d12_xs_list_values.h:410-422): All writes in aWriteGroupland together when its fence completes, butPump::relay()scannedgroup.writesforward and returned on the first matching write. A later write in the sameWriteGroupthat overwrites the cell with a non-matching value, overwrites it with a GPU/system timestamp, or partially overlaps[wait.address, wait.address + need)(e.g. a 32-bit write to the high or low half of a 64-bit waited cell) was ignored, falsely relaying the waiter onto a fence that leaves a non-meeting value.add_action()TOCTOU inPump::start()/Pump::stop()(d3d12_xs_list_values.h:389-489):Pump::start()wrotethread_andreleaser_insidestd::call_once, whilePump::stop()read them without synchronization: a concurrentstop()could race onthread_/releaser_and skip joining a started thread, and astart()afterstop()still spawned both threads.Pump::add_action()checkedstart()but did not checkexiting_undermutex_, leaving a TOCTOU window whereCopyPageMappingsBatchXcould enqueue an action gate afterstop_list_values()had begun and returnS_OKwithout running the remap.gate.waits.front()inPump::note_outcome()(d3d12_xs_list_values.h:968-972): Line 967 checked!gate.waits.empty(), but the logging block immediately below dereferencedgate.waits.front().addresswithout checking!gate.waits.empty().Changes
runtime/shims/d3d12_xs_list_values.h:Pump::relay()to takestd::shared_ptr<QueueValues>& ownerinstead of a rawID3D12Fence*&, keepingowner->writtenalive acrossqueue->Wait().Pump::relay()to scan eachWriteGroup's writes in reverse (rbegin()->rend()) with overflow-safe range checks over[wait.address, wait.address + need), relaying only when the last write overlapping the waited range is aWriteKind::valuecovering the full waited range that satisfiesconsole_value_met().std::once_flag start_withlifecycle_mutex_+start_attempted_+started_(acquire/release), sostart()never spawns threads afterstop(),stop()snapshots and joins every started thread without data races, andadd_writes()/add_gate()/add_action()checkexiting_(acquire) undermutex_.gate.waits.front()inPump::note_outcome()with!gate.waits.empty().runtime/shims/d3d12_xs_device.cpp:ValueSubmission::stand_at()to holdstd::shared_ptr<list_values::QueueValues> owneracrosswait(owner->written, value).runtime/test/xs_proxy_mock_test.cpp&runtime/CMakeLists.txt:check_list_values_relay_safety()covering:writes_insideWait, assertingfence->refs >= 1duringWaitand0after),WriteGroupvalue overwrite, timestamp overwrite, high-half 32-bit overlap, low-half 32-bit overlap, disjoint 32-bit low-half relay, and final-match positive relay.--list-values-stop-before-startCLI mode (registered as CTestxs_proxy_mock_list_values_stop_before_start) verifying idempotentstop_list_values()beforestart(), synchronousCopyPageMappingsBatchXfallback, post-stop drop of writes/gates, and clean refcount teardown.Verification
check_list_values_relay_safety()on unpatchedmain384abe5b0):wait_fence_seen == temp_written && wait_fence_refs >= 1(temp_written->refsdropped to0insidequeue->Wait(fence, value)).main5e95fa2f4, MSVC 14.51.36231/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2 /MD):xs_proxy_mock_test.exe(default +--list-values-stop-before-start+--slot133-layout+--env-slots+--env-slots-invalid+--env-slots-70+--env-slots-74+--fail-virtualalloc+--fail-virtualprotect+--fail-veh) — all 10 modes PASSroot_sig_test.exe— PASSdevice_proxy_test.exe— OK (0 failures)clang-cl/W4 /permissive- /utf-8 /std:c++20compile check onruntime/shims/d3d12_xs_device.cpp— exit 0, 0 new warningspython -I tests/test_ci_registration.py— 16/16 OKpython -I tests/test_build_runtime_fallback.py— 10/10 OKpython -I scripts/check_no_game_data.py runtime/shims/d3d12_xs_list_values.h runtime/shims/d3d12_xs_device.cpp runtime/test/xs_proxy_mock_test.cpp runtime/CMakeLists.txt— clean (exit 0)Hardware / Environment
clang-clAI-assisted: yes
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.