Re: [PATCH v3] kernel.h: Skip single-eval logic on literals in min()/max()
From: Kees Cook
Date: Fri Mar 09 2018 - 20:31:52 EST
On Fri, Mar 9, 2018 at 5:30 PM, Kees Cook <keescook@xxxxxxxxxxxx> wrote:
> --
> Kees Cook
> Pixel Security<div class="gmail_extra"><br><div class="gmail_quote">On
> [...]
WTF, gmail just blasted HTML into my explicitly plain-text email?! Apologies...
--
Kees Cook
Pixel Security<div class="gmail_extra"><br><div class="gmail_quote">On
Fri, Mar 9, 2018 at 5:30 PM, Kees Cook <span dir="ltr"><<a
href="mailto:keescook@xxxxxxxxxxxx"
target="_blank">keescook@xxxxxxxxxxxx</a>></span>
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On
Fri, Mar 9, 2018 at 4:38 PM, Linus Torvalds<br>
<<a href="mailto:torvalds@xxxxxxxxxxxxxxxxxxxx">torvalds@xxxxxxxxxxxxxxxxxxxx</a><wbr>>
wrote:<br>
> On Fri, Mar 9, 2018 at 4:32 PM, Andrew Morton <<a
href="mailto:akpm@xxxxxxxxxxxxxxxxxxxx">akpm@xxxxxxxxxxxxxxxxxxxx</a>>
wrote:<br>
>><br>
>> I wonder which gcc versions actually accept Kees's addition.<br>
<br>
</span>Ah, my old nemesis, gcc 4.4.4. *sob*<br>
<span class=""><br>
> Note that we already do have this pattern, as seen by:<br>
><br>
> git grep -2 __builtin_choose_expr | grep -2
__builtin_constant_p<br>
><br>
> which show drivers/pinctrl/intel/pinctrl-<wbr>intel.h, so the pattern<br>
> already exists current kernels and _works_ - it apparently just<br>
> doesn't work in slightly more complicated cases.<br>
<br>
</span>Fun. Yeah, so all the PIN_GROUP() callers have either a literal or an<br>
array name for that argument, so the argument to<br>
__builtin_constant_p() isn't complex.<br>
<br>
git grep '\bPIN_GROUP\b' | egrep -v '(1|2|3|true|false)\)'<br>
<span class=""><br>
> It's one reason why I wondered if simplifying the expression to have<br>
> just that single __builtin_constant_p() might not end up working..<br>
<br>
</span>Yeah, it seems like it doesn't bail out as "false" for complex<br>
expressions given to __builtin_constant_p().<br>
<br>
If no magic solution, then which of these?<br>
<br>
- go back to my original "multi-eval max only for constants" macro (meh)<br>
- add gcc version checks around this and similarly for -Wvla in the
future (eww)<br>
- raise gcc version (yikes)<br>
<br>
-Kees<br>
<br>
--<br>
Kees Cook<br>
Pixel Security<div class="gmail_extra"><br><div
class="gmail_quote">On<br>
Fri, Mar 9, 2018 at 4:38 PM, Linus Torvalds <span
dir="ltr">&lt;<a<br>
<span class="">href="mailto:<a
href="mailto:torvalds@xxxxxxxxxxxxxxxxxxxx">torvalds@linux-<wbr>foundation.org</a>"<br>
target="_blank"><a
href="mailto:torvalds@xxxxxxxxxxxxxxxxxxxx">torvalds@<wbr>linux-foundation.org</a></a>&gt;</<wbr>span><br>
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0<br>
</span>.8ex;border-left:1px #ccc solid;padding-left:1ex"><span
class="">On<br>
Fri, Mar 9, 2018 at 4:32 PM, Andrew Morton &lt;<a<br>
href="mailto:<a
href="mailto:akpm@xxxxxxxxxxxxxxxxxxxx">akpm@linux-<wbr>foundation.org</a>"><a
href="mailto:akpm@xxxxxxxxxxxxxxxxxxxx">akpm@linux-<wbr>foundation.org</a></a>&gt;<br>
wrote:<br><br>
&gt;<br><br>
&gt; I wonder which gcc versions actually accept Kees's
addition.<br><br>
<br><br>
</span>Note that we already do have this pattern, as seen
by:<br><br>
<br><br>
&nbsp; git grep -2&nbsp; __builtin_choose_expr | grep -2<br>
__builtin_constant_p<br><br>
<br><br>
which show drivers/pinctrl/intel/pinctrl-<wbr><wbr>intel.h, so
the pattern<br><br>
already exists current kernels and _works_ - it apparently just<br><br>
doesn't work in slightly more complicated cases.<br><br>
<br><br>
It's one reason why I wondered if simplifying the expression to
have<br><br>
just that single __builtin_constant_p() might not end up working..<br><br>
<div class="HOEnZb"><div class="h5"><span
class="HOEnZb"><font color="#888888"><br><br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; Linus<br><br>
</font></span></blockquote></<wbr>div><br><br
clear="all"><div><br></div>--<br>
<br><div class="gmail_signature"
data-smartmail="gmail_<wbr>signature">Kees<br>
Cook<br>Pixel Security</div><br>
</div><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>--
<br><div class="gmail_signature" data-smartmail="gmail_signature">Kees
Cook<br>Pixel Security</div>
</div>