take loader_lock in terminator_DestroySurfaceKHR - #2044
Merged
charles-lunarg merged 1 commit intoOct 1, 2026
Merged
Conversation
|
Author aizu-m not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
|
Author aizu-m not on autobuild list. Waiting for curator authorization before starting CI build. |
charles-lunarg
approved these changes
Oct 1, 2026
charles-lunarg
left a comment
Collaborator
There was a problem hiding this comment.
This is a very good find. Clear explanation of the problem and the fix. The test also reproduces when testing without the fix, making this a very easy approval.
|
CI Vulkan-Loader build queued with queue ID 140757. |
|
CI Vulkan-Loader build # 3795 running. |
|
CI Vulkan-Loader build # 3795 passed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ThreadSanitizer,
test_threadingbuilt with-D LOADER_ENABLE_THREAD_SANITIZER=ON, a few threads each creating and destroying their ownVkSurfaceKHR:M0 is
loader_lock. The reader holds it, the writer holds nothing. Found reading back through the surface terminators after #1946 and #1956.Every
terminator_Create*Surface*holdsloader_lockacrossallocate_icd_surface_struct, which reserves a slot inloader_inst->surfaces_listand initialises or doubles each driver'ssurface_list. Both of those can reallocate.terminator_DestroySurfaceKHRwalks and clears the same two lists with no lock, and thevkDestroySurfaceKHRtrampoline does not take one either. Only the surface needs external synchronisation, so destroying one surface while another thread creates a different one is legal.The reported race is on the slot status. The worse case is a resize landing between the destroy path's load of
surface_list.listand its store through that pointer, which is a write into freed memory.loader_release_object_from_listhas one call site and this was it. All threeloader_get_next_available_entrycall sites already hold the lock.Locking in the terminator rather than the trampoline keeps a layer calling down the chain covered, and puts the lock where the creation side already takes it.
loader_lockis recursive, so a caller that already holds it is unaffected. It is taken after the android/ios early-outs, so no return path escapes it.Threading.SurfaceCreateDestroyLoopreports the trace above on an unpatched loader and is clean after.