AK+Kernel+LibSanitizer: Implement __ubsan_handle_function_type_mismatch

This commit is contained in:
implicitfield 2023-09-21 21:46:11 +04:00 committed by Andrew Kaster
parent 7a74805067
commit 1159cd9390
4 changed files with 37 additions and 0 deletions

View file

@ -148,6 +148,11 @@ struct PointerOverflowData {
SourceLocation location;
};
struct FunctionTypeMismatchData {
SourceLocation location;
TypeDescriptor const& type;
};
struct FloatCastOverflowData {
SourceLocation location;
TypeDescriptor const& from_type;

View file

@ -141,4 +141,10 @@ void __ubsan_handle_pointer_overflow(PointerOverflowData const& data, ValueHandl
{
print_location(data.location);
}
void __ubsan_handle_function_type_mismatch(FunctionTypeMismatchData const&, ValueHandle) __attribute__((used));
void __ubsan_handle_function_type_mismatch(FunctionTypeMismatchData const& data, ValueHandle)
{
print_location(data.location);
}
}

View file

@ -208,4 +208,11 @@ void __ubsan_handle_pointer_overflow(PointerOverflowData const& data, ValueHandl
critical_dmesgln("KUBSAN: addition of unsigned offset to {:p} overflowed to {:p}", base, result);
print_location(data.location);
}
void __ubsan_handle_function_type_mismatch(FunctionTypeMismatchData const&) __attribute__((used));
void __ubsan_handle_function_type_mismatch(FunctionTypeMismatchData const& data)
{
critical_dmesgln("KUBSAN: call to function through pointer to incorrect function type {}", data.type.name());
print_location(data.location);
}
}

View file

@ -482,4 +482,23 @@ static void handle_float_cast_overflow(FloatCastOverflowData& data, ValueHandle)
handle_float_cast_overflow(data, value);
ABORT_ALWAYS();
}
static void handle_function_type_mismatch(FunctionTypeMismatchData& data, ValueHandle)
{
auto location = data.location.permanently_clear();
if (!location.needs_logging())
return;
WARNLN_AND_DBGLN("UBSAN: call to function through pointer to incorrect function type {}", data.type.name());
print_location(location);
}
[[gnu::used]] void __ubsan_handle_function_type_mismatch(FunctionTypeMismatchData& data, ValueHandle value)
{
handle_function_type_mismatch(data, value);
ABORT_IF_DEADLY();
}
[[gnu::used, noreturn]] void __ubsan_handle_function_type_mismatch_abort(FunctionTypeMismatchData& data, ValueHandle value)
{
handle_function_type_mismatch(data, value);
ABORT_ALWAYS();
}
} // extern "C"