Skip to content

Commit

Permalink
crypto: ecdh_helper - Ensure 'len >= secret.len' in decode_key()
Browse files Browse the repository at this point in the history
The length ('len' parameter) passed to crypto_ecdh_decode_key() is never
checked against the length encoded in the passed buffer ('buf'
parameter). This could lead to an out-of-bounds access when the passed
length is less than the encoded length.

Add a check to prevent that.

Fixes: 3c4b239 ("crypto: ecdh - Add ECDH software support")
Signed-off-by: Daniele Alessandrelli <daniele.alessandrelli@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
dalessan authored and herbertx committed Feb 10, 2021
1 parent 578f23d commit a53ab94
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crypto/ecdh_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ int crypto_ecdh_decode_key(const char *buf, unsigned int len,
if (secret.type != CRYPTO_KPP_SECRET_TYPE_ECDH)
return -EINVAL;

if (unlikely(len < secret.len))
return -EINVAL;

ptr = ecdh_unpack_data(&params->curve_id, ptr, sizeof(params->curve_id));
ptr = ecdh_unpack_data(&params->key_size, ptr, sizeof(params->key_size));
if (secret.len != crypto_ecdh_key_len(params))
Expand Down

0 comments on commit a53ab94

Please sign in to comment.