intel/executor: Add an overflow check for alloc function

Assisted-by: Pi coding agent (GPT-5.5)
Acked-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41610>
This commit is contained in:
Caio Oliveira 2026-05-12 15:32:15 -07:00
parent 3522f0f24c
commit 8d237b5408

View file

@ -348,12 +348,17 @@ executor_alloc_bytes(executor_bo *bo, uint32_t size)
void *
executor_alloc_bytes_aligned(executor_bo *bo, uint32_t size, uint32_t alignment)
{
void *r = bo->cursor;
if (alignment) {
r = (void *)(((uintptr_t)r + alignment-1) & ~((uintptr_t)alignment-1));
}
bo->cursor = r + size;
return r;
uintptr_t r = (uintptr_t)bo->cursor;
if (alignment)
r = (r + alignment - 1) & ~((uintptr_t)alignment - 1);
uint64_t offset = r - (uintptr_t)bo->map;
if (offset > bo->size || size > bo->size - offset)
failf("executor BO overflow");
void *ptr = (void *)r;
bo->cursor = ptr + size;
return ptr;
}
executor_address