linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 1/2] lib/mpi: Fix buffer overrun when SG is too long
@ 2022-12-27  9:46 Roberto Sassu
  2022-12-27  9:46 ` [PATCH v4 2/2] KEYS: asymmetric: Copy sig and digest in public_key_verify_signature() Roberto Sassu
  0 siblings, 1 reply; 3+ messages in thread
From: Roberto Sassu @ 2022-12-27  9:46 UTC (permalink / raw)
  To: dhowells, herbert, davem, zohar, dmitry.kasatkin, paul, jmorris,
	serge, ebiggers
  Cc: linux-integrity, linux-security-module, keyrings, linux-crypto,
	linux-kernel, Roberto Sassu

From: Herbert Xu <herbert@gondor.apana.org.au>

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: 2d4d1eea540b ("lib/mpi: Add mpi sgl helpers")
Reported-by: Roberto Sassu <roberto.sassu@huaweicloud.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
 lib/mpi/mpicoder.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/mpi/mpicoder.c b/lib/mpi/mpicoder.c
index 39c4c6731094..3cb6bd148fa9 100644
--- a/lib/mpi/mpicoder.c
+++ b/lib/mpi/mpicoder.c
@@ -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;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-27 10:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-27  9:46 [PATCH v4 1/2] lib/mpi: Fix buffer overrun when SG is too long Roberto Sassu
2022-12-27  9:46 ` [PATCH v4 2/2] KEYS: asymmetric: Copy sig and digest in public_key_verify_signature() Roberto Sassu
2022-12-27 10:51   ` Roberto Sassu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).