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

Closed
tahffo68hk-hash wants to merge 1 commit from upstream-pr/594 into main
tahffo68hk-hash commented 2026-11-24 09:26:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tahffo68hk-hash on 2026-11-24T09:26:48Z.


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 辅助:是。
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5469502156 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/594). Originally posted by [tahffo68hk-hash](https://github.com/tahffo68hk-hash) on 2026-11-24T09:26:48Z. --- ## 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>
trigger337 commented 2026-11-24 09:49:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-24T09:49:38Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7127943399 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/594#issuecomment-7127943399). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T09:49:38Z. --- 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
MoonEyes commented 2026-11-27 23:20:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T23:20:04Z.


Hi @tahffo68hk-hash, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/CMakeLists.txt, runtime/src/vulkan_backend.h), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7230059493 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/594#issuecomment-7230059493). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T23:20:04Z. --- Hi @tahffo68hk-hash, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/CMakeLists.txt`, `runtime/src/vulkan_backend.h`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
DadaCap commented 2026-11-28 10:34:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T10:34:26Z.


Thanks for the contribution! This PR was reviewed by the maintainers and is being closed as part of a large batch of closures.

Reason: superseded by main.

If this looks like a mistake, mention @DadaCap here at any time and it will be looked at again.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237984179 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/594#issuecomment-7237984179). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T10:34:26Z. --- Thanks for the contribution! This PR was reviewed by the maintainers and is being closed as part of a large batch of closures. Reason: superseded by main. If this looks like a mistake, mention @DadaCap here at any time and it will be looked at again. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!594
No description provided.