lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 05 Apr 2018 20:51:31 +0000
From:   James Y Knight <>
To:     Linus Torvalds <>
Cc:     Peter Zijlstra <>,,, Ingo Molnar <>,
        Linux Kernel Mailing List <>,, Andrew Morton <>,
        Chandler Carruth <>,
        Stephen Hines <>,
        Nick Desaulniers <>,
        Kees Cook <>,,
        Greg Hackmann <>,
Subject: Re: [GIT PULL] x86/build changes for v4.17

On Thu, Apr 5, 2018 at 2:06 PM Linus Torvalds
> On Thu, Apr 5, 2018 at 10:46 AM, James Y Knight <>
> >
> > GCC, however, mixes up the concept of a C "constant expression" with the
> > results of running optimization passes such as inlining for its
> > definition/implementation of __builtin_constant_p. Clang does not, and
> > likely will not ever, do that.

> Nothing has ever said that "__builtin_constant_p(x)" means "is x an
> integer constant expression"

I had actually meant that the __builtin_constant_p **itself** had to be a
constant expression, not that its *argument* must be an I-C-E for
__builtin_constant_p to return true.

But after spending some time on further investigating in order to show an
example of how this matters, I must take back my words. I was mistaken
about GCC's semantics.

Take this example:
int function(void);
void useval(int*);

int f() {
     int v = 1 + 2;
     int array[2][__builtin_constant_p(v) ? 1 : 100];
     return sizeof(array[function()]) / sizeof(array[0]);

Build with "gcc -O -std=c99":
         subq    $24, %rsp
         leaq    8(%rsp), %rdi
         call    useval
         call    function
         movl    $4, %eax
         addq    $24, %rsp

Note the fact that "function" is actually *called* indicates that 'array'
is a VLA (...and that C99's sizeof(VLA) semantics are bonkers, but that's
another story...).

Which means that __builtin_constant_p(v) was _not_ evaluated as an integer
constant expression by GCC. Instead, it was left as an expression. And, the
stack frame being only 24 bytes indicates that the __bcp eventually
evaluated to true.

I actually think this actually _is_ something clang can implement. Thanks
for making me try to prove myself. :)

Powered by blists - more mailing lists