[llvm-bugs] [Bug 41972] New: -fsanitize-cfi-cross-dso causes .S functions to no longer recognize their defined function prototype
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue May 21 14:13:48 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=41972
Bug ID: 41972
Summary: -fsanitize-cfi-cross-dso causes .S functions to no
longer recognize their defined function prototype
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: keescook at chromium.org
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
neeilans at live.com, richard-llvm at metafoo.co.uk
When building and linking .S files into a project (like, say, the Linux
kernel), having their function prototypes declared in headers works fine with
just "-fsanitize=cfi".
For example with return.S:
.globl do_nothing_asm
.align 4,0x90
do_nothing_asm:
nop
ret
.type do_nothing_asm, @function
.size do_nothing_asm, .-do_nothing_asm
and main.c:
#include <stdio.h>
extern void do_nothing_asm(void);
void do_nothing_C(void)
{
return;
}
int main(void)
{
void (*func)(void);
printf("C ...\n");
func = do_nothing_C;
func();
printf("asm ...\n");
func = do_nothing_asm;
func();
return 0;
}
$ clang -flto -fvisibility=hidden -fsanitize=cfi -c -o main.o main.c
$ clang -flto -fvisibility=hidden -fsanitize=cfi -c -o return.o return.S
$ clang -flto -fvisibility=hidden -fsanitize=cfi -fuse-ld=lld -o test main.o
return.o
$ ./test
C ...
asm ...
$
But enabling cross-dso, this breaks:
$ clang -flto -fvisibility=hidden -fsanitize=cfi -fsanitize-cfi-cross-dso -c
-o main.o main.c
$ clang -flto -fvisibility=hidden -fsanitize=cfi -fsanitize-cfi-cross-dso -c
-o return.o return.S
$ clang -flto -fvisibility=hidden -fsanitize=cfi -fsanitize-cfi-cross-dso
-fuse-ld=lld -o test main.o return.o
$ ./test
C ...
asm ...
Illegal instruction (core dumped)
$
This is a rather bad problem for the Linux kernel, as implementing functions in
.S is rather common, and especially so for indirect function calls to them in
things like the crypto subsystem. We need some way to either fix this in the
cross-DSO CFI or to mark these. (The kernel already marks .S functions with its
own "asmlinkage" macro, which could gain, for example, a CFI-specific attribute
if needed.)
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190521/46da8a4a/attachment.html>
More information about the llvm-bugs
mailing list