Skip to content

Commit dea3eb8

Browse files
smuellerDDherbertx
authored andcommitted
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: 4816c94 ("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>
1 parent 8861249 commit dea3eb8

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎lib/mpi/mpicoder.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,18 +364,20 @@ MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int nbytes)
364364
}
365365

366366
miter.consumed = lzeros;
367-
sg_miter_stop(&miter);
368367

369368
nbytes -= lzeros;
370369
nbits = nbytes * 8;
371370
if (nbits > MAX_EXTERN_MPI_BITS) {
371+
sg_miter_stop(&miter);
372372
pr_info("MPI: mpi too large (%u bits)\n", nbits);
373373
return NULL;
374374
}
375375

376376
if (nbytes > 0)
377377
nbits -= count_leading_zeros(*buff) - (BITS_PER_LONG - 8);
378378

379+
sg_miter_stop(&miter);
380+
379381
nlimbs = DIV_ROUND_UP(nbytes, BYTES_PER_MPI_LIMB);
380382
val = mpi_alloc(nlimbs);
381383
if (!val)

0 commit comments

Comments
 (0)