Skip to content

Commit

Permalink
core: fix possible overflow in shdr_alloc_and_copy()
Browse files Browse the repository at this point in the history
Prior to this patch, if SHDR_GET_SIZE() overflows it will return 0 and
further down in the function lead to an out-of-bounds access. So fix
this with an explicit test before using shdr_size in
shdr_alloc_and_copy().

Fixes: 064663e ("core: crypto: add struct shdr helper functions")
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
  • Loading branch information
jenswi-linaro authored and jforissier committed May 22, 2024
1 parent 78444d3 commit 6b5d112
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion core/crypto/signed_hdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct shdr *shdr_alloc_and_copy(size_t offs, const void *img, size_t img_size)
return NULL;

shdr_size = SHDR_GET_SIZE((const struct shdr *)(img_va + offs));
if (ADD_OVERFLOW(offs, shdr_size, &end) || end > img_size)
if (!shdr_size || ADD_OVERFLOW(offs, shdr_size, &end) || end > img_size)
return NULL;

if (ADD_OVERFLOW(img_va, shdr_size, &tmp))
Expand Down

0 comments on commit 6b5d112

Please sign in to comment.