runtime: keep a timed-out present probe's staging buffer until its copy is done (RT-PRESENT-PROBE-TIMEOUT-UAF) #2224
Closed
leonida/mandy
Tyrannys wants to merge 0 commits from
rt-present-probe-timeout into main
pull from: rt-present-probe-timeout
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2224
Loading…
Reference in a new issue
No description provided.
Delete branch "rt-present-probe-timeout"
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 closed
This pull request cannot be reopened because the branch was deleted.
Claimed in the coordination issue as: RT-PRESENT-PROBE-TIMEOUT-UAF (ubiquitarianism/leonida#1608)
What and why
djrolfes found in #1608 (from reading the code) that the optional present-source readback probe (
LEONIDA_CAPTURE_SOURCE=1,probe_read_sourceinruntime/src/vulkan_present.h) frees its staging resources after a 5-second fence timeout, even though the GPU copy may still be running. It is real, and a bit wider than the buffer:vkQueueSubmit, a failedvkWaitForFencesrancleanup(). That freed the staging memory and destroyed the buffer the pending copy writes into.vkResetCommandBuffer,vkBeginCommandBufferandvkResetFenceson the probe's command buffer and fence while they were still pending, and submitted them again.Change (the probe only; nothing else in the presenter is affected):
probe_reclaim()runs at the start of each probe. It checks the fence without waiting (timeout 0). Once the fence has signalled, it frees the parked buffer and memory. Until then, that probe is skipped and logged, so the busy command buffer and fence are never reset.vkQueueWaitIdle, so nothing is left atvkDestroyDevice.Tested
New:
vk_presenter_probe_timeoutrunsvk_presenter_sync_test --probe-timeout. It needs no game files.VK_TIMEOUTat once.vkDestroyDevice, is 0.Results:
LEONIDA_VK_VALIDATION=1(0 errors).main'svulkan_present.h, the test fails: the buffer is freed while the copy is pending. Validation also reports VUID-vkResetCommandBuffer-commandBuffer-00045, VUID-vkBeginCommandBuffer-commandBuffer-00049, the in-use fence reset, and objects still alive atvkDestroyDevice.ctest -R "vk_presenter|vk_present_dump"(7 tests): all pass, plain and withLEONIDA_VK_VALIDATION=1.ctest -R "present|presenter|swapchain|capture"with validation: 14 of 15 pass.xbox_presentfails atpresent_planes(&one, 1)(VkResult -11) on this machine. It fails the same way withmain'svulkan_present.h, plain or under validation, so it is not caused by this change.tests/test_ctest_registration.pypasses.scripts/check_no_game_data.pyon the changed files is clean. The game was not run.Built with Ninja and MSVC on
maina73a57e13.GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
RTX 3090 / 621.40, validation on, current main a73a57e13: this PR's vk_presenter_probe_timeout plus main's vulkan_present.h hits VUID-vkQueueSubmit-pCommandBuffers-00071, a WRITE_AFTER_WRITE on the probe buffer, and 2 leaked objects (VkBuffer + VkDeviceMemory, VUID-vkDestroyDevice-device-05137) on 5/5 runs. With this PR the same test is clean. Present ctest is 13/14 on main vs 14/15 with the PR; the only failure on both is xbox_present (VkResult -11).
I reviewed
ea7b88bcby reading the code against maina73a57e13. My Windows PC is down today, so there is no build or run in this comment. ammonium231's RTX 3090 run above already covers the failing and fixed sides.The fix reads right to me. These are the paths I checked:
~VulkanPresenterdoesvkQueueWaitIdle(queue_)unconditionally under the submit turn, not only when there is a swapchain. Only after that doesprobe_reclaim(true)free the parked buffer and memory. The probe submits on that samequeue_, so its copy is done by then.probe_reclaim(false)runs before any new record or submit, so a second timed-out readback cannot overwrite a buffer that is still parked. It also covers the second probe of the same present (the"target"call at line 811): it is skipped as well, instead of resetting the busy command buffer and fence.VK_ERROR_DEVICE_LOST, the fence never signals.probe_reclaim(false)then returns false for good, and every later probe is skipped and logged. For a diagnostic behindLEONIDA_CAPTURE_SOURCE=1that is the right outcome. The destructor still frees the parked objects after its idle wait, and freeing them is allowed after a loss.One question, probably outside this PR. After a timeout the held copy still reads the source image, not only the staging buffer.
resource_lockis released before the submit, andvulkan_backend.h:1738says present and probe submissions have their own fences, outside the queue retirement timelines. So if the title destroys that resource while the copy is held, is its destruction ordered after the probe's fence? I think it is ordered whenqueue_is also one of the context's replay queues: a later retire-ticket signal on the same queue covers the earlier probe submission. I don't think it is ordered when the presenter has its own queue. After a 5 s timeout the device is most likely gone anyway, so I would not hold the PR for this. A sentence in the description saying the fix covers the staging buffer and the probe's own command buffer and fence would make the scope clear.AI-assisted (Claude Code).
#2224 | head ea7b88bc48293a5bd1766fb810ba4816a2a28eed (merged cleanly onto origin/main 48bae6cade) | Windows 11 (10.0.26200.9974), MSVC 19.44.35228.0, NVIDIA GeForce RTX 3090, Python 3.12.10 | AI-assisted: yes
Independent Verification (Windows 11 + MSVC + RTX 3090)
runtime/CMakeLists.txt,runtime/src/vulkan_present.h,runtime/test/vk_presenter_probe_timeout.h, andruntime/test/vk_presenter_sync_test.cpp.python -I scripts/check_no_game_data.pypassed (rc=0), andpython -I tests/test_ctest_registration.pypassed (7/7 OK).MSVC 19.44.35228.0, CMake + NinjaRelWithDebInfo, NVIDIA GeForce RTX 3090):origin/main48bae6cadevulkan_present.h+#2224--probe-timeoutharness): Builtvk_presenter_sync_test.exeagainst unpatchedruntime/src/vulkan_present.hand ranvk_presenter_sync_test.exe --probe-timeouton RTX 3090 -> exited1: on the timed-out fence wait ([rt] present-probe: readback submit/wait failed (0)),cleanup()freed the staging buffer/memory while the copy was still held on the timeline semaphore (freed_in_flight = true) and the next present immediately reset/resubmitted the in-flightprobe_commands_andprobe_fence_.#2224 + origin/main48bae6cade): Rebuiltvk_presenter_sync_test.exewith patchedruntime/src/vulkan_present.h(probe_reclaim+probe_parked_buffer_/probe_parked_memory_) and ran all three CTest targets on RTX 3090:vk_presenter_sync_test.exe->vk_presenter_sync_test: ok(rc=0)vk_presenter_sync_test.exe --sparse-capture->sparse capture: frames 1/4, cap, last-fence drain, explicit readback, disk and splash-only handoffs verified(rc=0)vk_presenter_sync_test.exe --probe-timeout->vk_presenter_sync_test --probe-timeout: ok(rc=0; loggedreadback wait failed (2); its buffer is freed once the copy is done, skipped the busy probe on the in-flight frame, reclaimed and read backsource frame 3once signalled, and returned expectedpresent 0..3 = {0, -1, 0, 0}).LEONIDA_VK_VALIDATION=1withoutVK_LAYER_KHRONOS_validationinstalled cleanly exits77(SKIP_RETURN_CODE 77).TAKEN by OreoFR (Windows, RTX 4070 8 GB)
Verified by OreoFR — READY
vk_presenter_probe_timeoutfails on main at line 181 (kept): after the forced fence timeout, main frees the staging buffer while the held copy is still pending.vk_presenter_syncandvk_presenter_sparse_capturepass on main and on the merge.vk_presenter_probe_timeoutpasses; ctest (Ninja RelWithDebInfo, all targets, gta6rt launchers excluded) in package p3 = main + #2179 + #2224 (no shared files): 506 tests, new failures vs main: none.xmem_no_write_watch,d3d12_meshandd3d12_mesh_heavy_cachefailed in the parallel run and pass when re-run alone (main alone: 505 tests, 6 failures: big_compile_gate and api_ref_state and d3d12_queue_wait_timeout timeouts, xs_proxy_mock, vk_compile_gate_calibration, xbox_present; xbox_present fails in every package as on main)LEONIDA_CARGO=OFF,LEONIDA_XMA2_DECODER_LIBempty) in package p3; imports unchanged vs main (25 DLLs, 755 functions, no WS2_32)probe_fence_has signalled (it skips its own readback until then), and the destructor frees them after its queue wait, before the fence is destroyed.Ready to merge per the maintainers' plan.
AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.
Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (
d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools,d3d12/, or general docs), please feel free to reopen it.