[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6949ced7c1014488b2d00ff26eba6b6b@AcuMS.aculab.com>
Date: Fri, 30 Dec 2022 13:35:07 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Roberto Sassu' <roberto.sassu@...weicloud.com>,
"dhowells@...hat.com" <dhowells@...hat.com>,
"herbert@...dor.apana.org.au" <herbert@...dor.apana.org.au>,
"davem@...emloft.net" <davem@...emloft.net>,
"zohar@...ux.ibm.com" <zohar@...ux.ibm.com>,
"dmitry.kasatkin@...il.com" <dmitry.kasatkin@...il.com>,
"paul@...l-moore.com" <paul@...l-moore.com>,
"jmorris@...ei.org" <jmorris@...ei.org>,
"serge@...lyn.com" <serge@...lyn.com>,
"ebiggers@...nel.org" <ebiggers@...nel.org>
CC: "linux-integrity@...r.kernel.org" <linux-integrity@...r.kernel.org>,
"linux-security-module@...r.kernel.org"
<linux-security-module@...r.kernel.org>,
"keyrings@...r.kernel.org" <keyrings@...r.kernel.org>,
"linux-crypto@...r.kernel.org" <linux-crypto@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"stable@...r.kernel.org" <stable@...r.kernel.org>
Subject: RE: [PATCH v5 1/2] lib/mpi: Fix buffer overrun when SG is too long
From: Roberto Sassu
> Sent: 27 December 2022 14:28
>
> From: Herbert Xu <herbert@...dor.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@...weicloud.com>
> Signed-off-by: Herbert Xu <herbert@...dor.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);
Technically that min_t() is incorrect.
miter.length is size_t (unsigned long on 64bit) and nbytes unsigned int.
Any cast needs to force the smaller type to the larger one.
(Clearly here the domain of the values is probably than 4G - but that isn't
the point. There must be some places where the sg length needs to
be size_t because 32 bits isn't enough.)
In reality min() is being completely over-zealous in its checking and
should allow comparisons where the signed-ness of the two values matches.
Search for the patch I posted before xmas.
David
> + nbytes -= len;
>
> for (x = 0; x < len; x++) {
> a <<= 8;
> --
> 2.25.1
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists