lkml.org 
[lkml]   [2020]   [Sep]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [GIT PULL] percpu fix for v5.9-rc6
On Fri, Sep 18, 2020 at 9:17 AM Gustavo A. R. Silva
<gustavoars@kernel.org> wrote:
>
> This bug could have been prevented by either adopting better
> coding practices or through the use[3] of the recent struct_size() helper.

Well, my unspoken point was that coding practices are just
theoretical. Coding practices don't help - actual *checking* of them
helps.

I realize that structures with flexible-array member are allowed to
use sizeof() in standard C, but if we want to make sure this doesn't
happen, we would need to have a stricter model than that. But a quick
google didn't find any flag to enable such a stricter mode.

I guess a sparse warning would work, but sparse already has too many
warnings and as a result most people don't care - even if they were to
run sparse in the first place.

Is there some gcc option that I didn't find to help find any questionable cases?

Because if we have a coding practice that you should use
'struct_size()', then we should also have a way to _verify_ that.

The whole - and really ONLY - point of using flexible arrays was that
it would protect against these things. And as things are now, it
simply doesn't. It's not an actual improvement over just using a
zero-sized array.

(Slightly related: copying a struct has the exact same issue. A
flexible array is no better than a zero-sized array, and generates the
same code and the same lack of any warnings, afaik).

Linus

\
 
 \ /
  Last update: 2020-09-18 19:24    [W:0.086 / U:0.596 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site