From 9870c8d8c4bfff16f2c60f378742d144242f08e6 Mon Sep 17 00:00:00 2001 From: Icenowy Zheng Date: Fri, 27 Mar 2026 19:06:09 +0800 Subject: [PATCH] pvr: follow other drivers' practice for copying build ID Previously the output length of pvr_get_driver_build_sha() is changed to BUILD_ID_EXPECTED_HASH_LENGTH, but the array defined to receive its output, the driver_build_sha array inside struct pvr_instance, is declared with BLAKE3_KEY_LEN, which is longer than BUILD_ID_EXPECTED_HASH_LENGTH. This leads to uninitialized memory being accessed when creating pipelineCacheUUID value, and the pipelineCacheUUID value would become random in each run, defecting the purpose of it. Refactor the code copying the build ID to follow other drivers: changing the parameter from the buffer to the instance pointer, inserting a static assert thanks to being able to retrieve the destination buffer length (as an array inside the instance structure) and using copy_build_id_to_sha1() to do the final copy. Fixes: 6a42493c94b6 ("pvr: Use BUILD_ID_EXPECTED_HASH_LENGTH") Signed-off-by: Icenowy Zheng Reviewed-by: Ella Stanforth Part-of: --- src/imagination/vulkan/pvr_instance.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/imagination/vulkan/pvr_instance.c b/src/imagination/vulkan/pvr_instance.c index d8112af81fa..9ff8648f208 100644 --- a/src/imagination/vulkan/pvr_instance.c +++ b/src/imagination/vulkan/pvr_instance.c @@ -297,7 +297,7 @@ out: } static bool -pvr_get_driver_build_sha(uint8_t blake3_out[const static BUILD_ID_EXPECTED_HASH_LENGTH]) +pvr_get_driver_build_sha(struct pvr_instance *instance) { const struct build_id_note *note; unsigned build_id_len; @@ -314,7 +314,8 @@ pvr_get_driver_build_sha(uint8_t blake3_out[const static BUILD_ID_EXPECTED_HASH_ return false; } - memcpy(blake3_out, build_id_data(note), BUILD_ID_EXPECTED_HASH_LENGTH); + STATIC_ASSERT(sizeof(instance->driver_build_sha) == BLAKE3_KEY_LEN); + copy_build_id_to_sha1(instance->driver_build_sha, note); return true; } @@ -364,7 +365,7 @@ VkResult pvr_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false)); - if (!pvr_get_driver_build_sha(instance->driver_build_sha)) { + if (!pvr_get_driver_build_sha(instance)) { result = vk_errorf(NULL, VK_ERROR_INITIALIZATION_FAILED, "Failed to get driver build sha.");