* [PATCH] crypto: ecc: handle unaligned input buffer in ecc_swap_digits
@ 2021-07-21 8:39 Mian Yousaf Kaukab
2021-07-21 12:10 ` Stefan Berger
2021-07-30 3:11 ` Herbert Xu
0 siblings, 2 replies; 3+ messages in thread
From: Mian Yousaf Kaukab @ 2021-07-21 8:39 UTC (permalink / raw)
To: linux-crypto, linux-kernel
Cc: stefanb, davem, herbert, tiwai, guillaume.gardet, Mian Yousaf Kaukab
ecdsa_set_pub_key() makes an u64 pointer at 1 byte offset of the key.
This results in an unaligned u64 pointer. This pointer is passed to
ecc_swap_digits() which assumes natural alignment.
This causes a kernel crash on an armv7 platform:
[ 0.409022] Unhandled fault: alignment exception (0x001) at 0xc2a0a6a9
...
[ 0.416982] PC is at ecdsa_set_pub_key+0xdc/0x120
...
[ 0.491492] Backtrace:
[ 0.492059] [<c07c266c>] (ecdsa_set_pub_key) from [<c07c75d4>] (test_akcipher_one+0xf4/0x6c0)
Handle unaligned input buffer in ecc_swap_digits() by replacing
be64_to_cpu() to get_unaligned_be64(). Change type of in pointer to
void to reflect it doesn’t necessarily need to be aligned.
Fixes: 4e6602916bc6 ("crypto: ecdsa - Add support for ECDSA signature verification")
Reported-by: Guillaume Gardet <guillaume.gardet@arm.com>
Suggested-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de>
---
crypto/ecc.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/crypto/ecc.h b/crypto/ecc.h
index a006132646a4..1350e8eb6ac2 100644
--- a/crypto/ecc.h
+++ b/crypto/ecc.h
@@ -27,6 +27,7 @@
#define _CRYPTO_ECC_H
#include <crypto/ecc_curve.h>
+#include <asm/unaligned.h>
/* One digit is u64 qword. */
#define ECC_CURVE_NIST_P192_DIGITS 3
@@ -46,13 +47,13 @@
* @out: Output array
* @ndigits: Number of digits to copy
*/
-static inline void ecc_swap_digits(const u64 *in, u64 *out, unsigned int ndigits)
+static inline void ecc_swap_digits(const void *in, u64 *out, unsigned int ndigits)
{
const __be64 *src = (__force __be64 *)in;
int i;
for (i = 0; i < ndigits; i++)
- out[i] = be64_to_cpu(src[ndigits - 1 - i]);
+ out[i] = get_unaligned_be64(&src[ndigits - 1 - i]);
}
/**
--
2.26.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: ecc: handle unaligned input buffer in ecc_swap_digits
2021-07-21 8:39 [PATCH] crypto: ecc: handle unaligned input buffer in ecc_swap_digits Mian Yousaf Kaukab
@ 2021-07-21 12:10 ` Stefan Berger
2021-07-30 3:11 ` Herbert Xu
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Berger @ 2021-07-21 12:10 UTC (permalink / raw)
To: Mian Yousaf Kaukab, linux-crypto, linux-kernel
Cc: davem, herbert, tiwai, guillaume.gardet
On 7/21/21 4:39 AM, Mian Yousaf Kaukab wrote:
> ecdsa_set_pub_key() makes an u64 pointer at 1 byte offset of the key.
> This results in an unaligned u64 pointer. This pointer is passed to
> ecc_swap_digits() which assumes natural alignment.
>
> This causes a kernel crash on an armv7 platform:
> [ 0.409022] Unhandled fault: alignment exception (0x001) at 0xc2a0a6a9
> ...
> [ 0.416982] PC is at ecdsa_set_pub_key+0xdc/0x120
> ...
> [ 0.491492] Backtrace:
> [ 0.492059] [<c07c266c>] (ecdsa_set_pub_key) from [<c07c75d4>] (test_akcipher_one+0xf4/0x6c0)
>
> Handle unaligned input buffer in ecc_swap_digits() by replacing
> be64_to_cpu() to get_unaligned_be64(). Change type of in pointer to
> void to reflect it doesn’t necessarily need to be aligned.
>
> Fixes: 4e6602916bc6 ("crypto: ecdsa - Add support for ECDSA signature verification")
> Reported-by: Guillaume Gardet <guillaume.gardet@arm.com>
> Suggested-by: Takashi Iwai <tiwai@suse.de>
> Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de>
Tested-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
> crypto/ecc.h | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/crypto/ecc.h b/crypto/ecc.h
> index a006132646a4..1350e8eb6ac2 100644
> --- a/crypto/ecc.h
> +++ b/crypto/ecc.h
> @@ -27,6 +27,7 @@
> #define _CRYPTO_ECC_H
>
> #include <crypto/ecc_curve.h>
> +#include <asm/unaligned.h>
>
> /* One digit is u64 qword. */
> #define ECC_CURVE_NIST_P192_DIGITS 3
> @@ -46,13 +47,13 @@
> * @out: Output array
> * @ndigits: Number of digits to copy
> */
> -static inline void ecc_swap_digits(const u64 *in, u64 *out, unsigned int ndigits)
> +static inline void ecc_swap_digits(const void *in, u64 *out, unsigned int ndigits)
> {
> const __be64 *src = (__force __be64 *)in;
> int i;
>
> for (i = 0; i < ndigits; i++)
> - out[i] = be64_to_cpu(src[ndigits - 1 - i]);
> + out[i] = get_unaligned_be64(&src[ndigits - 1 - i]);
> }
>
> /**
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: ecc: handle unaligned input buffer in ecc_swap_digits
2021-07-21 8:39 [PATCH] crypto: ecc: handle unaligned input buffer in ecc_swap_digits Mian Yousaf Kaukab
2021-07-21 12:10 ` Stefan Berger
@ 2021-07-30 3:11 ` Herbert Xu
1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2021-07-30 3:11 UTC (permalink / raw)
To: Mian Yousaf Kaukab
Cc: linux-crypto, linux-kernel, stefanb, davem, tiwai, guillaume.gardet
On Wed, Jul 21, 2021 at 10:39:05AM +0200, Mian Yousaf Kaukab wrote:
> ecdsa_set_pub_key() makes an u64 pointer at 1 byte offset of the key.
> This results in an unaligned u64 pointer. This pointer is passed to
> ecc_swap_digits() which assumes natural alignment.
>
> This causes a kernel crash on an armv7 platform:
> [ 0.409022] Unhandled fault: alignment exception (0x001) at 0xc2a0a6a9
> ...
> [ 0.416982] PC is at ecdsa_set_pub_key+0xdc/0x120
> ...
> [ 0.491492] Backtrace:
> [ 0.492059] [<c07c266c>] (ecdsa_set_pub_key) from [<c07c75d4>] (test_akcipher_one+0xf4/0x6c0)
>
> Handle unaligned input buffer in ecc_swap_digits() by replacing
> be64_to_cpu() to get_unaligned_be64(). Change type of in pointer to
> void to reflect it doesn’t necessarily need to be aligned.
>
> Fixes: 4e6602916bc6 ("crypto: ecdsa - Add support for ECDSA signature verification")
> Reported-by: Guillaume Gardet <guillaume.gardet@arm.com>
> Suggested-by: Takashi Iwai <tiwai@suse.de>
> Signed-off-by: Mian Yousaf Kaukab <ykaukab@suse.de>
> ---
> crypto/ecc.h | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
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] 3+ messages in thread
end of thread, other threads:[~2021-07-30 3:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-21 8:39 [PATCH] crypto: ecc: handle unaligned input buffer in ecc_swap_digits Mian Yousaf Kaukab
2021-07-21 12:10 ` Stefan Berger
2021-07-30 3:11 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).