Re: [PATCH] tee: Prevent size calculation wraparound on 32-bit kernels

From: Jann Horn
Date: Fri May 02 2025 - 08:29:36 EST


On Thu, May 1, 2025 at 10:02 PM David Laight
<david.laight.linux@xxxxxxxxx> wrote:
>
> On Mon, 28 Apr 2025 15:06:43 +0200
> Jann Horn <jannh@xxxxxxxxxx> wrote:
>
> > The current code around TEE_IOCTL_PARAM_SIZE() is a bit wrong on
> > 32-bit kernels: Multiplying a user-provided 32-bit value with the
> > size of a structure can wrap around on such platforms.
> >
> > Fix it by using saturating arithmetic for the size calculation.
>
> Why not just add a sanity check on 'num_params' after it is read.
> Max is 31 (1024-32)/32), but any sane limit will do because of
> the buf.buf_len test.

That would work, too. I don't know which way looks nicer.