[compiler-rt] r259007 - [cfi] Fix recovery from out-of-bounds vtable error.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 27 16:37:54 PST 2016
Author: eugenis
Date: Wed Jan 27 18:37:54 2016
New Revision: 259007
URL: http://llvm.org/viewvc/llvm-project?rev=259007&view=rev
Log:
[cfi] Fix recovery from out-of-bounds vtable error.
Modified:
compiler-rt/trunk/lib/cfi/cfi.cc
compiler-rt/trunk/test/cfi/cross-dso/target_out_of_bounds.cpp
Modified: compiler-rt/trunk/lib/cfi/cfi.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/cfi/cfi.cc?rev=259007&r1=259006&r2=259007&view=diff
==============================================================================
--- compiler-rt/trunk/lib/cfi/cfi.cc (original)
+++ compiler-rt/trunk/lib/cfi/cfi.cc Wed Jan 27 18:37:54 2016
@@ -306,12 +306,14 @@ ALWAYS_INLINE void CfiSlowPathCommon(u64
// FIXME: call the ubsan handler if DiagData != nullptr?
VReport(1, "CFI: invalid memory region for a check target: %p\n", Ptr);
#ifdef CFI_ENABLE_DIAG
- if (DiagData)
+ if (DiagData) {
__ubsan_handle_cfi_check_fail(
reinterpret_cast<__ubsan::CFICheckFailData *>(DiagData),
reinterpret_cast<uptr>(Ptr));
- else
+ return;
+ } else {
Trap();
+ }
#else
Trap();
#endif
@@ -348,7 +350,8 @@ void InitializeFlags() {
SetVerbosity(common_flags()->verbosity);
- if (Verbosity()) ReportUnrecognizedFlags();
+ if (Verbosity())
+ ReportUnrecognizedFlags();
if (common_flags()->help) {
cfi_parser.PrintFlagDescriptions();
Modified: compiler-rt/trunk/test/cfi/cross-dso/target_out_of_bounds.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/cfi/cross-dso/target_out_of_bounds.cpp?rev=259007&r1=259006&r2=259007&view=diff
==============================================================================
--- compiler-rt/trunk/test/cfi/cross-dso/target_out_of_bounds.cpp (original)
+++ compiler-rt/trunk/test/cfi/cross-dso/target_out_of_bounds.cpp Wed Jan 27 18:37:54 2016
@@ -20,9 +20,13 @@ int main(int argc, char *argv[]) {
// enough to handle unaddressable vtables. TODO: fix this.
void *empty = calloc(1, 128);
uintptr_t v = (uintptr_t)empty + 64;
- A *volatile p = new A();
- for (uintptr_t *q = (uintptr_t *)p; q < (uintptr_t *)(p + 1); ++q)
+ char *volatile p = reinterpret_cast<char *>(new A());
+ for (uintptr_t *q = (uintptr_t *)p; q < (uintptr_t *)(p + sizeof(A)); ++q)
*q = v;
+
+ // CHECK: runtime error: control flow integrity check for type 'A' failed during cast
+ A *volatile pa = reinterpret_cast<A *>(p);
+
// CHECK: untime error: control flow integrity check for type 'A' failed during virtual call
- p->f();
+ pa->f();
}
More information about the llvm-commits
mailing list