@@ -284,3 +284,8 @@ config X86_CET_TEST
depends on m
depends on X86_KERNEL_IBT
tristate "in-kernel CET testing module"
+
+config X86_FINEIBT_TEST
+ depends on m
+ depends on X86_KERNEL_FINEIBT
+ tristate "in-kernel FineIBT testing module"
@@ -150,6 +150,7 @@ obj-$(CONFIG_UNWINDER_GUESS) += unwind_guess.o
obj-$(CONFIG_AMD_MEM_ENCRYPT) += sev.o
obj-$(CONFIG_X86_KERNEL_FINEIBT) += fineibt.o
obj-$(CONFIG_X86_CET_TEST) += cet_test.o
+obj-$(CONFIG_X86_FINEIBT_TEST) += fineibt_test.o
###
# 64 bit specific files
new file mode 100644
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/module.h>
+
+void __fineibt_debug(void);
+
+void fineibt_foo(void) {
+ pr_info("FineIBT: dmesg should show a FineIBT violation message.\n");
+}
+
+void fineibt_bar(void) {
+ pr_info("FineIBT: this first one should run smoothly.\n");
+}
+
+static int fineibt_test_init(void)
+{
+ pr_info("FineIBT test\n");
+
+ __fineibt_debug();
+
+ asm volatile(
+ "call fineibt_bar\n"
+ "lea fineibt_foo(%%rip), %%rax\n"
+ "mov $0xdeadbeef, %%r11\n"
+ "call *%%rax\n"
+ /* this should trigger the handler because the hash is wrong */
+ ::: "rax"
+ );
+ return 0;
+}
+
+static void fineibt_test_exit(void)
+{
+}
+
+module_init(fineibt_test_init);
+module_exit(fineibt_test_exit);
+
+MODULE_LICENSE("GPL v2");