Coder Social home page Coder Social logo

mustakimur / os-cfi Goto Github PK

View Code? Open in Web Editor NEW
35.0 1.0 13.0 66.06 MB

Origin-sensitive Control Flow Integrity (OS-CFI) - USENIX Security 2019

Home Page: https://www.usenix.org/conference/usenixsecurity19/presentation/khandaker

License: GNU General Public License v2.0

C 7.53% C++ 43.29% Objective-C 1.77% CMake 0.19% Shell 0.03% Go 0.04% OCaml 0.13% Python 0.51% CSS 0.01% Batchfile 0.01% Roff 0.01% LLVM 32.93% Assembly 12.41% HTML 0.44% Swift 0.01% Perl 0.04% Dockerfile 0.01% Emacs Lisp 0.01% Objective-C++ 0.54% Cuda 0.10%
llvm control-flow-integrity control-flow-graph clang security-tools

os-cfi's Introduction

Origin-sensitive Control Flow Integrity

We propose a new context for CFI, origin sensitivity, that can effectively break down large ECs and reduce the average and largest EC size. Origin-sensitive CFI (OS-CFI) takes the origin of the code pointer called by an ICT as the context and constrains the targets of the ICT with this context. It supports both C-style indirect calls and C++ virtual calls. Additionally, we leverage common hardware features in the commodity Intel processors (MPX and TSX) to improve both security and performance of OS-CFI. Our evaluation shows that OS-CFI can substantially reduce the largest and average EC sizes (by 98% in some cases) and has strong performance – 7.6% overhead on average for all C/C++ benchmarks of SPEC CPU2006 and NGINX.

Note: Intel MPX is deprecated in latest CPU and kernel, so some part of code will require to adjust for latest.

Join us in the slack

IMPORTANT

This is a research prototype. Its sole purpose is to demonstrate that the original concept works. It is expected to have implementation flaws or can be broken/deprecated to latest sysyem. We welcome efforts to re-produce/evaluate our results but request an opportunity to fix any technical flaws. Generally speaking, we value design flaws more but will try to fix technical issues too.

If you plan to use this project in production, we would love to hear about it and provide help if needed (Join our slack channel).

This project is licensed in GPLv3 with the following additional conditions:

  1. If you plan to benchmark, compare, evaluate this project with intention to publish the results (including in a paper), you must first contact us with your real identity, affiliation, and advisors, and a short description of how you will use our source code (before any claim). In addition, you should provide an opportunity for us to comment on and help with technical and other issues related to this project. Examples include but are not limited to failure to compile or incomplete protection.

  2. If you use any part of this project (excluding third-party software) and published a paper about it, you agree to open-source your project within one month of the paper (of any publicly available location) publication.

Note: If you do not agree to these conditions, please do not use our source code.

Project Structure

  • llvm-src: LLVM/Clang 7.0 Source Directory.
    • clang/lib/CodeGen: Fake reference monitor and metadata update Instrumentation.
    • llvm/lib/Transforms/instCFG: CFG, optimization, and original reference monitor instrumentation.
  • oscfi-lib-src: OSCFI reference monitor and metadata source code.
  • svf-src: Modified DDA to generate CFG and tag locations (for label-as-value).
  • pyScript: Python code works on DDA generated CFG to reconstruct the original CFG.
  • testSuite: Stores sample cases to test the project.
  • run.sh: Bash script to run the OSCFI on any targeted project.

Overall Process

  • Step 1: Copy OSCFI monitor codes.
  • Step 2: Build the target project with OSCFI clang/clang++.
  • Step 3: Run SVF-SUPA (DDA) from OSCFI to generate the CFG. It also creates labels for translation (also known as label-as-value).
  • Step 4: Build the binary. Later, dump the section 'cfg_label_tracker' from the binary. Finally, run a python script to reconstruct the CFG.
  • Step 5: Instrument the CFG using a LLVM pass.
  • Step 6: Repeat step 4 and 5 to reconstruct the CFG due to optimization effect.
  • Step 7: Build the final binary (secured by OSCFI).

Docker Installation

To build a docker image, we have provided a Dockerfile. Follow the following commands to build and run:

docker build -t <any-name>/oscfi:1.0 .
docker run -it <any-name>/oscfi:1.0 /bin/bash

Manual Installation

The following guideline assumes a fresh ubuntu:21.04 docker container has been used. We recommend to use the docker installation guideline (check above).

Following commands are for preparing basic tools:

apt update
apt upgrade
apt install git cmake g++ python python3-pip wget

Following commands are for preparing radare2 (a binary diassembler):

wget https://radare.mikelloc.com/get/4.5.0-git/radare2\_4.5.0-git\_amd64.deb
dpkg -i radare2\_4.5.0-git\_amd64.deb
pip install r2pipe
rm radare2\_4.5.0-git\_amd64.debrm radare2\_4.5.0-git\_amd64.deb

Following commands are for configuring the build:

git clone https://github.com/mustakimur/OS-CFI.git
echo "export OSCFI_PATH=\\"/home/OS-CFI\\"" >> ~/.profile
source ~/.profile

Following commands are for preparing Gold plugin build:

apt-get install linux-headers-5.11.0-17-generic csh gawk automake libtool bison flex libncurses5-dev
apt-get install apt-file texinfo texi2html
apt-file update
apt-file search makeinfo

Following commands are for building binutils required for Gold plugin:

cd /home
git clone --depth 1 git://sourceware.org/git/binutils-gdb.git binutils
mkdir binutils-build
cd binutils-build
../binutils/configure --disable-gdb --enable-gold --enable-plugins --disable-werror
make

Following commands are for building compiler with Gold plugin:

cd $OSCFI_PATH/
mkdir llvm-obj
cd llvm-obj/
cmake -DLLVM_BINUTILS_INCDIR="/home/binutils/include" -G "Unix Makefiles" ../llvm-src
make -j8

Following commands are for replacing existing binaries with Gold plugin binaries:

cd /home
mkdir backup
cd /usr/bin/

cp ar /home/backup/
cp nm /home/backup/
cp ld /home/backup/
cp ranlib /home/backup/

cp /home/binutils-build/binutils/ar ./
rm nm
cp /home/binutils-build/binutils/nm-new ./nm
cp /home/binutils-build/binutils/ranlib ./
cp /home/binutils-build/gold/ld-new ./ld

cd /usr/lib
cd bfd-plugins
cp $OSCFI_PATH/llvm-obj/lib/LLVMgold.so ./
cp $OSCFI_PATH/llvm-obj/lib/libLTO.* ./

Following commands are for building SVF-SUPA (for CFG generation):

cd $OSCFI_PATH/svf-src

export LLVM_SRC="$OSCFI_PATH/llvm-src"
export LLVM_OBJ="$OSCFI_PATH/llvm-obj"
export LLVM_DIR="$OSCFI_PATH/llvm-obj"
export PATH=$LLVM_DIR/bin:$PATH

mkdir debug-build
cd debug-build
cmake -D CMAKE_BUILD_TYPE:STRING=Debug ../
make -j4

export PATH=$OSCFI_PATH/svf-src/debug-build/bin:$PATH

Spec Benchmark Build Guideline [deprecated: update soon]

  1. Put spec2006-oscfi.cfg file into folder $CPU2006_HOME/config and analyze CPU2006 to generate bc files
cd $CPU2006_HOME
. ./shrc
rm -rf benchspec/CPU2006/*/exe/
runspec  --action=run --config=spec2006-oscfi.cfg --tune=base --size=test --iterations=1 --noreportable all
  1. Change the Makefile.spec in the build directory of the benchmark (e.g. ~/spec/benchspec/CPU2006/456.hmmer/build/build_base_amd64-m64-softbound-nn.0000/Makefile.spec):
# add oscfi.c, mpxrt.c, mpxrt-utils.c in the source list, keep others same
SOURCES=oscfi.c mpxrt.c mpxrt-utils.c ...
  1. Use the run.sh to start the system.

Sample Tests

  • Vulnerable code exploitation prevented by OS-CFI:
cd testSuite
./test_run.sh
  • For CPU2006spec 456.hmmer benchmark:
./test_hmmer.sh < inHmmer

os-cfi's People

Contributors

mustakimur avatar syssecfsu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

os-cfi's Issues

No lib folder on step 9.

I have implemented the installation procedure from the beginning but I stuck on step 9. There is no lib folder on llvm-obj. What may be the problem? I think the step 6 was not shown completely. I am presenting your paper this Friday, so wanted to experiment the results.

About the specific SPEC CPU2006’s version?

I am a postgraduate from a university in China and I am currently reproducing your thesis. However,  I encountered a problem that the number of indirect calls are not the same as your sheet in your paper.(**I am testing under SPEC CPU2006 v1.2**)
**Anyway, I would like to ask what is your specific version about the SPEC CPU2006? Hope to hear from you and wish you a happy life!**

How can i debug this project

Hello,
I want to debug your project to instrument helloworld.c ,but i have no idea.
Could you tell me the debug process Step by step?Thanks!

Hello, I am a Chinese university student and I want to use your project.However, a problem occurred during the test using

First of all, I'm very sorry that I downloaded your project without contacting you. In my graduation project I want to generate the CFG of the program, so I would like to see your generated CFG. I use ubuntu22.04 to compile the project. But the sample_exec compiled after I run test_run.sh cannot run normally, and the error message is similar: [Unexpected trap 13! at 0x402908(core dumped). And the cpp program I tested also has this problem. May I ask what the possible question is?where does the CFG exist?Thank you so much!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.