Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1389413 > unrolled thread

[PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl

Started bySowmini Varadhan <sowmini.varadhan@oracle.com>
First post2016-04-27 19:50 +0200
Last post2016-05-04 13:10 +0200
Articles 7 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl Sowmini Varadhan <sowmini.varadhan@oracle.com> - 2016-04-27 19:50 +0200
    Re: [PATCH v2] lib/mpi: Fix kernel unaligned access in  mpi_write_to_sgl Herbert Xu <herbert@gondor.apana.org.au> - 2016-04-28 03:10 +0200
      Re: [PATCH v2] lib/mpi: Fix kernel unaligned access in  mpi_write_to_sgl Sowmini Varadhan <sowmini.varadhan@oracle.com> - 2016-04-28 03:10 +0200
        Re: [PATCH v2] lib/mpi: Fix kernel unaligned access in  mpi_write_to_sgl Herbert Xu <herbert@gondor.apana.org.au> - 2016-05-03 10:20 +0200
          Re: [PATCH v2] lib/mpi: Fix kernel unaligned access in  mpi_write_to_sgl Sowmini Varadhan <sowmini.varadhan@oracle.com> - 2016-05-03 12:30 +0200
            Re: [PATCH v2] lib/mpi: Fix kernel unaligned access in  mpi_write_to_sgl Herbert Xu <herbert@gondor.apana.org.au> - 2016-05-04 04:40 +0200
              Re: [PATCH v2] lib/mpi: Fix kernel unaligned access in  mpi_write_to_sgl Sowmini Varadhan <sowmini.varadhan@oracle.com> - 2016-05-04 13:10 +0200

#1389413 — [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl

FromSowmini Varadhan <sowmini.varadhan@oracle.com>
Date2016-04-27 19:50 +0200
Subject[PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl
Message-ID<rsBL4-59n-13@gated-at.bofh.it>
Commit 2d4d1eea540b ("lib/mpi: Add mpi sgl helpers") added
mpi_write_to_sgl() which generates traps due to unaligned
access on some platforms like sparc. Fix this by using
the get_unaligned* and put_unaligned* functions.

Fixes: 2d4d1eea540b ("lib/mpi: Add mpi sgl helpers")
Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
---
v2: tadeusz.struk comments: Predicate on BYTES_PER_MPI_LIMB.

 lib/mpi/mpicoder.c |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c
index eb15e7d..b61eb6b 100644
--- a/lib/mpi/mpicoder.c
+++ b/lib/mpi/mpicoder.c
@@ -21,6 +21,7 @@
 #include <linux/bitops.h>
 #include <linux/count_zeros.h>
 #include "mpi-internal.h"
+#include <asm/unaligned.h>
 
 #define MAX_EXTERN_MPI_BITS 16384
 
@@ -405,10 +406,22 @@ int mpi_write_to_sgl(MPI a, struct scatterlist *sgl, unsigned *nbytes,
 				p -= sizeof(alimb);
 				continue;
 			} else {
-				mpi_limb_t *limb1 = (void *)p - sizeof(alimb);
-				mpi_limb_t *limb2 = (void *)p - sizeof(alimb)
-							+ lzeros;
-				*limb1 = *limb2;
+				mpi_limb_t tmp;
+#if BYTES_PER_MPI_LIMB == 4
+				tmp = get_unaligned_be32((void *)p -
+							 sizeof(alimb) +
+							 lzeros);
+				put_unaligned_be32(tmp, (void *)p -
+						   sizeof(alimb));
+#elif BYTES_PER_MPI_LIMB == 8
+				tmp = get_unaligned_be64((void *)p -
+							 sizeof(alimb) +
+							 lzeros);
+				put_unaligned_be64(tmp, (void *)p -
+						   sizeof(alimb));
+#else
+#error please implement for this limb size.
+#endif
 				p -= lzeros;
 				y = lzeros;
 			}
-- 
1.7.1

[toc] | [next] | [standalone]


#1389710 — Re: [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl

FromHerbert Xu <herbert@gondor.apana.org.au>
Date2016-04-28 03:10 +0200
SubjectRe: [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl
Message-ID<rsICS-2JI-7@gated-at.bofh.it>
In reply to#1389413
On Wed, Apr 27, 2016 at 01:43:56PM -0400, Sowmini Varadhan wrote:
> 
> Commit 2d4d1eea540b ("lib/mpi: Add mpi sgl helpers") added
> mpi_write_to_sgl() which generates traps due to unaligned
> access on some platforms like sparc. Fix this by using
> the get_unaligned* and put_unaligned* functions.
> 
> Fixes: 2d4d1eea540b ("lib/mpi: Add mpi sgl helpers")
> Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>

Please cc linux-crypto.

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

[toc] | [prev] | [next] | [standalone]


#1389723 — Re: [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl

FromSowmini Varadhan <sowmini.varadhan@oracle.com>
Date2016-04-28 03:10 +0200
SubjectRe: [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl
Message-ID<rsICT-2JI-33@gated-at.bofh.it>
In reply to#1389710
On (04/28/16 09:01), Herbert Xu wrote:
> Subject: Re: [PATCH v2] lib/mpi: Fix kernel unaligned access in
>  mpi_write_to_sgl
> 
> Please cc linux-crypto.

Just bounced the message to linux-crypto as well. 
I think get_maintainers.pl might also need to be updated to 
generate this automatically.

Thanks,
--Sowmini

[toc] | [prev] | [next] | [standalone]


#1393154 — Re: [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl

FromHerbert Xu <herbert@gondor.apana.org.au>
Date2016-05-03 10:20 +0200
SubjectRe: [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl
Message-ID<ruDIK-4pf-9@gated-at.bofh.it>
In reply to#1389723
On Wed, Apr 27, 2016 at 09:08:27PM -0400, Sowmini Varadhan wrote:
> On (04/28/16 09:01), Herbert Xu wrote:
> > Subject: Re: [PATCH v2] lib/mpi: Fix kernel unaligned access in
> >  mpi_write_to_sgl
> > 
> > Please cc linux-crypto.
> 
> Just bounced the message to linux-crypto as well. 
> I think get_maintainers.pl might also need to be updated to 
> generate this automatically.

Sorry, but your patch doesn't apply against the current tree at all.
Please rebase it if it is still needed.

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

[toc] | [prev] | [next] | [standalone]


#1393310 — Re: [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl

FromSowmini Varadhan <sowmini.varadhan@oracle.com>
Date2016-05-03 12:30 +0200
SubjectRe: [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl
Message-ID<ruFKy-6sc-23@gated-at.bofh.it>
In reply to#1393154
On (05/03/16 16:12), Herbert Xu wrote:
> 
> Sorry, but your patch doesn't apply against the current tree at all.
> Please rebase it if it is still needed.

Hello,

I had based my patch off of net-next, which is where I do my work.

I'd be happy to rebase it on the "current tree", 
but given that mpicoder.c does not have an entry in MAINTAINERS, 
please clarify what you mean by "current tree" in this case.

do you mean

 git://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
or
 git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6.git
or 
 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

(which are the three possible candidates I can see in MAINTAINERS).

It would be nice to get this bug fixed, since the fix is fairly
obvious, and the nuisance factor from the generated "unaligned
access" messages on the impacted non-intel platforms is quite high, 

thanks,
--Sowmini

[toc] | [prev] | [next] | [standalone]


#1393905 — Re: [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl

FromHerbert Xu <herbert@gondor.apana.org.au>
Date2016-05-04 04:40 +0200
SubjectRe: [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl
Message-ID<ruUTg-3mC-1@gated-at.bofh.it>
In reply to#1393310
On Tue, May 03, 2016 at 06:19:15AM -0400, Sowmini Varadhan wrote:
> On (05/03/16 16:12), Herbert Xu wrote:
> > 
> > Sorry, but your patch doesn't apply against the current tree at all.
> > Please rebase it if it is still needed.
> 
> Hello,
> 
> I had based my patch off of net-next, which is where I do my work.

Please base it on cryptodev.

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

[toc] | [prev] | [next] | [standalone]


#1394149 — Re: [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl

FromSowmini Varadhan <sowmini.varadhan@oracle.com>
Date2016-05-04 13:10 +0200
SubjectRe: [PATCH v2] lib/mpi: Fix kernel unaligned access in mpi_write_to_sgl
Message-ID<rv2QN-2Ku-3@gated-at.bofh.it>
In reply to#1393905
On (05/04/16 10:32), Herbert Xu wrote:
> 
> Please base it on cryptodev.
> 

Looks like this got fixed in cryptodev by commit cece762f6f3c 
("lib/mpi: mpi_write_sgl(): fix out-of-bounds stack access")

Thanks,
--Sowmini

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web