diff options
author | Stephan Mueller <smueller@chronox.de> | 2017-08-10 02:06:18 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2017-08-22 02:45:01 -0400 |
commit | dea3eb8b452e36cf2dd572b0a797915ccf452ae6 (patch) | |
tree | 8d4fe3412cd76e3bcd7959aa635e71ab80b622f8 | |
parent | 8861249c740fc4af9ddc5aee321eafefb960d7c6 (diff) |
lib/mpi: kunmap after finishing accessing buffer
Using sg_miter_start and sg_miter_next, the buffer of an SG is kmap'ed
to *buff. The current code calls sg_miter_stop (and thus kunmap) on the
SG entry before the last access of *buff.
The patch moves the sg_miter_stop call after the last access to *buff to
ensure that the memory pointed to by *buff is still mapped.
Fixes: 4816c9406430 ("lib/mpi: Fix SG miter leak")
Cc: <stable@vger.kernel.org>
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | lib/mpi/mpicoder.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c index 5a0f75a3bf01..eead4b339466 100644 --- a/lib/mpi/mpicoder.c +++ b/lib/mpi/mpicoder.c | |||
@@ -364,11 +364,11 @@ MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int nbytes) | |||
364 | } | 364 | } |
365 | 365 | ||
366 | miter.consumed = lzeros; | 366 | miter.consumed = lzeros; |
367 | sg_miter_stop(&miter); | ||
368 | 367 | ||
369 | nbytes -= lzeros; | 368 | nbytes -= lzeros; |
370 | nbits = nbytes * 8; | 369 | nbits = nbytes * 8; |
371 | if (nbits > MAX_EXTERN_MPI_BITS) { | 370 | if (nbits > MAX_EXTERN_MPI_BITS) { |
371 | sg_miter_stop(&miter); | ||
372 | pr_info("MPI: mpi too large (%u bits)\n", nbits); | 372 | pr_info("MPI: mpi too large (%u bits)\n", nbits); |
373 | return NULL; | 373 | return NULL; |
374 | } | 374 | } |
@@ -376,6 +376,8 @@ MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int nbytes) | |||
376 | if (nbytes > 0) | 376 | if (nbytes > 0) |
377 | nbits -= count_leading_zeros(*buff) - (BITS_PER_LONG - 8); | 377 | nbits -= count_leading_zeros(*buff) - (BITS_PER_LONG - 8); |
378 | 378 | ||
379 | sg_miter_stop(&miter); | ||
380 | |||
379 | nlimbs = DIV_ROUND_UP(nbytes, BYTES_PER_MPI_LIMB); | 381 | nlimbs = DIV_ROUND_UP(nbytes, BYTES_PER_MPI_LIMB); |
380 | val = mpi_alloc(nlimbs); | 382 | val = mpi_alloc(nlimbs); |
381 | if (!val) | 383 | if (!val) |