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: acb0885 ("teec: use multiple of page size for page aligned buffers")
Signed-off-by: Jorge Ramirez-Ortiz <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
  • Loading branch information
ldts authored and jforissier committed Jan 16, 2024
1 parent 333e512 commit f7e4ced
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion libteec/src/tee_client_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f7e4ced

Please sign in to comment.