summaryrefslogtreecommitdiffstats
path: root/include/qemu
diff options
context:
space:
mode:
authorDaniele Buono2020-12-05 00:06:12 +0100
committerPaolo Bonzini2021-01-02 21:03:35 +0100
commitc905a3680dc1dae044ea6b9aaf9f0482e5ebf63c (patch)
tree1e70e38d8c7edee5be7794dd772da572b4e7393e /include/qemu
parentconfigure,meson: add option to enable LTO (diff)
downloadqemu-c905a3680dc1dae044ea6b9aaf9f0482e5ebf63c.tar.gz
qemu-c905a3680dc1dae044ea6b9aaf9f0482e5ebf63c.tar.xz
qemu-c905a3680dc1dae044ea6b9aaf9f0482e5ebf63c.zip
cfi: Initial support for cfi-icall in QEMU
LLVM/Clang, supports runtime checks for forward-edge Control-Flow Integrity (CFI). CFI on indirect function calls (cfi-icall) ensures that, in indirect function calls, the function called is of the right signature for the pointer type defined at compile time. For this check to work, the code must always respect the function signature when using function pointer, the function must be defined at compile time, and be compiled with link-time optimization. This rules out, for example, shared libraries that are dynamically loaded (given that functions are not known at compile time), and code that is dynamically generated at run-time. This patch: 1) Introduces the CONFIG_CFI flag to support cfi in QEMU 2) Introduces a decorator to allow the definition of "sensitive" functions, where a non-instrumented function may be called at runtime through a pointer. The decorator will take care of disabling cfi-icall checks on such functions, when cfi is enabled. 3) Marks functions currently in QEMU that exhibit such behavior, in particular: - The function in TCG that calls pre-compiled TBs - The function in TCI that interprets instructions - Functions in the plugin infrastructures that jump to callbacks - Functions in util that directly call a signal handler Signed-off-by: Daniele Buono <dbuono@linux.vnet.ibm.com> Acked-by: Alex Bennée <alex.bennee@linaro.org Message-Id: <20201204230615.2392-3-dbuono@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'include/qemu')
-rw-r--r--include/qemu/compiler.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index df9ec08f8a..d620a841e4 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -233,4 +233,15 @@ extern void QEMU_NORETURN QEMU_ERROR("code path is reachable")
# define QEMU_FALLTHROUGH do {} while (0) /* fallthrough */
#endif
+#ifdef CONFIG_CFI
+/*
+ * If CFI is enabled, use an attribute to disable cfi-icall on the following
+ * function
+ */
+#define QEMU_DISABLE_CFI __attribute__((no_sanitize("cfi-icall")))
+#else
+/* If CFI is not enabled, use an empty define to not change the behavior */
+#define QEMU_DISABLE_CFI
+#endif
+
#endif /* COMPILER_H */