Skip to content

loader: fix heap overflow when registry path exceeds reg_data buffer#1916

Open
aizu-m wants to merge 1 commit into
KhronosGroup:mainfrom
aizu-m:reg-data-buffer-growth
Open

loader: fix heap overflow when registry path exceeds reg_data buffer#1916
aizu-m wants to merge 1 commit into
KhronosGroup:mainfrom
aizu-m:reg-data-buffer-growth

Conversation

@aizu-m
Copy link
Copy Markdown
Contributor

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

Reading the registry path code I noticed reg_data is allocated at total_size (4096 by default) but each snprintf in windows_add_json_entry is bounded by json_size, the registry value size that windows_get_device_registry_entry reads with RegQueryValueEx (and the D3DKMT adapter query passes in). That size is uncapped. Pulling the buffer logic out into a small harness, a 9000-byte driver/layer JSON path lands like this:

buffer capacity=4096, wrote=9000 bytes, canary bytes clobbered=16/16

The NULL branch never checks json_size against total_size, and the realloc branch only doubles the size once, so any single REG_SZ/REG_MULTI_SZ path longer than the buffer overflows it.

Grow the buffer until the value actually fits and bound each snprintf by the remaining destination space. windows_get_registry_files has the same single-double plus source-length-bounded snprintf shape (its name is capped at 2048 so it is only an off-by-one at the capacity boundary) and gets the same treatment.

@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 761419.

@ci-tester-lunarg
Copy link
Copy Markdown

CI Vulkan-Loader build # 3506 running.

@ci-tester-lunarg
Copy link
Copy Markdown

CI Vulkan-Loader build # 3506 aborted.

@ci-tester-lunarg
Copy link
Copy Markdown

CI Vulkan-Loader build queued with queue ID 761647.

@ci-tester-lunarg
Copy link
Copy Markdown

CI Vulkan-Loader build # 3508 running.

@ci-tester-lunarg
Copy link
Copy Markdown

CI Vulkan-Loader build # 3508 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.

2 participants