[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 4/4] xen/ubsan: Introduce and use CONFIG_UBSAN
Tested with GCC 4.9 of Debian Jessie. Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- CC: George Dunlap <George.Dunlap@xxxxxxxxxxxxx> CC: Jan Beulich <JBeulich@xxxxxxxx> CC: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx> CC: Stefano Stabellini <sstabellini@xxxxxxxxxx> CC: Tim Deegan <tim@xxxxxxx> CC: Wei Liu <wei.liu2@xxxxxxxxxx> CC: Julien Grall <julien.grall@xxxxxxx> TODO at some future point: Fix the following known issues: Clang 3.9 - linker error in shadow/multi.c with fetch_type_names[]. With UBSAN enabled, it appears that dead code elimination doesn't remove the single reference to fetch_type_names[] which lives behind DEBUG_TRACE_DUMP. Clang 4.0 - ABI change with the hooks. --- xen/Kconfig | 6 ++++++ xen/Kconfig.debug | 8 ++++++++ xen/Rules.mk | 4 ++++ xen/arch/x86/Kconfig | 1 + xen/common/Makefile | 1 + xen/common/ubsan/ubsan.c | 22 +++++++++++++++------- xen/include/xen/compiler.h | 1 + 7 files changed, 36 insertions(+), 7 deletions(-) diff --git a/xen/Kconfig b/xen/Kconfig index 65d491d..f57cefd 100644 --- a/xen/Kconfig +++ b/xen/Kconfig @@ -38,4 +38,10 @@ config LTO If unsure, say N. +# +# For architectures that know their GCC __int128 support is sound +# +config ARCH_SUPPORTS_INT128 + bool + source "Kconfig.debug" diff --git a/xen/Kconfig.debug b/xen/Kconfig.debug index 195d504..e63b533 100644 --- a/xen/Kconfig.debug +++ b/xen/Kconfig.debug @@ -121,6 +121,14 @@ config SCRUB_DEBUG Verify that pages that need to be scrubbed before being allocated to a guest are indeed scrubbed. +config UBSAN + bool "Undefined behaviour sanitizer" + depends on X86 + ---help--- + Enable undefined behaviour sanitizer. + + If unsure, say N here. + endif # DEBUG || EXPERT endmenu diff --git a/xen/Rules.mk b/xen/Rules.mk index cafc67b..2659f8a 100644 --- a/xen/Rules.mk +++ b/xen/Rules.mk @@ -119,6 +119,10 @@ ifeq ($(CONFIG_GCOV),y) $(filter-out %.init.o $(nogcov-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fprofile-arcs -ftest-coverage endif +ifeq ($(CONFIG_UBSAN),y) +$(filter-out %.init.o $(noubsan-y),$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS += -fsanitize=undefined +endif + ifeq ($(CONFIG_LTO),y) CFLAGS += -flto LDFLAGS-$(clang) += -plugin LLVMgold.so diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 30c2769..f77e6fc 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -5,6 +5,7 @@ config X86 def_bool y select ACPI select ACPI_LEGACY_TABLES_LOOKUP + select ARCH_SUPPORTS_INT128 select COMPAT select CORE_PARKING select HAS_ALTERNATIVE diff --git a/xen/common/Makefile b/xen/common/Makefile index 39e2614..66cc2c8 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -75,6 +75,7 @@ tmem-$(CONFIG_COMPAT) += compat/tmem_xen.o obj-$(CONFIG_TMEM) += $(tmem-y) subdir-$(CONFIG_GCOV) += gcov +subdir-$(CONFIG_UBSAN) += ubsan subdir-y += libelf subdir-$(CONFIG_HAS_DEVICE_TREE) += libfdt diff --git a/xen/common/ubsan/ubsan.c b/xen/common/ubsan/ubsan.c index e44c8ce..b601af9 100644 --- a/xen/common/ubsan/ubsan.c +++ b/xen/common/ubsan/ubsan.c @@ -10,13 +10,21 @@ * */ -#include <linux/bitops.h> -#include <linux/bug.h> -#include <linux/ctype.h> -#include <linux/init.h> -#include <linux/kernel.h> -#include <linux/types.h> -#include <linux/sched.h> +#include <xen/bitops.h> +#include <xen/kernel.h> +#include <xen/lib.h> +#include <xen/types.h> +#include <xen/spinlock.h> +#include <xen/percpu.h> + +#define pr_err(...) printk(XENLOG_ERR __VA_ARGS__) +struct xen_ubsan { int in_ubsan; }; +static DEFINE_PER_CPU(struct xen_ubsan[1], in_ubsan); +#undef current +#define current this_cpu(in_ubsan) +#define dump_stack dump_execution_state +#define u64 long long unsigned int +#define s64 long long int #include "ubsan.h" diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h index 533a8ea..e4d706f 100644 --- a/xen/include/xen/compiler.h +++ b/xen/include/xen/compiler.h @@ -15,6 +15,7 @@ #define noinline __attribute__((__noinline__)) #define noreturn __attribute__((__noreturn__)) +#define __noreturn noreturn #define __packed __attribute__((__packed__)) -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |