RE: [GIT PULL] percpu fix for v5.9-rc6
From: David Laight
Date: Sat Sep 19 2020 - 11:15:14 EST
From: Arvind Sankar
> Sent: 18 September 2020 23:40
..
> Ouch, offsetof() and sizeof() will give different results in the
> presence of alignment padding.
>
> https://godbolt.org/z/rqnxTK
>
> I think, grepping at random, that at least struct scsi_vpd is like this,
> size is 24 but data[] starts at offset 20.
>
> struct scsi_vpd {
> struct rcu_head rcu;
> int len;
> unsigned char data[];
> };
For another standards 'brain-fart' consider:
x = malloc(offsetof(struct scsi_vpd, data[count]));
Since offsetof() is defined to return a compile-time constant
(hi Microsoft) this is illegal unless 'count' is also a
compile-time constant.
(It ought to be defined to be constant if the field is constant.)
If count < 4 then *x = *y will also write past the end of x.
Such structure assignments should be compile-time errors.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)