[PR #594] vulkan_backend: clear bindless_upload_semaphore_ in ~VulkanQueue (VK-QUEUE-BINDLESS-SEMAPHORE-UAF) #635

Open
opened 2026-11-26 20:18:33 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/594
Author: @tahffo68hk-hash
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/vk-queue-bindless-semaphore-uaf


📝 Commits (1)

  • 0c436ae vulkan_backend: clear bindless_upload_semaphore_ in ~VulkanQueue (VK-QUEUE-BINDLESS-SEMAPHORE-UAF)

📊 Changes

3 files changed (+176 additions, -2 deletions)

View changed files

📝 runtime/CMakeLists.txt (+15 -0)
📝 runtime/src/vulkan_backend.h (+3 -2)
➕ runtime/test/vk_queue_bindless_uaf_test.cpp (+158 -0)

📄 Description

Summary

When a VulkanQueue submits a command buffer carrying a new bindless descriptor table generation (context_.note_bindless_upload()), VulkanQueue::execute() publishes its own timeline semaphore progress_ into context_.bindless_upload_semaphore_ (under storage_mutex_) so other queues wait on it before binding the new generation.

In ~VulkanQueue() (runtime/src/vulkan_backend.h), after vkQueueWaitIdle(queue_) completes and before vkDestroySemaphore(device, progress_, nullptr) destroys progress_, ~VulkanQueue() cleared context_.storage_init_semaphore_ when it matched progress_, but did not clear context_.bindless_upload_semaphore_. Any other queue executing afterwards saw a non-null bindless_upload_semaphore_ with a newer bindless_upload_version_ and passed the destroyed VkSemaphore handle to vkQueueSubmit() in pWaitSemaphores (use-after-free / VUID-VkSubmitInfo-pWaitSemaphores-parameter).

Fix

  • Clear context_.bindless_upload_semaphore_ = VK_NULL_HANDLE alongside context_.storage_init_semaphore_ under context_.storage_mutex_ in ~VulkanQueue() (runtime/src/vulkan_backend.h).
  • Add a real Vulkan GPU regression test runtime/test/vk_queue_bindless_uaf_test.cpp (registered as vk_queue_bindless_uaf in runtime/CMakeLists.txt) that:
    1. Executes a real GPU copy on Queue A with context.note_bindless_upload().
    2. Destroys Queue A (recording destroyed VkSemaphore handles via vkDestroySemaphore).
    3. Executes a real GPU copy + host readback on Queue B, asserting zero destroyed semaphores are passed to vkQueueSubmit() and that the GPU copy readback matches expected bytes.

Verification (Real Dual-GPU Hardware)

  • Before fix on NVIDIA GeForce RTX 5060 Ti:
    FAIL runtime/test/vk_queue_bindless_uaf_test.cpp:150: driver::dangling_wait_hits.load() == 0
  • After fix on NVIDIA GeForce RTX 5060 Ti:
    vk_queue_bindless_uaf_test: PASS (0 dangling waits, GPU readback verified)
  • After fix on AMD Radeon(TM) Graphics (GFX1036):
    vk_queue_bindless_uaf_test: PASS (0 dangling waits, GPU readback verified)

Coordination

  • Claimed on #14 as VK-QUEUE-BINDLESS-SEMAPHORE-UAF (no overlapping open PRs or claims).
  • AI-assisted: yes.
中文翻译

摘要

当某个 VulkanQueue 提交携带新一代 bindless 描述符表上传的命令缓冲(调用 context_.note_bindless_upload())时,VulkanQueue::execute() 会将该队列的 timeline semaphore progress_ 发布到 context_.bindless_upload_semaphore_,供其他队列在后续提交时等待。

在 ~VulkanQueue()(runtime/src/vulkan_backend.h)等待队列空闲并销毁 progress_ 之前,代码只清理了匹配的 context_.storage_init_semaphore_,遗漏了 context_.bindless_upload_semaphore_。此后其他队列执行提交时会把已销毁的 VkSemaphore 句柄传入 vkQueueSubmit() 的 pWaitSemaphores,构成跨队列悬空句柄使用(use-after-free / VUID-VkSubmitInfo-pWaitSemaphores-parameter)。

修复

  • 在 ~VulkanQueue() 的 storage_mutex_ 临界区内同步清理匹配的 context_.bindless_upload_semaphore_ = VK_NULL_HANDLE。
  • 新增真实 Vulkan GPU 回归测试 runtime/test/vk_queue_bindless_uaf_test.cpp(CMake 注册名 vk_queue_bindless_uaf):Queue A 发布 bindless 上传并销毁后,Queue B 执行真实 GPU 拷贝并主机读回,验证 vkQueueSubmit 不再传入已销毁的 semaphore 且读回数据正确。

真实双卡 GPU 验证

  • 修复前(NVIDIA RTX 5060 Ti):直接复现 dangling_wait_hits != 0 失败。
  • 修复后(NVIDIA RTX 5060 Ti):PASS (0 dangling waits, GPU readback verified)。
  • 修复后(AMD Radeon Graphics / GFX1036):PASS (0 dangling waits, GPU readback verified)。

协同

  • 已在 #14 认领 VK-QUEUE-BINDLESS-SEMAPHORE-UAF。
  • AI 辅助:是。

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/594 **Author:** [@tahffo68hk-hash](https://github.com/tahffo68hk-hash) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/vk-queue-bindless-semaphore-uaf` --- ### 📝 Commits (1) - [`0c436ae`](https://github.com/ubiquitarianism/leonida/commit/0c436ae3d2aa13e3b5c3665b167b049956006201) vulkan_backend: clear bindless_upload_semaphore_ in ~VulkanQueue (VK-QUEUE-BINDLESS-SEMAPHORE-UAF) ### 📊 Changes **3 files changed** (+176 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+15 -0) 📝 `runtime/src/vulkan_backend.h` (+3 -2) ➕ `runtime/test/vk_queue_bindless_uaf_test.cpp` (+158 -0) </details> ### 📄 Description ## Summary When a `VulkanQueue` submits a command buffer carrying a new bindless descriptor table generation (`context_.note_bindless_upload()`), `VulkanQueue::execute()` publishes its own timeline semaphore `progress_` into `context_.bindless_upload_semaphore_` (under `storage_mutex_`) so other queues wait on it before binding the new generation. In `~VulkanQueue()` (`runtime/src/vulkan_backend.h`), after `vkQueueWaitIdle(queue_)` completes and before `vkDestroySemaphore(device, progress_, nullptr)` destroys `progress_`, `~VulkanQueue()` cleared `context_.storage_init_semaphore_` when it matched `progress_`, **but did not clear `context_.bindless_upload_semaphore_`**. Any other queue executing afterwards saw a non-null `bindless_upload_semaphore_` with a newer `bindless_upload_version_` and passed the destroyed `VkSemaphore` handle to `vkQueueSubmit()` in `pWaitSemaphores` (use-after-free / `VUID-VkSubmitInfo-pWaitSemaphores-parameter`). ### Fix - Clear `context_.bindless_upload_semaphore_ = VK_NULL_HANDLE` alongside `context_.storage_init_semaphore_` under `context_.storage_mutex_` in `~VulkanQueue()` (`runtime/src/vulkan_backend.h`). - Add a real Vulkan GPU regression test `runtime/test/vk_queue_bindless_uaf_test.cpp` (registered as `vk_queue_bindless_uaf` in `runtime/CMakeLists.txt`) that: 1. Executes a real GPU copy on Queue A with `context.note_bindless_upload()`. 2. Destroys Queue A (recording destroyed `VkSemaphore` handles via `vkDestroySemaphore`). 3. Executes a real GPU copy + host readback on Queue B, asserting zero destroyed semaphores are passed to `vkQueueSubmit()` and that the GPU copy readback matches expected bytes. ### Verification (Real Dual-GPU Hardware) - **Before fix** on NVIDIA GeForce RTX 5060 Ti: `FAIL runtime/test/vk_queue_bindless_uaf_test.cpp:150: driver::dangling_wait_hits.load() == 0` - **After fix** on **NVIDIA GeForce RTX 5060 Ti**: `vk_queue_bindless_uaf_test: PASS (0 dangling waits, GPU readback verified)` - **After fix** on **AMD Radeon(TM) Graphics (GFX1036)**: `vk_queue_bindless_uaf_test: PASS (0 dangling waits, GPU readback verified)` ### Coordination - Claimed on #14 as `VK-QUEUE-BINDLESS-SEMAPHORE-UAF` (no overlapping open PRs or claims). - AI-assisted: yes. <details> <summary>中文翻译</summary> ## 摘要 当某个 `VulkanQueue` 提交携带新一代 bindless 描述符表上传的命令缓冲(调用 `context_.note_bindless_upload()`)时,`VulkanQueue::execute()` 会将该队列的 timeline semaphore `progress_` 发布到 `context_.bindless_upload_semaphore_`,供其他队列在后续提交时等待。 在 `~VulkanQueue()`(`runtime/src/vulkan_backend.h`)等待队列空闲并销毁 `progress_` 之前,代码只清理了匹配的 `context_.storage_init_semaphore_`,**遗漏了 `context_.bindless_upload_semaphore_`**。此后其他队列执行提交时会把已销毁的 `VkSemaphore` 句柄传入 `vkQueueSubmit()` 的 `pWaitSemaphores`,构成跨队列悬空句柄使用(use-after-free / `VUID-VkSubmitInfo-pWaitSemaphores-parameter`)。 ### 修复 - 在 `~VulkanQueue()` 的 `storage_mutex_` 临界区内同步清理匹配的 `context_.bindless_upload_semaphore_ = VK_NULL_HANDLE`。 - 新增真实 Vulkan GPU 回归测试 `runtime/test/vk_queue_bindless_uaf_test.cpp`(CMake 注册名 `vk_queue_bindless_uaf`):Queue A 发布 bindless 上传并销毁后,Queue B 执行真实 GPU 拷贝并主机读回,验证 `vkQueueSubmit` 不再传入已销毁的 semaphore 且读回数据正确。 ### 真实双卡 GPU 验证 - **修复前(NVIDIA RTX 5060 Ti)**:直接复现 `dangling_wait_hits != 0` 失败。 - **修复后(NVIDIA RTX 5060 Ti)**:`PASS (0 dangling waits, GPU readback verified)`。 - **修复后(AMD Radeon Graphics / GFX1036)**:`PASS (0 dangling waits, GPU readback verified)`。 ### 协同 - 已在 #14 认领 `VK-QUEUE-BINDLESS-SEMAPHORE-UAF`。 - AI 辅助:是。 </details> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#635
No description provided.