[PATCH] Implement bad cast checks using control flow integrity information.
Peter Collingbourne
peter at pcc.me.uk
Fri Mar 13 15:47:04 PDT 2015
> Please also add compiler-rt test(s)
Will do
================
Comment at: docs/UsersManual.rst:971
@@ -970,1 +970,3 @@
where the array bound can be statically determined.
+ - ``-fsanitize=cfi-dcast``: Base-to-derived cast to the wrong
+ dynamic type. Implies ``-flto``.
----------------
kcc wrote:
> Don't we want more verbose names?
> cfi-polymorphic-base-downcast
> cfi-void-to-polymorphic-cast
> or something.
>
Okay, I've given these better names.
================
Comment at: docs/UsersManual.rst:974
@@ -971,1 +973,3 @@
+ - ``-fsanitize=cfi-vcast``: Cast from ``void*`` or another unrelated
+ type to the wrong dynamic type. Implies ``-flto``.
- ``-fsanitize=cfi-vptr``: Use of an object whose vptr is of the
----------------
jfb wrote:
> Add `-fsanitize=cfi-cast-strict`?
Done.
================
Comment at: lib/CodeGen/CGClass.cpp:2121
@@ +2120,3 @@
+ if (MD->isVirtual()) {
+ // Virtual member functions are only ok if they are implicit destructors.
+ if (isa<CXXDestructorDecl>(MD) && MD->isImplicit())
----------------
jfb wrote:
> Why?
Explained in comment.
================
Comment at: test/CodeGenCXX/cfi-cast.cpp:4
@@ +3,3 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-vcast,cfi-cast-strict -emit-llvm -o - %s | FileCheck -check-prefix=CHECK-VCAST-STRICT %s
+
+struct A {
----------------
jfb wrote:
> Could you have a quick blurb that helps decipher the `metadata !"1B'` part, explaining that it's the important bit in the checks.
Done
================
Comment at: test/CodeGenCXX/cfi-cast.cpp:15
@@ +14,3 @@
+
+// CHECK-DCAST: define void @_Z3abpP1A
+void abp(A *a) {
----------------
jfb wrote:
> `CHECK-LABEL-DCAST` (same below).
Done
================
Comment at: test/CodeGenCXX/cfi-cast.cpp:77
@@ +76,2 @@
+ static_cast<C*>(p);
+}
----------------
jfb wrote:
> Add rvalue ref test?
>
> ```
> A a();
>
> B rvalue() {
> return static_cast<B&&>(a());
> }
> ```
Done.
http://reviews.llvm.org/D8312
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the cfe-commits
mailing list