* [PATCH] crypto: ecdh - avoid buffer overflow in ecdh_set_secret()
@ 2021-01-02 13:59 Ard Biesheuvel
2021-01-02 22:10 ` Herbert Xu
0 siblings, 1 reply; 2+ messages in thread
From: Ard Biesheuvel @ 2021-01-02 13:59 UTC (permalink / raw)
To: linux-crypto; +Cc: herbert, pavel, Ard Biesheuvel
Pavel reports that commit 17858b140bf4 ("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: 17858b140bf4 ("crypto: ecdh - avoid unaligned accesses in ecdh_set_secret()")
Reported-by: Pavel Machek <pavel@denx.de>
Cc: <stable@vger.kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
crypto/ecdh.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/crypto/ecdh.c b/crypto/ecdh.c
index d56b8603dec9..96f80c8f8e30 100644
--- a/crypto/ecdh.c
+++ b/crypto/ecdh.c
@@ -39,7 +39,8 @@ static int ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,
struct ecdh params;
unsigned int ndigits;
- if (crypto_ecdh_decode_key(buf, len, ¶ms) < 0)
+ if (crypto_ecdh_decode_key(buf, len, ¶ms) < 0 ||
+ params.key_size > sizeof(ctx->private_key))
return -EINVAL;
ndigits = ecdh_supported_curve(params.curve_id);
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] crypto: ecdh - avoid buffer overflow in ecdh_set_secret()
2021-01-02 13:59 [PATCH] crypto: ecdh - avoid buffer overflow in ecdh_set_secret() Ard Biesheuvel
@ 2021-01-02 22:10 ` Herbert Xu
0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2021-01-02 22:10 UTC (permalink / raw)
To: Ard Biesheuvel; +Cc: linux-crypto, pavel
On Sat, Jan 02, 2021 at 02:59:09PM +0100, Ard Biesheuvel wrote:
> Pavel reports that commit 17858b140bf4 ("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: 17858b140bf4 ("crypto: ecdh - avoid unaligned accesses in ecdh_set_secret()")
> Reported-by: Pavel Machek <pavel@denx.de>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
> crypto/ecdh.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-01-02 22:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-02 13:59 [PATCH] crypto: ecdh - avoid buffer overflow in ecdh_set_secret() Ard Biesheuvel
2021-01-02 22:10 ` Herbert Xu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.