From f412bac00ae038ba12177b1a60d90695ec405db6 Mon Sep 17 00:00:00 2001 From: Jorge Ramirez-Ortiz Date: Tue, 16 Jan 2024 09:12:40 +0100 Subject: [PATCH] teec: do fail on MAX_SIZE allocation requests The variable aligned_sz will be 0 when the requested sz is MAX_SIZE. Since posix_memalign can return a valid pointer for zero size allocations, share memory registration requests for MAX_SIZE might make it to the kernel. This PR stops it early - just as it was before "teec: use multiple of page size for page aligned buffers" was merged. Fixes: acb0885c117e ("teec: use multiple of page size for page aligned buffers") Signed-off-by: Jorge Ramirez-Ortiz Reviewed-by: Jens Wiklander --- libteec/src/tee_client_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libteec/src/tee_client_api.c b/libteec/src/tee_client_api.c index 6d398ab9..b7507452 100644 --- a/libteec/src/tee_client_api.c +++ b/libteec/src/tee_client_api.c @@ -82,7 +82,7 @@ static void *teec_paged_aligned_alloc(size_t sz) size_t page_sz = sysconf(_SC_PAGESIZE); size_t aligned_sz = ((sz + page_sz - 1) / page_sz) * page_sz; - if (!posix_memalign(&p, page_sz, aligned_sz)) + if (aligned_sz >= sz && !posix_memalign(&p, page_sz, aligned_sz)) return p; return NULL;