[lkml]   [2018]   [Mar]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH v5 0/2] Remove false-positive VLAs when using max()
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.


 \ /
  Last update: 2018-03-16 12:49    [W:0.114 / U:0.224 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site