RE: [PATCH] jfs: Use unsigned variable for length calculations

From: David Laight
Date: Mon Jun 05 2023 - 09:24:30 EST


From: Kees Cook
> Sent: 01 June 2023 17:55
>
> On Mon, Feb 06, 2023 at 07:50:42PM +0000, Dr. David Alan Gilbert wrote:
> > * Kees Cook (keescook@xxxxxxxxxxxx) wrote:
> > > On Sat, Feb 04, 2023 at 08:25:45PM +0000, Dr. David Alan Gilbert wrote:
...
> > > > > - int ssize; /* source pathname size */
> > > > > + u32 ssize; /* source pathname size */
> > > >
> > > > Had you considered using size_t - this is set from a strlen and used by a memcpy
> > > > that both talk size_t.
> > >
> > > I considered that, but I've had other maintainers upset about doubling
> > > the variable size.
> >
> > I bet at least on some platforms it's cheaper as the 64 bit.
> >
> > > I opted to keep the variable 32-bit here, so the
> > > machine code would only change to lose signed-ness.

On x86-64 'unsigned int' and 'signed long' are likely to
generate the best code.

If you use 'signed int' it will to have to be sign extended
if used in a 64-bit expression (eg as an array index).

(That is probably true of most 64bit arch.)

OTOH 'unsigned long' always requires a REX prefix - making the
code that bit larger.

David

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