From: kettenis Date: Fri, 23 Feb 2024 21:33:51 +0000 (+0000) Subject: Start of a BTCFI test. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b7a8588755fd1a9790fc5e212a6769acf92edb7d;p=openbsd Start of a BTCFI test. --- diff --git a/regress/sys/btcfi/Makefile b/regress/sys/btcfi/Makefile new file mode 100644 index 00000000000..b5cdcbf6cfb --- /dev/null +++ b/regress/sys/btcfi/Makefile @@ -0,0 +1,22 @@ +# $OpenBSD: Makefile,v 1.1 2024/02/23 21:33:51 kettenis Exp $ + +.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "aarch64" + +PROG= foobar +OBJS= foo.o + +.if ${MACHINE_ARCH} == "aarch64" +NOBTCFI_CFLAGS= -mbranch-protection=none +.else +NOBTCFI_CFLAGS= -fcf-protection=none +.endif + +foo.o: foo.c + ${COMPILE.c} ${NOBTCFI_CFLAGS} ${.CURDIR}/foo.c -o foo.o + +.elif make(regress) || make(all) +regress: + @echo Cannot run on ${MACHINE_ARCH}. + @echo SKIPPED +.endif +.include diff --git a/regress/sys/btcfi/foo.c b/regress/sys/btcfi/foo.c new file mode 100644 index 00000000000..59630e6e176 --- /dev/null +++ b/regress/sys/btcfi/foo.c @@ -0,0 +1,6 @@ +/* Public domain */ + +void +foo(void) +{ +} diff --git a/regress/sys/btcfi/foobar.c b/regress/sys/btcfi/foobar.c new file mode 100644 index 00000000000..e521979c54e --- /dev/null +++ b/regress/sys/btcfi/foobar.c @@ -0,0 +1,34 @@ +/* Public domain */ + +#include +#include + +extern void foo(void); +void (*foobar)(void) = foo; + +void +bar(void) +{ + foobar(); +} + +void +handler(int sig, siginfo_t *si, void *context) +{ + if (si->si_signo == SIGILL && si->si_code == ILL_BTCFI) + exit(0); +} + +int +main(void) +{ + struct sigaction sa; + + sa.sa_sigaction = handler; + sa.sa_mask = 0; + sa.sa_flags = SA_SIGINFO; + sigaction(SIGILL, &sa, NULL); + + bar(); + exit(1); +}