You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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:
…able code
CrossDSOCFIPass is supposed to replace this stub function to a properly
aligned function. However the pass is not ran if the file has no
executable code, thus producing incorrectly aligned __cfi_check.
Fixesllvm#45638.
Differential Revision: https://reviews.llvm.org/D155736
Extended Description
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
The text was updated successfully, but these errors were encountered: