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

Open
github-bot wants to merge 1 commit from github-bot/gh-594 into main AGit
Owner

@⁠tahffo68hk-hash on GitHub · 2026-11-24 09:26 UTC · original
tahffo68hk-hash:fix/vk-queue-bindless-semaphore-uaf → main · +176 −2 · 3 files · 1 commits · open

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 辅助:是。
**@⁠tahffo68hk-hash** on GitHub · 2026-11-24 09:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/594) `tahffo68hk-hash:fix/vk-queue-bindless-semaphore-uaf` → `main` · +176 −2 · 3 files · 1 commits · open ## 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>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:10:40 +00:00
Author
Owner

@⁠trigger337 on GitHub · 2026-11-24 09:49 UTC · original

Hardware verification report for vk_queue_bindless_uaf_test on native AMD RDNA2 GPU:

Environment:

  • GPU: AMD Radeon RX 6900 XT (RADV NAVI21, RDNA2, subgroup size 32..64)
  • Driver: Mesa 26.2.5-cachyos1.1 (Vulkan 1.4.333)
  • Host: Linux CachyOS (x86_64, kernel 7.3.1-2-cachyos)
  • Compiler: GCC 15.2.1 / CMake 4.2.0-rc2
  • Tree: PR #594 (fix/vk-queue-bindless-semaphore-uaf)

Execution & Results:

  • Target: cmake --build runtime/build/linux --target vk_queue_bindless_uaf_test
  • Binary output:
    device: AMD Radeon RX 6900 XT (RADV NAVI21)
    subgroup sizes: 32..64 (default 64), requirable in stages 0xf0, subgroupSizeControl on, computeFullSubgroups on
    vk_queue_bindless_uaf_test: PASS (0 dangling waits, GPU readback verified)
    
  • CTest: ctest --test-dir runtime/build/linux -R vk_queue_bindless_uaf: 1/1 passed.

Confirms zero dangling waits and verified GPU copy readback on physical AMD Radeon RX 6900 XT under Vulkan 1.4.

agent: yes
AI-assisted: yes

**@⁠trigger337** on GitHub · 2026-11-24 09:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/594#issuecomment-7127943399) Hardware verification report for `vk_queue_bindless_uaf_test` on native AMD RDNA2 GPU: **Environment:** - GPU: AMD Radeon RX 6900 XT (RADV NAVI21, RDNA2, subgroup size 32..64) - Driver: Mesa 26.2.5-cachyos1.1 (Vulkan 1.4.333) - Host: Linux CachyOS (x86_64, kernel 7.3.1-2-cachyos) - Compiler: GCC 15.2.1 / CMake 4.2.0-rc2 - Tree: PR #594 (`fix/vk-queue-bindless-semaphore-uaf`) **Execution & Results:** - Target: `cmake --build runtime/build/linux --target vk_queue_bindless_uaf_test` - Binary output: ``` device: AMD Radeon RX 6900 XT (RADV NAVI21) subgroup sizes: 32..64 (default 64), requirable in stages 0xf0, subgroupSizeControl on, computeFullSubgroups on vk_queue_bindless_uaf_test: PASS (0 dangling waits, GPU readback verified) ``` - CTest: `ctest --test-dir runtime/build/linux -R vk_queue_bindless_uaf`: 1/1 passed. Confirms zero dangling waits and verified GPU copy readback on physical AMD Radeon RX 6900 XT under Vulkan 1.4. agent: yes AI-assisted: yes
This pull request has changes conflicting with the target branch.
  • runtime/CMakeLists.txt
  • runtime/src/vulkan_backend.h
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/594/head:github-bot/gh-594'
git switch 'github-bot/gh-594'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-594'
git switch 'github-bot/gh-594'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-594'
git switch 'github-bot/gh-594'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-594'
git switch 'main'
git merge --squash 'github-bot/gh-594'
git switch 'main'
git merge --ff-only 'github-bot/gh-594'
git switch 'main'
git merge 'github-bot/gh-594'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.