Skip to content

Commit

Permalink
lib/mpi: Fix SG miter leak
Browse files Browse the repository at this point in the history
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: 127827b ("lib/mpi: Do not do sg_virt")
Reported-by: Nicolai Stange <[email protected]>
Tested-by: Nicolai Stange <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
herbertx committed Jul 29, 2016
1 parent 64ec6cc commit 4816c94
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/mpi/mpicoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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++;
Expand All @@ -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;
Expand Down

0 comments on commit 4816c94

Please sign in to comment.