Repository navigation
Conversation
…py is done (RT-PRESENT-PROBE-TIMEOUT-UAF) The optional present-source readback probe (LEONIDA_CAPTURE_SOURCE) freed its staging buffer and memory when its 5-second fence wait failed, although the copy it had submitted could still be running, and the next probe reset and resubmitted the same command buffer and fence while they were pending. On a failed wait after a successful submit the buffer and memory are now parked. A later probe frees them once the fence has signalled and skips its readback until then; the destructor frees them after its queue wait. A failed submit still frees them at once. vk_presenter_sync_test --probe-timeout holds the probe's copy on a timeline semaphore and makes its fence wait time out, then checks that nothing in use is freed, the next probe does not resubmit, readbacks resume once the copy is done, and validation reports nothing up to and including vkDestroyDevice. Found by djrolfes in ProjectLeonida#1608. AI-assisted (Claude Code).
|
RTX 3090 / 621.40, validation on, current main a73a57e: 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 The fix reads right to me. These are the paths I checked:
One question, probably outside this PR. After a timeout the held copy still reads the source image, not only the staging buffer. AI-assisted (Claude Code). |
|
#2224 | head ea7b88b (merged cleanly onto origin/main 48bae6c) | 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)
|
timbot103
left a comment
There was a problem hiding this comment.
I reviewed head ea7b88bc4 against its declared base and the supplied main snapshot. This was a static audit only. I ran no builds, tests, or GPU workloads.
The fence poll in runtime/src/vulkan_present.h:818 prevents command-buffer and fence reuse while the copy is pending and bounds deferred staging to one allocation per presenter. The timeout path and teardown still have two lifetime gaps.
- Major —
runtime/src/vulkan_present.h:231. Teardown forces reclamation even ifvkQueueWaitIdlereturns an error such asVK_ERROR_OUT_OF_HOST_MEMORY. A pending copy can lose its staging, fence, and command pool. Require completion or confirmed device loss before destroying those objects, and cover the failed idle wait in the regression test. - Major —
runtime/src/vulkan_present.h:974. The source image can still retire while a timed-out probe reads it.runtime/src/vulkan_backend.h:1738describes the probe's fence as outside the retirement timelines, and the image can be destroyed after the next retirement ticket completes on another queue. Register a lifetime dependency for the source and its backing through probe completion. - Minor —
runtime/test/vk_presenter_probe_timeout.h:152. A scheduling pause can let the fixed delay expire before the third present checks the pending probe. That makes correct code fail the submission-count check. Signal at the queue-idle step that follows the probe attempt. - Minor —
runtime/test/vk_presenter_probe_timeout.h:166. With validation disabled, the test can pass when the probe resumes and both parked objects leak. Assert that the hooks observed both the buffer destroy and the memory free.
AI-assisted.
|
TAKEN by OreoFR (Windows, RTX 4070 8 GB) |
|
Verified by OreoFR — READY
Ready to merge per the maintainers' plan. AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR. |
Claimed in the coordination issue as: RT-PRESENT-PROBE-TIMEOUT-UAF (#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
maina73a57e.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