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: 6a42493c94 ("pvr: Use BUILD_ID_EXPECTED_HASH_LENGTH")
Signed-off-by: Icenowy Zheng <zhengxingda@iscas.ac.cn>
Reviewed-by: Ella Stanforth <ella@igalia.com>
(cherry picked from commit 9870c8d8c4)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41269>
This commit is contained in:
Icenowy Zheng 2026-03-27 19:06:09 +08:00 committed by Eric Engestrom
parent 342f9fb5da
commit ca1923a820
2 changed files with 5 additions and 4 deletions

View file

@ -4454,7 +4454,7 @@
"description": "pvr: follow other drivers' practice for copying build ID",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "6a42493c94b669108a36d0c83f1ab0c6c67397ba",
"notes": null

View file

@ -306,7 +306,7 @@ out:
}
static bool
pvr_get_driver_build_sha(uint8_t sha_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;
@ -323,7 +323,8 @@ pvr_get_driver_build_sha(uint8_t sha_out[const static BUILD_ID_EXPECTED_HASH_LEN
return false;
}
memcpy(sha_out, build_id_data(note), BUILD_ID_EXPECTED_HASH_LENGTH);
STATIC_ASSERT(sizeof(instance->driver_build_sha) == SHA1_DIGEST_LENGTH);
copy_build_id_to_sha1(instance->driver_build_sha, note);
return true;
}
@ -373,7 +374,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.");