Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dea3eb8b authored by Stephan Mueller's avatar Stephan Mueller Committed by Herbert Xu
Browse files

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: 4816c940 ("lib/mpi: Fix SG miter leak")
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarStephan Mueller <smueller@chronox.de>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 8861249c
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -364,11 +364,11 @@ MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int nbytes)
	}
	}


	miter.consumed = lzeros;
	miter.consumed = lzeros;
	sg_miter_stop(&miter);


	nbytes -= lzeros;
	nbytes -= lzeros;
	nbits = nbytes * 8;
	nbits = nbytes * 8;
	if (nbits > MAX_EXTERN_MPI_BITS) {
	if (nbits > MAX_EXTERN_MPI_BITS) {
		sg_miter_stop(&miter);
		pr_info("MPI: mpi too large (%u bits)\n", nbits);
		pr_info("MPI: mpi too large (%u bits)\n", nbits);
		return NULL;
		return NULL;
	}
	}
@@ -376,6 +376,8 @@ MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int nbytes)
	if (nbytes > 0)
	if (nbytes > 0)
		nbits -= count_leading_zeros(*buff) - (BITS_PER_LONG - 8);
		nbits -= count_leading_zeros(*buff) - (BITS_PER_LONG - 8);


	sg_miter_stop(&miter);

	nlimbs = DIV_ROUND_UP(nbytes, BYTES_PER_MPI_LIMB);
	nlimbs = DIV_ROUND_UP(nbytes, BYTES_PER_MPI_LIMB);
	val = mpi_alloc(nlimbs);
	val = mpi_alloc(nlimbs);
	if (!val)
	if (!val)