[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 1/7] 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> --- 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 e99370322b44..7ebe4bfc14dc 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 9c7f3b9b6c07..8987f9d45397 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; -- 2.48.1
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |