<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 27, 2016 at 4:37 PM, Evgeniy Stepanov via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: eugenis<br>
Date: Wed Jan 27 18:37:54 2016<br>
New Revision: 259007<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=259007&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=259007&view=rev</a><br>
Log:<br>
[cfi] Fix recovery from out-of-bounds vtable error.<br>
<br>
Modified:<br>
compiler-rt/trunk/lib/cfi/cfi.cc<br>
compiler-rt/trunk/test/cfi/cross-dso/target_out_of_bounds.cpp<br>
<br>
Modified: compiler-rt/trunk/lib/cfi/cfi.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/cfi/cfi.cc?rev=259007&r1=259006&r2=259007&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/cfi/cfi.cc?rev=259007&r1=259006&r2=259007&view=diff</a><br>
==============================================================================<br>
--- compiler-rt/trunk/lib/cfi/cfi.cc (original)<br>
+++ compiler-rt/trunk/lib/cfi/cfi.cc Wed Jan 27 18:37:54 2016<br>
@@ -306,12 +306,14 @@ ALWAYS_INLINE void CfiSlowPathCommon(u64<br>
// FIXME: call the ubsan handler if DiagData != nullptr?<br>
VReport(1, "CFI: invalid memory region for a check target: %p\n", Ptr);<br>
#ifdef CFI_ENABLE_DIAG<br>
- if (DiagData)<br>
+ if (DiagData) {<br>
__ubsan_handle_cfi_check_fail(<br>
reinterpret_cast<__ubsan::CFICheckFailData *>(DiagData),<br>
reinterpret_cast<uptr>(Ptr));<br>
- else<br>
+ return;<br>
+ } else {<br></blockquote><div><br></div><div>Drop the else-after-return, and possibly invert to reduce indentation:<br><br> if (!DiagData)<br> Trap();<br> __ubsaN-handle_...</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Trap();<br>
+ }<br>
#else<br>
Trap();<br>
#endif<br>
@@ -348,7 +350,8 @@ void InitializeFlags() {<br>
<br>
SetVerbosity(common_flags()->verbosity);<br>
<br>
- if (Verbosity()) ReportUnrecognizedFlags();<br>
+ if (Verbosity())<br>
+ ReportUnrecognizedFlags();<br>
<br>
if (common_flags()->help) {<br>
cfi_parser.PrintFlagDescriptions();<br>
<br>
Modified: compiler-rt/trunk/test/cfi/cross-dso/target_out_of_bounds.cpp<br>
URL: <a href="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" rel="noreferrer" target="_blank">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</a><br>
==============================================================================<br>
--- compiler-rt/trunk/test/cfi/cross-dso/target_out_of_bounds.cpp (original)<br>
+++ compiler-rt/trunk/test/cfi/cross-dso/target_out_of_bounds.cpp Wed Jan 27 18:37:54 2016<br>
@@ -20,9 +20,13 @@ int main(int argc, char *argv[]) {<br>
// enough to handle unaddressable vtables. TODO: fix this.<br>
void *empty = calloc(1, 128);<br>
uintptr_t v = (uintptr_t)empty + 64;<br>
- A *volatile p = new A();<br>
- for (uintptr_t *q = (uintptr_t *)p; q < (uintptr_t *)(p + 1); ++q)<br>
+ char *volatile p = reinterpret_cast<char *>(new A());<br>
+ for (uintptr_t *q = (uintptr_t *)p; q < (uintptr_t *)(p + sizeof(A)); ++q)<br>
*q = v;<br>
+<br>
+ // CHECK: runtime error: control flow integrity check for type 'A' failed during cast<br>
+ A *volatile pa = reinterpret_cast<A *>(p);<br>
+<br>
// CHECK: untime error: control flow integrity check for type 'A' failed during virtual call<br>
- p->f();<br>
+ pa->f();<br>
}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>