From de022ca0f6c7a4934bcacf7e7c6bf03cb0f46da6 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: d37a10035e06 ("teec: use multiple of page size for page aligned buffers") Signed-off-by: Jorge Ramirez-Ortiz --- libteec/src/tee_client_api.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libteec/src/tee_client_api.c b/libteec/src/tee_client_api.c index 6d398ab9..bb1c8372 100644 --- a/libteec/src/tee_client_api.c +++ b/libteec/src/tee_client_api.c @@ -82,7 +82,8 @@ 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)) + /* aligned_sz will be null if MAX_SIZE was requested */ + if (aligned_sz && !posix_memalign(&p, page_sz, aligned_sz)) return p; return NULL;