]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
xen/ubsan: provide helper for clang's -fsanitize=function
authorRoger Pau Monne <roger.pau@citrix.com>
Wed, 12 Mar 2025 12:35:53 +0000 (13:35 +0100)
committerRoger Pau Monne <roger.pau@citrix.com>
Fri, 14 Mar 2025 09:07:11 +0000 (10:07 +0100)
clang's -fsanitize=function relies on the presence of
__ubsan_handle_function_type_mismatch() to print the detection of indirect
calls of a function through a function pointer of the wrong type.

Implement the helper, inspired on the llvm ubsan lib implementation.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/common/ubsan/ubsan.c
xen/common/ubsan/ubsan.h

index e99370322b44bc9941d702859d1f2d627deaddc6..7ebe4bfc14dc0edbef6a9c61c70ac6cb507b79f4 100644 (file)
@@ -546,3 +546,19 @@ void __ubsan_handle_invalid_builtin(struct invalid_builtin_data *data)
 
        ubsan_epilogue(&flags);
 }
+
+void __ubsan_handle_function_type_mismatch(
+       struct function_type_mismatch_data *data, unsigned long val)
+{
+       unsigned long flags;
+
+       if (suppress_report(&data->location))
+               return;
+
+       ubsan_prologue(&data->location, &flags);
+
+       pr_err("call to function %ps through pointer to incorrect function type %s\n",
+               (void *)val, data->type->type_name);
+
+       ubsan_epilogue(&flags);
+}
index 9c7f3b9b6c078b20f61ecaa6157d848845828156..8987f9d4539715b4ad3b94b7b73e90803c175e57 100644 (file)
@@ -95,6 +95,11 @@ enum {
        kind_clz,
 };
 
+struct function_type_mismatch_data {
+       struct source_location location;
+       struct type_descriptor *type;
+};
+
 #if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__)
 typedef __int128 s_max;
 typedef unsigned __int128 u_max;