Skip to content

Commit

Permalink
core: elf_load_body(): use MUL_OVERFLOW() to get size of section headers
Browse files Browse the repository at this point in the history
At the end of elf_load_body(), section headers are copied in a system heap
memory block, associated to state->shdr. As the computed size is the
result of an uncontrolled multiplication (ehdr.e_shnum * ehdr.e_shentsize),
it could have overflowed and result in allocating a small memory block.

Use an overflow checking macro to prevent this case.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reported-by: Bastien Simondi <bsimondi@netflix.com> [1.7]
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
  • Loading branch information
jforissier committed Feb 25, 2019
1 parent bcc81cf commit 5787ecd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/arch/arm/kernel/elf_load.c
Expand Up @@ -585,8 +585,11 @@ TEE_Result elf_load_body(struct elf_load_state *state, vaddr_t vabase)
*/ */
if (ehdr.e_shoff) { if (ehdr.e_shoff) {
/* We have section headers */ /* We have section headers */
res = alloc_and_copy_to(&p, state, ehdr.e_shoff, size_t sz = 0;
ehdr.e_shnum * ehdr.e_shentsize);
if (MUL_OVERFLOW(ehdr.e_shnum, ehdr.e_shentsize, &sz))
return TEE_ERROR_OUT_OF_MEMORY;
res = alloc_and_copy_to(&p, state, ehdr.e_shoff, sz);
if (res != TEE_SUCCESS) if (res != TEE_SUCCESS)
return res; return res;
state->shdr = p; state->shdr = p;
Expand Down

0 comments on commit 5787ecd

Please sign in to comment.