[PATCH v5 1/2] lib/mpi: Fix buffer overrun when SG is too long

David Laight David.Laight at ACULAB.COM
Sat Dec 31 13:23:14 UTC 2022


From: Herbert Xu
> Sent: 30 December 2022 15:40
> 
> On Fri, Dec 30, 2022 at 01:35:07PM +0000, David Laight wrote:
> >
> > miter.length is size_t (unsigned long on 64bit) and nbytes unsigned int.
> 
> miter.length is bounded by sg->length which is unsigned int.

I did say 'technically' :-)

Should there be a sg_miter_stop() before the return at the bottom?
Care seems to have been taken to add one before an earlier error return.
(The logic in that function is very strange...)

Indeed other parts of the file are equally strange.
The big multi-line if-else in twocompl() is just:
	p[i] = (p[1] ^ 0xff) + 1;
or even:
	p[i] = -p[i];
That function could also return the 'zero status' to correct
for -0 (rather than the extra check earlier in the caller).

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)



More information about the Linux-security-module-archive mailing list