mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:10:53 +01:00
[PR #2224] runtime: keep a timed-out present probe's staging buffer until its copy is done (RT-PRESENT-PROBE-TIMEOUT-UAF) #2228
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#2228
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/2224
Author: @Tyrannys
Created: 11/26/2026
Status: 🔄 Open
Base:
main← Head:rt-present-probe-timeout📝 Commits (1)
ea7b88bruntime: keep a timed-out present probe's staging buffer until its copy is done (RT-PRESENT-PROBE-TIMEOUT-UAF)📊 Changes
4 files changed (+322 additions, -5 deletions)
View changed files
📝
runtime/CMakeLists.txt(+2 -1)📝
runtime/src/vulkan_present.h(+38 -4)➕
runtime/test/vk_presenter_probe_timeout.h(+190 -0)📝
runtime/test/vk_presenter_sync_test.cpp(+92 -0)📄 Description
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
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.