From 1313787c125234b2fca5cafa4a85f115917813c8 Mon Sep 17 00:00:00 2001 From: Asahi Lina Date: Fri, 3 Mar 2023 21:35:56 +0900 Subject: [PATCH] asahi: Do not overread user index buffers We need to align the extent to 4 for the GPU, but we can't copy more than the original size out of the user buffer. Always alloc the exact size we need. This does mean the GPU gets an IB extent that could include some other stuff later in the pool, if not aligned. This is probably safe? Given the base alignment, it should never cross a page boundary and fault or anything like that. Signed-off-by: Asahi Lina Part-of: --- src/gallium/drivers/asahi/agx_state.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 4367ac2cf19..cb0edba9c54 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -2389,8 +2389,9 @@ agx_index_buffer_direct_ptr(struct agx_batch *batch, } else { *extent = ALIGN_POT(draw->count * info->index_size, 4); - return agx_pool_upload_aligned( - &batch->pool, ((uint8_t *)info->index.user) + offset, *extent, 64); + return agx_pool_upload_aligned(&batch->pool, + ((uint8_t *)info->index.user) + offset, + draw->count * info->index_size, 64); } }