[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] xen/ubsan: Support for -fsanitise=builtin



commit 0ff8c6cf906060e3612e2243aca7c3cb5e9c3b42
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Sun May 12 14:17:08 2019 +0100
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Thu Jun 27 19:04:03 2019 +0100

    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>
    Acked-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/common/ubsan/ubsan.c | 23 +++++++++++++++++++++++
 xen/common/ubsan/ubsan.h |  9 +++++++++
 2 files changed, 32 insertions(+)

diff --git a/xen/common/ubsan/ubsan.c b/xen/common/ubsan/ubsan.c
index 50a4e14fac..0fddacabda 100644
--- a/xen/common/ubsan/ubsan.c
+++ b/xen/common/ubsan/ubsan.c
@@ -518,3 +518,26 @@ 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 = NULL;
+
+       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;
+       }
+
+       if (fn)
+               pr_err("passing zero to %s(), which is not a valid argument\n", 
fn);
+       else
+               pr_err("Unknown kind %u\n", data->kind);
+
+       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;
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.