Skip to content

clamp re-queried physical device count in setup_loader_term_phys_devs#1949

Merged
charles-lunarg merged 1 commit into
KhronosGroup:mainfrom
aizu-m:term-phys-devs-count-clamp
Jun 25, 2026
Merged

clamp re-queried physical device count in setup_loader_term_phys_devs#1949
charles-lunarg merged 1 commit into
KhronosGroup:mainfrom
aizu-m:term-phys-devs-count-clamp

Conversation

@aizu-m

@aizu-m aizu-m commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

setup_loader_term_phys_devs, the per-ICD two-call enumeration:

loader.c:6795  physical_devices = loader_stack_alloc(device_count * sizeof(VkPhysicalDevice));  // sizing query
loader.c:6806  EnumeratePhysicalDevices(icd_instance, &device_count, physical_devices);          // fill query
loader.c:6921  for (j = 0; j < device_count; ++j)
loader.c:6922      check_and_add_to_new_phys_devs(..., physical_devices[j], ...);

Walking the two calls: device_count is the same in/out variable for both, and the size handed to loader_stack_alloc is never kept. A driver that reports a larger device_count on the fill call than on the sizing call leaves the consume loop reading past the end of the stack array, and those out-of-bounds VkPhysicalDevice handles feed straight into the wrapped device list.

terminator_EnumeratePhysicalDeviceGroups already clamps its re-queried group count this way; the base vkEnumeratePhysicalDevices path was the one still trusting the second count. Snapshot the count before the fill call and clamp device_count back down to it.

The per-ICD physical_devices scratch array is sized from the first EnumeratePhysicalDevices query, then the fill call re-uses the same device_count as the in/out parameter. The allocated size was never kept, so a driver reporting a larger count on the fill call than on the sizing call drove the consume loop past the end of the stack array. Snapshot the allocated count and clamp device_count back to it.
@ci-tester-lunarg

Copy link
Copy Markdown

Author aizu-m not on autobuild list. Waiting for curator authorization before starting CI build.

1 similar comment
@ci-tester-lunarg

Copy link
Copy Markdown

Author aizu-m not on autobuild list. Waiting for curator authorization before starting CI build.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build queued with queue ID 18012.

@charles-lunarg charles-lunarg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More defensive checks for bad drivers, good with me.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3591 running.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3591 passed.

@charles-lunarg charles-lunarg merged commit e069cc2 into KhronosGroup:main Jun 25, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants