[Bug target/102953] Improvements to CET-IBT and ENDBR generation

andrew.cooper3 at citrix dot com gcc-bugzilla@gcc.gnu.org
Fri Oct 29 22:57:28 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102953

--- Comment #17 from Andrew Cooper <andrew.cooper3 at citrix dot com> ---
I think I've found a bug in the -fcf-check-attribute implementation.

  $ cat fnptr-array-arg.c
  static int __attribute__((cf_check)) foo(char a[], int b)
  {
      return 0;
  }
  int (*ptr)(char[], int) = foo;

  $ gcc -Wall -fcf-protection=branch -mmanual-endbr -fcf-check-attribute=no -c
fnptr-array-arg.c -o tmp.o && objdump -d tmp.o
  fnptr-array-arg.c:5:27: warning: initialization of 'int (*)(char *, int)'
from incompatible pointer type 'int (__attribute__((nocf_check)) *)(char *,
int)' [-Wincompatible-pointer-types]
      5 | int (*ptr)(char[], int) = foo;
        |                           ^~~

  tmp.o:     file format elf64-x86-64


  Disassembly of section .text:

  0000000000000000 <foo>:
     0: 31 c0                   xor    %eax,%eax
     2: c3                      retq   


Despite the explicit cf_check, a diagnostic is raised complaining about
cf_check-ness of the pointer, and the generated code has no `endbr64`
instruction.

This issue only manifests when using array arguments in the function.  When
switching `char[]` for `char*`, everything works as expected.  Also, dropping
-fcf-check-attribute=no also causes things to work.

  $ gcc -Wall -fcf-protection=branch -mmanual-endbr -c fnptr-array-arg.c -o
tmp.o && objdump -d tmp.o

  tmp.o:     file format elf64-x86-64


  Disassembly of section .text:

  0000000000000000 <foo>:
     0: f3 0f 1e fa             endbr64 
     4: 31 c0                   xor    %eax,%eax
     6: c3                      retq   


Something about the array type seems to cause the explicit cf_check attribute
to be lost.


More information about the Gcc-bugs mailing list