* [PATCH 1/1] lib: rsa: fix data abort in br_i32_decode()
@ 2020-09-08 10:29 Heinrich Schuchardt
2020-09-08 23:56 ` Simon Glass
0 siblings, 1 reply; 3+ messages in thread
From: Heinrich Schuchardt @ 2020-09-08 10:29 UTC (permalink / raw)
To: u-boot
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 <xypron.glpk@gmx.de>
---
lib/rsa/rsa-keyprop.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/lib/rsa/rsa-keyprop.c b/lib/rsa/rsa-keyprop.c
index 1e83eedc82..6153cb00b3 100644
--- a/lib/rsa/rsa-keyprop.c
+++ b/lib/rsa/rsa-keyprop.c
@@ -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
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 1/1] lib: rsa: fix data abort in br_i32_decode()
2020-09-08 10:29 [PATCH 1/1] lib: rsa: fix data abort in br_i32_decode() Heinrich Schuchardt
@ 2020-09-08 23:56 ` Simon Glass
2020-09-10 0:15 ` AKASHI Takahiro
0 siblings, 1 reply; 3+ messages in thread
From: Simon Glass @ 2020-09-08 23:56 UTC (permalink / raw)
To: u-boot
HI Heinrich,
On Tue, 8 Sep 2020 at 04:29, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> 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 <xypron.glpk@gmx.de>
> ---
> lib/rsa/rsa-keyprop.c | 22 ++++++++++++++--------
> 1 file changed, 14 insertions(+), 8 deletions(-)
Reviewed-by: Simon Glass <sjg@chromium.org>
>
> diff --git a/lib/rsa/rsa-keyprop.c b/lib/rsa/rsa-keyprop.c
> index 1e83eedc82..6153cb00b3 100644
> --- a/lib/rsa/rsa-keyprop.c
> +++ b/lib/rsa/rsa-keyprop.c
> @@ -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);
Is it possible to use __get_unaligned_be() ?
Regards,
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH 1/1] lib: rsa: fix data abort in br_i32_decode()
2020-09-08 23:56 ` Simon Glass
@ 2020-09-10 0:15 ` AKASHI Takahiro
0 siblings, 0 replies; 3+ messages in thread
From: AKASHI Takahiro @ 2020-09-10 0:15 UTC (permalink / raw)
To: u-boot
On Tue, Sep 08, 2020 at 05:56:06PM -0600, Simon Glass wrote:
> HI Heinrich,
>
> On Tue, 8 Sep 2020 at 04:29, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> >
> > 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 <xypron.glpk@gmx.de>
> > ---
> > lib/rsa/rsa-keyprop.c | 22 ++++++++++++++--------
> > 1 file changed, 14 insertions(+), 8 deletions(-)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> >
> > diff --git a/lib/rsa/rsa-keyprop.c b/lib/rsa/rsa-keyprop.c
> > index 1e83eedc82..6153cb00b3 100644
> > --- a/lib/rsa/rsa-keyprop.c
> > +++ b/lib/rsa/rsa-keyprop.c
> > @@ -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);
>
> 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
> Regards,
> Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-09-10 0:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-08 10:29 [PATCH 1/1] lib: rsa: fix data abort in br_i32_decode() Heinrich Schuchardt
2020-09-08 23:56 ` Simon Glass
2020-09-10 0:15 ` AKASHI Takahiro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox