All Projects → trailofbits → Clang Cfi Showcase

trailofbits / Clang Cfi Showcase

Licence: other
Sample programs that illustrate how to use control flow integrity with the clang compiler

Labels

Projects that are alternatives of or similar to Clang Cfi Showcase

Directxmath
DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps
Stars: ✭ 859 (+1001.28%)
Mutual labels:  clang
Zapcc
zapcc is a caching C++ compiler based on clang, designed to perform faster compilations
Stars: ✭ 1,109 (+1321.79%)
Mutual labels:  clang
Seriouscode
This header file enforces Clang warnings to bu turned-on for specific flags (almost everyone, at least each one I was able to find).
Stars: ✭ 68 (-12.82%)
Mutual labels:  clang
Pyc Cfg
Pyc-cfg is a pure python control flow graph builder for almost all Ansi C programming language.
Stars: ✭ 29 (-62.82%)
Mutual labels:  clang
Llvm 9.0 Learner Tutorial
A blog for LLVM(v9.0.0 or v11.0.0) beginner, step by step, with detailed documents and comments. Record the way I learn LLVM and accomplish a complete project for FPGA High-Level Synthesis with it.
Stars: ✭ 58 (-25.64%)
Mutual labels:  clang
Optviewer Demo
Demonstration of LLVM's opt-viewer tool
Stars: ✭ 63 (-19.23%)
Mutual labels:  clang
Clif
Binding generator to wrap C++ for Python using LLVM.
Stars: ✭ 845 (+983.33%)
Mutual labels:  clang
Cvise
Super-parallel Python port of the C-Reduce
Stars: ✭ 77 (-1.28%)
Mutual labels:  clang
Cxxctp
DEPRECATED. USE INSTEAD github.com/blockspacer/flextool
Stars: ✭ 58 (-25.64%)
Mutual labels:  clang
Ccache
ccache – a fast compiler cache
Stars: ✭ 1,128 (+1346.15%)
Mutual labels:  clang
Kfr
Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Stars: ✭ 985 (+1162.82%)
Mutual labels:  clang
C2goasm
C to Go Assembly
Stars: ✭ 1,072 (+1274.36%)
Mutual labels:  clang
Avalonstudio
Cross platform IDE and Shell
Stars: ✭ 1,132 (+1351.28%)
Mutual labels:  clang
Xcodecompilationdatabase
Generate a Compilation Database from Xcode's build log - nothing more :).
Stars: ✭ 28 (-64.1%)
Mutual labels:  clang
Seeless
C IDE for iOS
Stars: ✭ 71 (-8.97%)
Mutual labels:  clang
Irony Mode
A C/C++ minor mode for Emacs powered by libclang
Stars: ✭ 851 (+991.03%)
Mutual labels:  clang
Clang Blueprint
🏰 Example C++11 CMake project that incorporates awesome Clang tooling 🐉
Stars: ✭ 63 (-19.23%)
Mutual labels:  clang
Codechecker
CodeChecker is an analyzer tooling, defect database and viewer extension for the Clang Static Analyzer and Clang Tidy
Stars: ✭ 1,209 (+1450%)
Mutual labels:  clang
Meta Clang
Clang C/C++ cross compiler and runtime for OpenEmbedded/Yocto Project
Stars: ✭ 76 (-2.56%)
Mutual labels:  clang
Clang Callgraph
A tool based on clang which generates a call graph from a given C++ codebase
Stars: ✭ 65 (-16.67%)
Mutual labels:  clang

Clang CFI Showcase

Control flow integrity is an exploit mitigation, like stack cookies, DEP, and ASLR. Like other exploit mitigations, the goal of CFI is to prevent bugs from turning into exploits. CFI works by reducing the ability of an attacker to redirect program execution to an attacker controlled destination.

We have created samples with specially crafted bugs to showcase clang's control flow integrity implementation. These examples are an accompaniment to our blog post describing CFI in clang.

All of the samples are designed to compile cleanly with the absolute maximum warning level* (-Weverything).

The bugs in these examples are not statically identified by the compiler, but are detected at runtime via CFI. Where possible, we simulate potential malicious behavior that occurs without CFI protections.

Each example builds two binaries, one with CFI protection (e.g. cfi_icall) and one without CFI protections (e.g. no_cfi_icall).

*Ok, we lied, we had to disable two warnings, one about C++98 compatibility, and one about virtual functions being defined inline. The point is still valid since those warnings do not relate to potential bugs.

CFI Examples

  • cfi_icall demonstrates control flow integrity of indirect calls. The example binary accepts a single command line argument (valid values are 0-3, but try invalid values with both binaries!). The command line argument shows different aspects of indirect call CFI protection, or lack thereof.
  • cfi_vcall shows an example of CFI applied to virtual function calls. This example demonstrates how CFI would protect against a type confusion or similar attack.
  • cfi_nvcall shows clang’s protections for calling non-virtual member functions via something that is not an object that has those functions defined.
  • cfi_unrelated_cast shows how clang can prevent casts between objects of unrelated types.
  • cfi_derived_cast expands on cfi_unrelated_cast and shows how clang can prevent casts from an object of a base class to an object of a derived class, if the object is not actually of the derived class.
  • cfi_cast_strict showcases the very specific instance where the default level of base-to-derived cast protection, like in cfi_derived_cast, would not catch an illegal cast.

Requirements

These examples assume a Linux build environment with clang-3.9 and the GNU gold linker.

They should be portable to other operating systems; the only strict requirements are clang 3.7+ and an LTO capable linker.

Installing clang 3.9 on Linux

The following commands should install clang 3.9 on Ubuntu-based Linux distriutions.

UBUNTU_RELEASE=`lsb_release -sc`
sudo apt-get install -y software-properties-common build-essential
wget -qO - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository -y "deb http://apt.llvm.org/${UBUNTU_RELEASE}/ llvm-toolchain-${UBUNTU_RELEASE}-3.9 main"
sudo apt-get update
sudo apt-get install -y clang-3.9

Installing clang 3.9 on MacOS

The following instructions work to install clang 3.9 on MacOS 10.11 (El Capitan) and MacOS 10.12 (Sierra). These instructions are adapted from this Github issues post.

curl -O http://llvm.org/releases/3.9.0/clang+llvm-3.9.0-x86_64-apple-darwin.tar.xz
tar xJf clang+llvm-3.9.0-x86_64-apple-darwin.tar.xz
sudo mkdir -p /opt
sudo mv clang+llvm-3.9.0-x86_64-apple-darwin /opt/llvm39

export CC=/opt/llvm39/bin/clang
export CXX=/opt/llvm39/bin/clang++
export PATH=/opt/llvm39/bin:$PATH
export C_INCLUDE_PATH=/opt/llvm39/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/opt/llvm39/include:$CPLUS_INCLUDE_PATH
export LIBRARY_PATH=/opt/llvm39/lib:$LIBRARY_PATH
export DYLD_LIBRARY_PATH=/opt/llvm39/lib:$DYLD_LIBRARY_PATH

Makefile changes are needed to build these samples on MacOS:

  • The CC and CXX variables should say clang, and not clang-3.9
  • The default linker on MacOS supports LTO; the -B${GOLD} flag should be removed.

After these changes, the header of the Makefile should look similar to the following:

CXX = /opt/llvm39/bin/clang++
CC = /opt/llvm39/bin/clang
CFLAGS = -Weverything -Werror -pedantic -std=c99 -O0 -fvisibility=hidden -flto -fno-sanitize-trap=all
CXXFLAGS = -Weverything -Werror -pedantic -Wno-c++98-compat -Wno-weak-vtables -std=c++11 -O0 -fvisibility=hidden -flto -fno-sanitize-trap=all
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].