Skip to content

Commit

Permalink
teec: do fail on MAX_SIZE allocation requests
Browse files Browse the repository at this point in the history
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: d37a100 ("teec: use multiple of page size for page aligned buffers")
Signed-off-by: Jorge Ramirez-Ortiz <jorge@foundries.io>
  • Loading branch information
ldts committed Jan 16, 2024
1 parent 333e512 commit de022ca
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libteec/src/tee_client_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit de022ca

Please sign in to comment.