diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2016-07-28 07:29:17 +0200 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2016-07-29 12:30:16 +0200 |
commit | 4816c9406430d0d3d4fa58a212a7a869d429b315 (patch) | |
tree | 06eee2ccd96dbdcd86c8f0c4f700386d3f160985 /lib | |
parent | crypto: marvell - Update cache with input sg only when it is unmapped (diff) | |
download | linux-4816c9406430d0d3d4fa58a212a7a869d429b315.tar.xz linux-4816c9406430d0d3d4fa58a212a7a869d429b315.zip |
lib/mpi: Fix SG miter leak
In mpi_read_raw_from_sgl we may leak the SG miter resouces after
reading the leading zeroes. This patch fixes this by stopping the
iteration once the leading zeroes have been read.
Fixes: 127827b9c295 ("lib/mpi: Do not do sg_virt")
Reported-by: Nicolai Stange <nicstange@gmail.com>
Tested-by: Nicolai Stange <nicstange@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mpi/mpicoder.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c index c6272ae2015e..5a0f75a3bf01 100644 --- a/lib/mpi/mpicoder.c +++ b/lib/mpi/mpicoder.c @@ -363,6 +363,9 @@ MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int nbytes) lzeros = 0; } + miter.consumed = lzeros; + sg_miter_stop(&miter); + nbytes -= lzeros; nbits = nbytes * 8; if (nbits > MAX_EXTERN_MPI_BITS) { @@ -390,7 +393,10 @@ MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int nbytes) z = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB; z %= BYTES_PER_MPI_LIMB; - for (;;) { + while (sg_miter_next(&miter)) { + buff = miter.addr; + len = miter.length; + for (x = 0; x < len; x++) { a <<= 8; a |= *buff++; @@ -400,12 +406,6 @@ MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int nbytes) } } z += x; - - if (!sg_miter_next(&miter)) - break; - - buff = miter.addr; - len = miter.length; } return val; |