VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   33 Branches   55 Tags
author: Ard Biesheuvel <ardb@kernel.org> 2020-11-24 11:47:19 +0100 committer: Herbert Xu <herbert@gondor.apana.org.au> 2020-12-04 18:13:13 +1100 commit: 17858b140bf49961b71d4e73f1c3ea9bc8e7dda0 parent: 05c2a705917b77e0915cca3551583583f4eafcf8
Commit Summary:
crypto: ecdh - avoid unaligned accesses in ecdh_set_secret()
Diffstat:
1 file changed, 5 insertions, 4 deletions
diff --git a/crypto/ecdh.c b/crypto/ecdh.c
index b0232d6ab4ce..d56b8603dec9 100644
--- a/crypto/ecdh.c
+++ b/crypto/ecdh.c
@@ -53,12 +53,13 @@ static int ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,
 		return ecc_gen_privkey(ctx->curve_id, ctx->ndigits,
 				       ctx->private_key);
 
-	if (ecc_is_key_valid(ctx->curve_id, ctx->ndigits,
-			     (const u64 *)params.key, params.key_size) < 0)
-		return -EINVAL;
-
 	memcpy(ctx->private_key, params.key, params.key_size);
 
+	if (ecc_is_key_valid(ctx->curve_id, ctx->ndigits,
+			     ctx->private_key, params.key_size) < 0) {
+		memzero_explicit(ctx->private_key, params.key_size);
+		return -EINVAL;
+	}
 	return 0;
 }