lib: rsa: fix allocated size for rr and rrtmp in

A patch from »lib: rsa: distinguish between tpl and spl for« in state Mainline for u-boot

From: Heiko Stuebner <heiko.stuebner@...> Date: Wed, 20 May 2020 20:09:58 +0200

Commit-Message

When calculating rrtmp/rr rsa_gen_key_prop() tries to make (((rlen + 31) >> 5) + 1) steps in the rr uint32_t array and (((rlen + 7) >> 3) + 1) / 4 steps in uint32_t rrtmp[] with rlen being num_bits * 2 On a 4096bit key this comes down to to 257 uint32_t elements in rr and 256 elements in rrtmp but with the current allocation rr and rrtmp only have 129 uint32_t elements. On 2048bit keys this works by chance as the defined max_rsa_size=4096 allocates a suitable number of elements, but with an actual 4096bit key this results in other memory parts getting overwritten. so double the number of elements in rr and rrtmp so that it matches the needed number and should increase nicely if max_rsa_size gets increased in the future. Signed-off-by: Heiko Stuebner <heiko.stuebner@...>

Patch-Comment

changes in v4: - new patch lib/rsa/rsa-keyprop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)

Statistics

  • 2 lines added
  • 2 lines removed

Changes

---------------------------- lib/rsa/rsa-keyprop.c -----------------------------
index 4b54db44c4..e28fbb7472 100644
@@ -659,8 +659,8 @@ int rsa_gen_key_prop(const void *key, uint32_t keylen, struct key_prop **prop)
*prop = calloc(sizeof(**prop), 1);
n = calloc(sizeof(uint32_t), 1 + (max_rsa_size >> 5));
- rr = calloc(sizeof(uint32_t), 1 + (max_rsa_size >> 5));
- rrtmp = calloc(sizeof(uint32_t), 1 + (max_rsa_size >> 5));
+ rr = calloc(sizeof(uint32_t), 1 + ((max_rsa_size * 2) >> 5));
+ rrtmp = calloc(sizeof(uint32_t), 1 + ((max_rsa_size * 2) >> 5));
if (!(*prop) || !n || !rr || !rrtmp) {
ret = -ENOMEM;
goto err;
 
 

Recent Patches

About Us

Sed lacus. Donec lectus. Nullam pretium nibh ut turpis. Nam bibendum. In nulla tortor, elementum vel, tempor at, varius non, purus. Mauris vitae nisl nec metus placerat consectetuer.

Read More...