whatisgithub

What is clang-cfi-showcase?

trailofbits/clang-cfi-showcase — explained in plain English

Analysis updated 2026-07-25 · repo last pushed 2019-02-01

106C++Audience · researcherComplexity · 2/5DormantSetup · moderate

In one sentence

A set of C++ example programs that intentionally contain bugs to demonstrate how Clang's control flow integrity (CFI) protection blocks attacks at runtime. Each example builds a protected and unprotected version so you can see the difference.

Mindmap

mindmap
  root((repo))
    What it does
      Shows CFI protection
      Intentionally buggy programs
      Runtime attack blocking
    Examples included
      Wrong function calls
      Fake object types
      Bad type casting
    Tech stack
      C++ programs
      Clang compiler 3.7+
      Link-time optimization
    Audience
      Security researchers
      Developers learning mitigations
      Compiler security curious
    Setup
      Ubuntu and MacOS
      Specific Clang version
      LTO-compatible linker

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Run the protected and unprotected builds side-by-side to see how CFI stops runtime attacks.

USE CASE 2

Learn how attackers exploit type confusion and function pointer hijacking in C++ programs.

USE CASE 3

Evaluate whether enabling CFI in your own application would catch bugs that static analysis misses.

USE CASE 4

Use the examples as a companion to the Trail of Bits blog post on Clang CFI.

What is it built with?

C++ClangLink-Time Optimization

How does it compare?

trailofbits/clang-cfi-showcaseandrewrk/pydawmchughalex/skate3recomp
Stars106105108
LanguageC++C++C++
Last pushed2019-02-012010-08-27
MaintenanceDormantDormant
Setup difficultymoderatehardhard
Complexity2/53/54/5
Audienceresearcherdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Requires a specific Clang version (3.7+, 3.9 recommended) and a linker supporting link-time optimization.

So what is it?

Clang CFI Showcase is a collection of example programs that demonstrate a security feature called control flow integrity. The idea is straightforward: when software has a bug, attackers can sometimes exploit it by hijacking the program's execution and redirecting it to run malicious code. Control flow integrity, or CFI, is a defense that stops the program from jumping to places an attacker controls. This project provides hands-on examples showing how that protection works in practice. The repo contains several small programs, each with an intentionally planted bug. Every example builds two versions of the same program: one with CFI protection enabled and one without. By running both, you can see exactly what an attacker might achieve without protection and how CFI blocks them. The examples cover different attack scenarios, such as tricking a program into calling the wrong function, faking the type of an object to access functions that shouldn't be available, or casting an object to an unrelated type it doesn't actually belong to. This project is aimed at security researchers, developers learning about exploit mitigations, or anyone who wants to understand how compilers can help harden software against attacks. It accompanies a Trail of Bits blog post explaining CFI in Clang, and it works best as a companion to that material. Someone evaluating security features for a new application, or a developer curious about how modern compilers catch subtle bugs at runtime, would get a clear picture from these examples. The examples are written in C++ and require a specific version of the Clang compiler (3.7 or later, with 3.9 recommended) along with a linker that supports a technique called link-time optimization. The README includes installation instructions for Ubuntu Linux and MacOS. Notably, all the samples compile cleanly with Clang's maximum warning level, but the bugs they contain are not caught by the compiler itself. They are only detected when the program actually runs and CFI is enabled, which makes the point that CFI catches problems static analysis alone would miss.

Copy-paste prompts

Prompt 1
I cloned the clang-cfi-showcase repo. Walk me through building one example with CFI enabled and one without, and explain what attack the unprotected version is vulnerable to.
Prompt 2
Help me set up Clang with link-time optimization on Ubuntu so I can compile the clang-cfi-showcase examples and see CFI in action.
Prompt 3
Using the clang-cfi-showcase repo, explain the difference between the CFI-protected and unprotected builds for the type confusion example and what an attacker could do without CFI.
Prompt 4
I want to understand how Clang CFI catches bugs that the compiler warnings do not. Use the clang-cfi-showcase examples to show me why static analysis alone misses these issues.

Frequently asked questions

What is clang-cfi-showcase?

A set of C++ example programs that intentionally contain bugs to demonstrate how Clang's control flow integrity (CFI) protection blocks attacks at runtime. Each example builds a protected and unprotected version so you can see the difference.

What language is clang-cfi-showcase written in?

Mainly C++. The stack also includes C++, Clang, Link-Time Optimization.

Is clang-cfi-showcase actively maintained?

Dormant — no commits in 2+ years (last push 2019-02-01).

How hard is clang-cfi-showcase to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is clang-cfi-showcase for?

Mainly researcher.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.