Skip to content

Commit 0aa171e

Browse files
ardbiesheuvelherbertx
authored andcommitted
crypto: ecdh - avoid buffer overflow in ecdh_set_secret()
Pavel reports that commit 17858b1 ("crypto: ecdh - avoid unaligned accesses in ecdh_set_secret()") fixes one problem but introduces another: the unconditional memcpy() introduced by that commit may overflow the target buffer if the source data is invalid, which could be the result of intentional tampering. So check params.key_size explicitly against the size of the target buffer before validating the key further. Fixes: 17858b1 ("crypto: ecdh - avoid unaligned accesses in ecdh_set_secret()") Reported-by: Pavel Machek <[email protected]> Cc: <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent fd16931 commit 0aa171e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

crypto/ecdh.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ static int ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,
3939
struct ecdh params;
4040
unsigned int ndigits;
4141

42-
if (crypto_ecdh_decode_key(buf, len, &params) < 0)
42+
if (crypto_ecdh_decode_key(buf, len, &params) < 0 ||
43+
params.key_size > sizeof(ctx->private_key))
4344
return -EINVAL;
4445

4546
ndigits = ecdh_supported_curve(params.curve_id);

0 commit comments

Comments
 (0)