Re: [PATCH v5 0/2] Remove false-positive VLAs when using max()

From
Florian Weimer <hidden>
Date
2018-03-16 11:47:58
Also in
lkml, netdev
Reply to
Kees Cook, 2018-03-16
On 03/16/2018 05:25 AM, Kees Cook wrote:
In the effort to remove all VLAs from the kernel[1], it is desirable to
build with -Wvla. However, this warning is overly pessimistic, in that
it is only happy with stack array sizes that are declared as constant
expressions, and not constant values. One case of this is the evaluation
of the max() macro which, due to its construction, ends up converting
constant expression arguments into a constant value result. Attempts
to adjust the behavior of max() ran afoul of version-dependent compiler
behavior[2].
I find this commit message confusing.  VLAs have precisely defined semantics which differ from other arrays, and these differences can be observable (maybe not in the kernel, but certainly for userspace), so the compiler has to treat a VLA as such even if the length is a constant known at compile time.  (The original intent of the warning probably was a portability check anyway.)

If you want to catch stack frames which have unbounded size, -Werror=stack-usage=1000 or -Werror=vla-larger-than=1000 (with the constant adjusted as needed) might be the better approach.

Thanks,
Florian
Thread (37 messages) 37 messages, 10 authors, last reply 2018-03-22
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help