|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen staging] xen/ubsan: provide helper for clang's -fsanitize=function
commit f38148ab093d0e5967f92062b3196d7801850548
Author: Roger Pau Monne <roger.pau@xxxxxxxxxx>
AuthorDate: Wed Mar 12 13:35:53 2025 +0100
Commit: Roger Pau Monne <roger.pau@xxxxxxxxxx>
CommitDate: Mon Mar 17 13:33:28 2025 +0100
xen/ubsan: provide helper for clang's -fsanitize=function
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@xxxxxxxxxx>
Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
xen/common/ubsan/ubsan.c | 16 ++++++++++++++++
xen/common/ubsan/ubsan.h | 5 +++++
2 files changed, 21 insertions(+)
diff --git a/xen/common/ubsan/ubsan.c b/xen/common/ubsan/ubsan.c
index e99370322b..7ebe4bfc14 100644
--- a/xen/common/ubsan/ubsan.c
+++ b/xen/common/ubsan/ubsan.c
@@ -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);
+}
diff --git a/xen/common/ubsan/ubsan.h b/xen/common/ubsan/ubsan.h
index 9c7f3b9b6c..8987f9d453 100644
--- a/xen/common/ubsan/ubsan.h
+++ b/xen/common/ubsan/ubsan.h
@@ -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;
--
generated by git-patchbot for /home/xen/git/xen.git#staging
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |