[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] xen: hook up UBSAN with CONFIG_UBSAN
commit 572a78190403e5f2acbd01fa72c35fafe9700169 Author: Wei Liu <wei.liu2@xxxxxxxxxx> AuthorDate: Mon Oct 9 14:54:58 2017 +0100 Commit: Wei Liu <wei.liu2@xxxxxxxxxx> CommitDate: Mon Oct 9 17:05:00 2017 +0100 xen: hook up UBSAN with CONFIG_UBSAN Make the following changes: 1. Introduce CONFIG_UBSAN and other auxiliary options. 2. Introduce Build system rune to filter objects. 3. Make ubsan.c build. Currently only x86 is supported. All init.o's are filtered out because of limitation in the build system. There is no user of noubsan-y yet but it is worth keeping to ease future development. Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> Acked-by: Jan Beulich <jbeulich@xxxxxxxx> --- xen/Kconfig | 6 ++++++ xen/Kconfig.debug | 10 ++++++++++ xen/Rules.mk | 4 ++++ xen/arch/x86/Kconfig | 2 ++ xen/common/Kconfig | 3 +++ xen/common/Makefile | 1 + xen/common/ubsan/ubsan.c | 19 ++++++++++++------- 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/xen/Kconfig b/xen/Kconfig index 65d491d..ea7229a 100644 --- a/xen/Kconfig +++ b/xen/Kconfig @@ -38,4 +38,10 @@ config LTO If unsure, say N. +# +# For architectures that know their compiler __int128 support is sound +# +config ARCH_SUPPORTS_INT128 + bool + source "Kconfig.debug" diff --git a/xen/Kconfig.debug b/xen/Kconfig.debug index 195d504..3329c75 100644 --- a/xen/Kconfig.debug +++ b/xen/Kconfig.debug @@ -121,6 +121,16 @@ 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 HAS_UBSAN + ---help--- + Enable undefined behaviour sanitizer. It uses compiler to insert code + snippets so that undefined behaviours in C are detected during runtime. + This requires a UBSAN capable compiler and it is a debug only feature. + + 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..64955dc 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 @@ -21,6 +22,7 @@ config X86 select HAS_PASSTHROUGH select HAS_PCI select HAS_PDX + select HAS_UBSAN select NUMA select VGA diff --git a/xen/common/Kconfig b/xen/common/Kconfig index e9bb849..103ef44 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -32,6 +32,9 @@ config HAS_MEM_SHARING config HAS_PDX bool +config HAS_UBSAN + bool + config HAS_KEXEC bool 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 685b4de..fbe5685 100644 --- a/xen/common/ubsan/ubsan.c +++ b/xen/common/ubsan/ubsan.c @@ -10,13 +10,18 @@ * */ -#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/spinlock.h> +#include <xen/percpu.h> + +#define __noreturn noreturn +#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" -- generated by git-patchbot for /home/xen/git/xen.git#master _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx https://lists.xenproject.org/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |