pvr: follow other drivers' practice for copying build ID
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

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>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40673>
This commit is contained in:
Icenowy Zheng 2026-03-27 19:06:09 +08:00 committed by Marge Bot
parent 7a8721e95c
commit 9870c8d8c4

View file

@ -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.");