Skip to content

Commit

Permalink
lib/mpi: Fix buffer overrun when SG is too long
Browse files Browse the repository at this point in the history
[ Upstream commit 7361d1b ]

The helper mpi_read_raw_from_sgl sets the number of entries in
the SG list according to nbytes.  However, if the last entry
in the SG list contains more data than nbytes, then it may overrun
the buffer because it only allocates enough memory for nbytes.

Fixes: 2d4d1ee ("lib/mpi: Add mpi sgl helpers")
Reported-by: Roberto Sassu <roberto.sassu@huaweicloud.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
herbertx authored and gregkh committed Mar 10, 2023
1 parent 62030a4 commit 553d8b2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/mpi/mpicoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,8 @@ MPI mpi_read_raw_from_sgl(struct scatterlist *sgl, unsigned int nbytes)

while (sg_miter_next(&miter)) {
buff = miter.addr;
len = miter.length;
len = min_t(unsigned, miter.length, nbytes);
nbytes -= len;

for (x = 0; x < len; x++) {
a <<= 8;
Expand Down

0 comments on commit 553d8b2

Please sign in to comment.