lib: rsa: fix data abort in br_i32_decode()
PATCH 1/1 lib: rsa: fix data abort in br_i32_decode()
After removing leading zeros the RSA modulus may be unaligned. On architectures like ARM 32bit unaligned access may lead to a data abort, e.g. when executing 'ut lib lib_asn1_pkcs7'.
Use memcpy() to transfer from unaligned to aligned memory.
--- lib/rsa/rsa-keyprop.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
lib/rsa/rsa-keyprop.c +14 -8
@@ -17,23 +17,29 @@#include <u-boot/rsa-mod-exp.h> /** -* br_dec16be() - Convert 16-bit big-endian integer to native -* @src: Pointer to data -* Return: Native-endian integer +* br_dec16be() - convert unaligned 16-bit big-endian integer to native +* @src: unaligned pointer to data +* Return: native-endian 16-bit integer */ static unsigned br_dec16be (const void *src) { -return be16_to_cpup (src); +u16 buf; + +memcpy (&buf, src,sizeof (buf)); +return be16_to_cpu (buf); }/** -* br_dec32be() - Convert 32-bit big-endian integer to native -* @src: Pointer to data -* Return: Native-endian integer +* br_dec32be() - convert unaligned 32-bit big-endian integer to native +* @src: unaligned pointer to data +* Return: native-endian 32-bit integer */ static uint32_t br_dec32be (const void *src) { -return be32_to_cpup (src); +u32 buf; + +memcpy (&buf, src,sizeof (buf)); +return be32_to_cpu (buf); }/**
--
2.20.1
PATCH 1/1 lib: rsa: fix data abort in br_i32_decode()
HI Heinrich,
Quoted 11 lines · Heinrich Schuchardt
After removing leading zeros the RSA modulus may be unaligned. On architectures like ARM 32bit unaligned access may lead to a data abort, e.g. when executing 'ut lib
lib_asn1_pkcs7'.Use
memcpy()to transfer from unaligned to aligned memory.Signed-off-by Heinrich Schuchardt <[email protected]>--- lib/rsa/rsa-keyprop.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
Quoted 13 lines
lib/rsa/rsa-keyprop.c +1
-3@@ -17,23 +17,29 @@#include <u-boot/rsa-mod-exp.h> /** -* br_dec16be() - Convert 16-bit big-endian integer to native -* @src: Pointer to data -* Return: Native-endian integer +* br_dec16be() - convert unaligned 16-bit big-endian integer to native
lib/rsa/rsa-keyprop.c line 29
Quoted 10 lines
lib/rsa/rsa-keyprop.c +6
-1+* @src: unaligned pointer to data +* Return: native-endian 16-bit integer */ static unsigned br_dec16be (const void *src) { -return be16_to_cpup (src); +u16 buf; + +memcpy (&buf, src,sizeof (buf)); +return be16_to_cpu (buf);
Is it possible to use __get_unaligned_be() ?
Regards,
Simon
PATCH 1/1 lib: rsa: fix data abort in br_i32_decode()
Quoted 34 lines · Simon Glass
HI Heinrich,
Quoted 11 lines · Heinrich Schuchardt
After removing leading zeros the RSA modulus may be unaligned. On architectures like ARM 32bit unaligned access may lead to a data abort, e.g. when executing 'ut lib
lib_asn1_pkcs7'.Use
memcpy()to transfer from unaligned to aligned memory.Signed-off-by Heinrich Schuchardt <[email protected]>--- lib/rsa/rsa-keyprop.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)Reviewed-by Simon Glass <[email protected]>Quoted 17 lines
lib/rsa/rsa-keyprop.c +3
-3@@ -17,23 +17,29 @@#include <u-boot/rsa-mod-exp.h> /** -* br_dec16be() - Convert 16-bit big-endian integer to native -* @src: Pointer to data -* Return: Native-endian integer +* br_dec16be() - convert unaligned 16-bit big-endian integer to native +* @src: unaligned pointer to data +* Return: native-endian 16-bit integer */ static unsigned br_dec16be (const void *src)
Quoted 8 lines
lib/rsa/rsa-keyprop.c line 29
Quoted 6 lines
lib/rsa/rsa-keyprop.c +4
-1{ -return be16_to_cpup (src); +u16 buf; + +memcpy (&buf, src,sizeof (buf)); +return be16_to_cpu (buf);Is it possible to use
__get_unaligned_be()?
Robert has sent the fix here:
https://lists.denx.de/pipermail/u-boot/2020-September/425949.html
I think it's better.
-Takahiro Akashi
Quoted 2 lines
Regards,
Simon