OSDN Git Service

crypto: ecdh - avoid unaligned accesses in ecdh_set_secret()
authorArd Biesheuvel <ardb@kernel.org>
Tue, 24 Nov 2020 10:47:19 +0000 (11:47 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 4 Dec 2020 07:13:13 +0000 (18:13 +1100)
commit17858b140bf49961b71d4e73f1c3ea9bc8e7dda0
tree89b0f162292703ef55bf19475fc3156da73b96f8
parent05c2a705917b77e0915cca3551583583f4eafcf8
crypto: ecdh - avoid unaligned accesses in ecdh_set_secret()

ecdh_set_secret() casts a void* pointer to a const u64* in order to
feed it into ecc_is_key_valid(). This is not generally permitted by
the C standard, and leads to actual misalignment faults on ARMv6
cores. In some cases, these are fixed up in software, but this still
leads to performance hits that are entirely avoidable.

So let's copy the key into the ctx buffer first, which we will do
anyway in the common case, and which guarantees correct alignment.

Cc: <stable@vger.kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/ecdh.c