LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 46293 - __cfi_check not aligned to 4k on relocatable files with no executable code
Summary: __cfi_check not aligned to 4k on relocatable files with no executable code
Status: NEW
Alias: None
Product: new-bugs
Classification: Unclassified
Component: new bugs (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Peter Collingbourne
URL:
Keywords:
Depends on:
Blocks: 4068
  Show dependency tree
 
Reported: 2020-06-11 15:29 PDT by Sami Tolvanen
Modified: 2021-03-18 12:19 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sami Tolvanen 2020-06-11 15:29:06 PDT
When building a Linux kernel module with no executable code using -fsanitize=cfi + -fsanitize-cfi-cross-dso, I noticed the compiler-generated __cfi_check function was not aligned to 4096 bytes as expected:

$ echo "int a;" > test.c
$ clang -flto=thin -fvisibility=default \
    -fsanitize=cfi -fsanitize-cfi-cross-dso -c test.c
$ ld.lld -r -o test.ko test.o
$ llvm-readelf -S --wide test.ko
...
Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 2] .text.__cfi_check_fail PROGBITS   0000000000000000 000040 000026 00  AX  0   0 16
...


Note Al = 16 in the section header. Adding a function to the file results in __cfi_check to be aligned to 4096 again:

$ echo "int a; void b() {}" > test.c
$ clang -flto=thin -fvisibility=default \
    -fsanitize=cfi -fsanitize-cfi-cross-dso -c test.c
$ ld.lld -r -o test.ko test.o
$ llvm-readelf -S --wide test.ko
...
Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 2] .text.__cfi_check PROGBITS        0000000000000000 001000 000032 00  AX  0   0 4096
...

I couldn't find documentation that says __cfi_check is guaranteed to be aligned to 4k, but it's implied in the CFI design document and compiler-rt's CFI shadow implementation also assumes it:

https://clang.llvm.org/docs/ControlFlowIntegrityDesign.html#cfi-shadow