linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Arvind Sankar <nivedita@alum.mit.edu>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Arvind Sankar <nivedita@alum.mit.edu>,
	Matthew Wilcox <willy@infradead.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>,
	Christoph Lameter <cl@linux.com>, Linux-MM <linux-mm@kvack.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Kees Cook <keescook@chromium.org>
Subject: Re: [GIT PULL] percpu fix for v5.9-rc6
Date: Fri, 18 Sep 2020 18:39:57 -0400	[thread overview]
Message-ID: <20200918223957.GA2964553@rani.riverdale.lan> (raw)
In-Reply-To: <CAHk-=wgyKF9vnac3mw6v-Bo5D8X-rcrkF=BsZ2jX+OveGkGgBw@mail.gmail.com>

On Fri, Sep 18, 2020 at 02:18:20PM -0700, Linus Torvalds wrote:
> On Fri, Sep 18, 2020 at 2:00 PM Arvind Sankar <nivedita@alum.mit.edu> wrote:
> >
> > You could just assert that offsetof(typeof(s),flex) == sizeof(s), no?
> 
> No, because the whole point is that I want that "sizeof(s)" to *WARN*.
> 
> It's a nonsensical thing to do. That 's' has no statically known size.
> 
> The C standard is being very confused here, in that it tries to claim
> that the flexible arrays are somehow fundamentally different from a
> zero-sized one. But then it acts as if they are exactly the same wrt
> sizeof() and structure copies.
> 
> It should warn, exactly because right now it causes potential bugs
> like the one that started this thread.
> 
> You can't have both "zero-sized arrays are bad and shouldn't be used"
> and "flexible arrays are good, and work exactly like zero-sized
> arrays".
> 
> Either zero-sized arrays are bad or they aren't. And if they are bad,
> then flexible arrays shouldn't work *exactly* like them apart from
> some UBSAN warnings.
> 
> See my point?
> 
>              Linus

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[];
	};


  reply	other threads:[~2020-09-18 22:40 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-17 20:45 Dennis Zhou
2020-09-18  1:05 ` Linus Torvalds
2020-09-18 16:23   ` Gustavo A. R. Silva
2020-09-18 17:23     ` Linus Torvalds
2020-09-18 19:34       ` Gustavo A. R. Silva
2020-09-18 19:37         ` Linus Torvalds
2020-09-18 20:02           ` Matthew Wilcox
2020-09-18 20:14             ` Linus Torvalds
2020-09-18 20:29               ` Arvind Sankar
2020-09-18 20:40                 ` Linus Torvalds
2020-09-18 21:00                   ` Arvind Sankar
2020-09-18 21:18                     ` Linus Torvalds
2020-09-18 22:39                       ` Arvind Sankar [this message]
2020-09-19  1:28                         ` Linus Torvalds
2020-09-19  2:53                           ` Arvind Sankar
2020-09-19  3:02                             ` Matthew Wilcox
2020-09-19  3:04                             ` Linus Torvalds
2020-09-19  2:45                         ` Matthew Wilcox
2020-09-19  3:37                           ` Arvind Sankar
2020-09-19 15:15                         ` David Laight
2020-09-18 20:03           ` Gustavo A. R. Silva
2020-09-18  1:10 ` pr-tracker-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200918223957.GA2964553@rani.riverdale.lan \
    --to=nivedita@alum.mit.edu \
    --cc=cl@linux.com \
    --cc=dennis@kernel.org \
    --cc=gustavoars@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox