lkml.org 
[lkml]   [2020]   [Sep]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [GIT PULL] percpu fix for v5.9-rc6
Date
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)
\
 
 \ /
  Last update: 2020-09-19 17:16    [W:1.046 / U:2.348 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site