Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__cfi_check not aligned to 4k on relocatable files with no executable code #45638

Closed
samitolvanen opened this issue Jun 11, 2020 · 2 comments
Closed
Assignees
Labels
bugzilla Issues migrated from bugzilla clang:codegen

Comments

@samitolvanen
Copy link
Member

Bugzilla Link 46293
Version trunk
OS Linux
Blocks #4440
CC @eugenis,@nickdesaulniers

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

@samitolvanen
Copy link
Member Author

assigned to @pcc

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@kongy kongy closed this as completed in c7cacb2 Aug 3, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 3, 2023

@llvm/issue-subscribers-clang-codegen

doru1004 pushed a commit to doru1004/llvm-project that referenced this issue Aug 3, 2023
…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.

Fixes llvm#45638.

Differential Revision: https://reviews.llvm.org/D155736
razmser pushed a commit to razmser/llvm-project that referenced this issue Sep 8, 2023
…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.

Fixes llvm#45638.

Differential Revision: https://reviews.llvm.org/D155736
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:codegen
Projects
None yet
Development

No branches or pull requests

3 participants