diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 602eca0219..fbe9953547 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -270,7 +270,7 @@ set(SOURCES ${C_SOURCES} ) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=nonnull-attribute,bool,vla-bound,signed-integer-overflow") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=nonnull-attribute,bool,vla-bound,signed-integer-overflow,shift,shift-exponent,shift-base,integer-divide-by-zero,return,bounds,bounds-strict") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option -DKERNEL") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pie -fPIE -fno-rtti -ffreestanding -fbuiltin") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-80387 -mno-mmx -mno-sse -mno-sse2") diff --git a/Kernel/UBSanitizer.cpp b/Kernel/UBSanitizer.cpp index f0768e5613..23edcd1eff 100644 --- a/Kernel/UBSanitizer.cpp +++ b/Kernel/UBSanitizer.cpp @@ -87,4 +87,25 @@ void __ubsan_handle_mul_overflow(const OverflowData& data, void*, void*) dbgln("KUBSAN: multiplication overflow, {} ({}-bit)", data.type.name(), data.type.bit_width()); print_location(data.location); } + +void __ubsan_handle_shift_out_of_bounds(const ShiftOutOfBoundsData&, void* lhs, void* rhs); +void __ubsan_handle_shift_out_of_bounds(const ShiftOutOfBoundsData& data, void*, void*) +{ + dbgln("KUBSAN: shift out of bounds, {} ({}-bit) shifted by {} ({}-bit)", data.lhs_type.name(), data.lhs_type.bit_width(), data.rhs_type.name(), data.rhs_type.bit_width()); + print_location(data.location); +} + +void __ubsan_handle_divrem_overflow(const OverflowData&, void* lhs, void* rhs); +void __ubsan_handle_divrem_overflow(const OverflowData& data, void*, void*) +{ + dbgln("KUBSAN: divrem overlow, {} ({}-bit)", data.type.name(), data.type.bit_width()); + print_location(data.location); +} + +void __ubsan_handle_out_of_bounds(const OutOfBoundsData&, void*); +void __ubsan_handle_out_of_bounds(const OutOfBoundsData& data, void*) +{ + dbgln("KUBSAN: out of bounds access into array of {} ({}-bit), index type {} ({}-bit)", data.array_type.name(), data.array_type.bit_width(), data.index_type.name(), data.index_type.bit_width()); + print_location(data.location); +} } diff --git a/Kernel/UBSanitizer.h b/Kernel/UBSanitizer.h index ef1ceff69a..34491483e8 100644 --- a/Kernel/UBSanitizer.h +++ b/Kernel/UBSanitizer.h @@ -84,4 +84,16 @@ struct VLABoundData { const TypeDescriptor& type; }; +struct ShiftOutOfBoundsData { + SourceLocation location; + const TypeDescriptor& lhs_type; + const TypeDescriptor& rhs_type; +}; + +struct OutOfBoundsData { + SourceLocation location; + const TypeDescriptor& array_type; + const TypeDescriptor& index_type; +}; + }