[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 2/2] xen/ubsan: Support for -fsanitise=builtin
This fixes the UBSAN build for GCC 8 and later. The sanitiser checks for passing 0 to the ctz()/clz() builtins. Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> --- CC: Jan Beulich <JBeulich@xxxxxxxx> CC: Wei Liu <wl@xxxxxxx> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx> CC: Stefano Stabellini <sstabellini@xxxxxxxxxx> CC: Julien Grall <julien.grall@xxxxxxx> --- xen/common/ubsan/ubsan.c | 21 +++++++++++++++++++++ xen/common/ubsan/ubsan.h | 9 +++++++++ 2 files changed, 30 insertions(+) diff --git a/xen/common/ubsan/ubsan.c b/xen/common/ubsan/ubsan.c index 50a4e14fac..e75f614fa7 100644 --- a/xen/common/ubsan/ubsan.c +++ b/xen/common/ubsan/ubsan.c @@ -518,3 +518,24 @@ void __ubsan_handle_pointer_overflow(struct pointer_overflow_data *data, ubsan_epilogue(&flags); } + +void __ubsan_handle_invalid_builtin(struct invalid_builtin_data *data) +{ + unsigned long flags; + const char *fn; + + if (suppress_report(&data->location)) + return; + + ubsan_prologue(&data->location, &flags); + + switch (data->kind) { + case kind_ctz: fn = "ctz"; break; + case kind_clz: fn = "clz"; break; + default: fn = "<UNKNOWN>"; break; + } + + pr_err("passing zero to %s(), which is not a valid argument\n", fn); + + ubsan_epilogue(&flags); +} diff --git a/xen/common/ubsan/ubsan.h b/xen/common/ubsan/ubsan.h index 2710cd423e..a3159040fe 100644 --- a/xen/common/ubsan/ubsan.h +++ b/xen/common/ubsan/ubsan.h @@ -84,6 +84,15 @@ struct pointer_overflow_data { struct source_location location; }; +struct invalid_builtin_data { + struct source_location location; + unsigned char kind; +}; +enum { + kind_ctz, + kind_clz, +}; + #if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__) typedef __int128 s_max; typedef unsigned __int128 u_max; -- 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |