Index: docs/ControlFlowIntegrity.rst =================================================================== --- docs/ControlFlowIntegrity.rst +++ docs/ControlFlowIntegrity.rst @@ -20,22 +20,49 @@ allowing developers to enable them in release builds. To enable Clang's available CFI schemes, use the flag ``-fsanitize=cfi``. -As currently implemented, all of Clang's CFI schemes (``cfi-vcall``, -``cfi-derived-cast``, ``cfi-unrelated-cast``, ``cfi-nvcall``, ``cfi-icall``) -rely on link-time optimization (LTO); so it is required to specify -``-flto``, and the linker used must support LTO, for example via the `gold -plugin`_. To allow the checks to be implemented efficiently, the program must +You can enable only a subset of offered :ref:`schemes `. +As currently implemented, all schemes rely on link-time optimization (LTO); +so it is required to specify ``-flto``, and the linker used must support LTO, +for example via the `gold plugin`_. +To allow the checks to be implemented efficiently, the program must be structured such that certain object files are compiled with CFI enabled, and are statically linked into the program. This may preclude the use of shared libraries in some cases. -Clang currently implements forward-edge CFI for member function calls and -bad cast checking. More schemes are under development. - .. _gold plugin: http://llvm.org/docs/GoldPlugin.html +.. _cfi-schemes: + +Available schemes +================= + +Available schemes are: + + - ``-fsanitize=cfi-cast-strict``: Enables :ref:`strict cast checks + `. + - ``-fsanitize=cfi-derived-cast``: Base-to-derived cast to the wrong + dynamic type. + - ``-fsanitize=cfi-unrelated-cast``: Cast from ``void*`` or another + unrelated type to the wrong dynamic type. + - ``-fsanitize=cfi-nvcall``: Non-virtual call via an object whose vptr is of + the wrong dynamic type. + - ``-fsanitize=cfi-vcall``: Virtual call via an object whose vptr is of the + wrong dynamic type. + - ``-fsanitize=cfi-icall``: Indirect call of a function with wrong dynamic + type. + +You can use ``-fsanitize=cfi`` to enable all the schemes and use +``-fno-sanitize`` flag to narrow down the set of schemes as desired. +For example, you can build your program with +``-fsanitize=cfi -fno-sanitize=cfi-nvcall`` +to use all schemes except for non-virtual member function call checking. + +Remember that you have to provide ``-flto`` if at least one CFI scheme is +enabled. + + Forward-Edge CFI for Virtual Calls ----------------------------------- +================================== This scheme checks that virtual calls take place using a vptr of the correct dynamic type; that is, the dynamic type of the called object must be a @@ -59,7 +86,7 @@ of up to 15% has been observed for Chromium. Bad Cast Checking ------------------ +================= This scheme checks that pointer casts are made to an object of the correct dynamic type; that is, the dynamic type of the object must be a derived class @@ -94,7 +121,7 @@ and be statically linked into the program. Non-Virtual Member Function Call Checking ------------------------------------------ +========================================= This scheme checks that non-virtual calls take place using an object of the correct dynamic type; that is, the dynamic type of the called object @@ -126,7 +153,7 @@ default. It can be disabled with ``-fsanitize=cfi-cast-strict``. Indirect Function Call Checking -------------------------------- +=============================== This scheme checks that function calls take place using a function of the correct dynamic type; that is, the dynamic type of the function must match @@ -176,7 +203,7 @@ .. _cfi-blacklist: Blacklist ---------- +========= A :doc:`SanitizerSpecialCaseList` can be used to relax CFI checks for certain source files, functions and types using the ``src``, ``fun`` and ``type`` @@ -200,12 +227,12 @@ type:attr:uuid Design ------- +====== Please refer to the :doc:`design document`. Publications ------------- +============ `Control-Flow Integrity: Principles, Implementations, and Applications `_. Martin Abadi, Mihai Budiu, Ăšlfar Erlingsson, Jay Ligatti. Index: docs/UsersManual.rst =================================================================== --- docs/UsersManual.rst +++ docs/UsersManual.rst @@ -974,19 +974,8 @@ There are more fine-grained checks available: see the :ref:`list ` of specific kinds of - undefined behavior that can be detected. Checks for :doc:`ControlFlowIntegrity` - are: - - - ``-fsanitize=cfi-cast-strict``: Enables :ref:`strict cast checks - `. - - ``-fsanitize=cfi-derived-cast``: Base-to-derived cast to the wrong - dynamic type. Requires ``-flto``. - - ``-fsanitize=cfi-unrelated-cast``: Cast from ``void*`` or another - unrelated type to the wrong dynamic type. Requires ``-flto``. - - ``-fsanitize=cfi-nvcall``: Non-virtual call via an object whose vptr is of - the wrong dynamic type. Requires ``-flto``. - - ``-fsanitize=cfi-vcall``: Virtual call via an object whose vptr is of the - wrong dynamic type. Requires ``-flto``. + undefined behavior that can be detected and the :ref:`list ` + of control flow integrity schemes. You can turn off or modify checks for certain source files, functions or even variables by providing a special file: