Skip to content

Commit b3e73c3

Browse files
authored
Use CMake in llvm_mode (#61)
- Use CMake to compile in llvm_mode - Improve custom function context
1 parent d6b2ce0 commit b3e73c3

File tree

220 files changed

+1990
-410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+1990
-410
lines changed

.cirrus.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ angora_build_task:
44
cargo_cache:
55
folder: $CARGO_HOME/registry
66
# fingerprint_script: cat Cargo.lock
7-
build_script: ./build/build.sh
7+
build_script:
8+
- apt-get update
9+
- apt-get install -y cmake
10+
- cmake --version
11+
- ./build/build.sh
812
test_script: cargo test
913
before_cache_script: rm -rf $CARGO_HOME/registry/index

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ Cargo.lock
1111
GPATH
1212
GRTAGS
1313
GTAGS
14+
GSYMS
1415
output*/
1516
*.tar.gz
1617
*.tar.xz
1718
auto/
1819
/bin/
1920
obj-intel64/
20-
.DS_Store
21+
.DS_Store

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM ubuntu:16.04
22

33
RUN apt-get update && \
44
apt-get -y upgrade && \
5-
apt-get install -y git build-essential wget zlib1g-dev golang-go python-pip python-dev build-essential && \
5+
apt-get install -y git build-essential wget zlib1g-dev golang-go python-pip python-dev build-essential cmake && \
66
apt-get clean
77

88

angora_fuzzer

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if [ -z ${LOG_TYPE} ]
99
then LOG_TYPE="info"
1010
fi
1111

12-
envs="RUST_BACKTRACE=1 RUST_LOG=${LOG_TYPE}"
12+
envs="RUST_BACKTRACE=1 RUST_LOG=${LOG_TYPE} ANGORA_BIN_DIR=${FUZZ_DIR}/bin"
1313
fuzzer="${FUZZ_DIR}/target/${BUILD_TYPE}/fuzzer"
1414

1515
cmd="$envs $fuzzer $*"

build/build.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
#!/bin/bash
2+
BIN_PATH=$(readlink -f "$0")
3+
ROOT_DIR=$(dirname $(dirname $BIN_PATH))
24

35
set -euxo pipefail
46

57
if ! [ -x "$(command -v llvm-config)" ]; then
6-
./build/install_llvm.sh
8+
${ROOT_DIR}/build/install_llvm.sh
79
export PATH=${HOME}/clang+llvm/bin:$PATH
810
export LD_LIBRARY_PATH=${HOME}/clang+llvm/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
11+
export CC=clang
12+
export CXX=clang++
913
fi
1014

15+
PREFIX=${PREFIX:-${ROOT_DIR}/bin/}
16+
1117
cargo build
1218
cargo build --release
1319

14-
PREFIX=bin/
20+
rm -rf ${PREFIX}
1521
mkdir -p ${PREFIX}
16-
cp target/release/*.a ${PREFIX}
22+
mkdir -p ${PREFIX}/lib
1723
cp target/release/fuzzer ${PREFIX}
24+
cp target/release/*.a ${PREFIX}/lib
1825

26+
cd llvm_mode
27+
rm -rf build
28+
mkdir -p build
29+
cd build
30+
cmake -DCMAKE_INSTALL_PREFIX=${PREFIX} -DCMAKE_BUILD_TYPE=Release ..
31+
make # VERBOSE=1
32+
make install # VERBOSE=1
1933

20-
cd llvm_mode && make

build/install_pin_mode.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ PREFIX=/ ./install_pin.sh
99
make
1010
cp env.init /opt/
1111
cd ..
12-
make
12+
make OBJDIR=../bin/lib/

build/install_tools.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ set -euxo pipefail
55
#wllvm and gllvm
66
pip install --upgrade pip==9.0.3
77
pip install wllvm
8-
mkdir /go
8+
mkdir ${HOME}/go
99
go get github.com/SRI-CSL/gllvm/cmd/...
1010

common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "angora_common"
3-
version = "1.2.0"
3+
version = "1.2.1"
44
authors = ["sp1npx <[email protected]>"]
55
edition = "2018"
66

common/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ pub const PREFER_FAST_COND: bool = true;
1010

1111
// ************ Resources ****************
1212
// branch.rs
13-
pub const MAP_LENGTH: usize = 20;
14-
pub const BRANCHES_SIZE: usize = 1 << MAP_LENGTH;
13+
pub const MAP_SIZE_POW2: usize = 20;
14+
pub const BRANCHES_SIZE: usize = 1 << MAP_SIZE_POW2;
1515

1616
// executor.rs:
1717
pub const TMOUT_SKIP: usize = 3;

common/src/defs.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std;
22
// -- envs
33
pub static DISABLE_CPU_BINDING_VAR: &str = "ANGORA_DISABLE_CPU_BINDING";
4+
pub static ANGORA_BIN_DIR: &str = "ANGORA_BIN_DIR";
5+
46
// executor.rs
57
pub static TRACK_OUTPUT_VAR: &str = "ANGORA_TRACK_OUTPUT";
68
pub static COND_STMT_ENV_VAR: &str = "ANGORA_COND_STMT_SHM_ID";
@@ -34,12 +36,6 @@ pub const UNREACHABLE: u64 = std::u64::MAX;
3436

3537
// ** Cond Type
3638
// < 0xFF: simple if
37-
pub const COND_BASIC_MASK: u32 = 0xFF;
38-
pub const COND_SIGN_MASK: u32 = 0x100;
39-
pub const COND_BOOL_MASK: u32 = 0x200;
40-
// pub const COND_CALL_MASK: u32 = 0x400;
41-
// pub const COND_CALL_REV_MASK: u32 = 0xFBFF;
42-
4339
// http://llvm.org/doxygen/InstrTypes_8h_source.html
4440
// Opcode U L G E Intuitive operation
4541
pub const COND_FCMP_FALSE: u32 = 0;
@@ -87,6 +83,12 @@ pub const COND_ICMP_SLT_OP: u32 = 40;
8783
pub const COND_ICMP_SLE_OP: u32 = 41;
8884
pub const COND_SW_OP: u32 = 0x00FF;
8985

86+
pub const COND_BASIC_MASK: u32 = 0xFF;
87+
pub const COND_SIGN_MASK: u32 = 0x100;
88+
pub const COND_BOOL_MASK: u32 = 0x200;
89+
// pub const COND_CALL_MASK: u32 = 0x400;
90+
// pub const COND_CALL_REV_MASK: u32 = 0xFBFF;
91+
9092
pub const COND_MAX_EXPLORE_OP: u32 = 0x4000 - 1;
9193
pub const COND_MAX_EXPLOIT_OP: u32 = 0x5000 - 1;
9294

docs/build_target.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Example: how to custom `crc32` function in `zlib` library. (see `llvm_mode/exter
102102
./angora/tools/gen_library_abilist.sh /usr/lib/x86_64-linux-gnu/libz.so custom > zlib_abilist.txt
103103
104104
export ANGORA_TAINT_RULE_LIST=/path-to/zlib_abilist.txt
105-
# write your custom function, e.g. llvm_mode/external_lib/zlib-func.c
105+
# write your custom function, e.g. llvm_mode/external_lib/zlib-func.c and llvm_mode/external_lib/zlib_abilist.txt
106106
# compile it and
107107
export ANGORA_TAINT_CUSTOM_RULE=/path-to/zlib-func.o
108108
```
@@ -113,15 +113,15 @@ Use `USE_DFSAN=1 make` to build them.
113113

114114
## Build C++ program and C++ standard library
115115
- C++ program: CXX=/path-to-angora/bin/angora-clang++ or -DCMAKE_CXX_COMPILER=...
116-
- C++ standard library: we have built one under ubuntu 16.04 64bits in llvm_mode/libcxx_dfsan. You can built it by yourself with the following commands and move the libraries to llvm_mode/libcxx_dfsan directory and bin/. (run libcxx_dfsan/compile.sh)
116+
- C++ standard library: we have built one under ubuntu 16.04 64bits in llvm_mode/libcxx. You can built it by yourself with the following commands and move the libraries to llvm_mode/libcxx directory and bin/lib. (run libcxx_dfsan/compile.sh)
117117

118118
```
119119
# http://lists.llvm.org/pipermail/cfe-dev/2015-January/040876.html
120120
# install cmake ninja and download LLVM&CLANG source code
121121
CC=~/angora/bin/angora-clang CXX=~/angora/bin/angora-clang++ cmake -G Ninja ../llvm -DLIBCXXABI_ENABLE_SHARED=NO -DLIBCXX_ENABLE_SHARED=NO -DLLVM_FORCE_USE_OLD_TOOLCHAIN=YES -DLIBCXX_CXX_ABI=libcxxabi
122122
USE_DFSAN=1 ninja cxx cxxabi
123-
# move them to llvm_mode/libcxx_dfsan
123+
# move them to llvm_mode/libcxx and bin/lib
124124
```
125125

126126
## Add taints in input functions
127-
Angora models most input functions in `llvm_mode/io-func.c`. But it doesn't support some input functions like `scanf` or other input function in external libraries. You can add taints by yourself by the approach described in *Model an external library*. For example, program `who` use `getutxent` to read input, and we add taints in `__dfsw_getutxent` in `io-func.c` file.
127+
Angora models most input functions in `llvm_mode/external_lib/io-func.c`. But it doesn't support some input functions like `scanf` or other input function in external libraries. You can add taints by yourself by the approach described in *Model an external library*. For example, program `who` use `getutxent` to read input, and we add taints in `__dfsw_getutxent` in `io-func.c` file.

docs/configuration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Configuration Files
22

3-
- `llvm_mode/config.h`: Configuration file for llvm pass.
4-
- `llvm_mode/custom/angora_abilist.txt` : Taint propagation rules for functions in libraries in llvm mode.
5-
- `llvm_mode/custom/exploitation_list.txt` : Security sensitive functions or instructions in llvm mode.
3+
- `llvm_mode/include/defs.h`: Configuration and definition file for llvm pass.
4+
- `llvm_mode/rules/angora_abilist.txt` : Taint propagation rules for functions in libraries in llvm mode.
5+
- `llvm_mode/rules/exploitation_list.txt` : Security sensitive functions or instructions in llvm mode.
66
- `common/src/config.rs`: Configuration file for fuzzer.

docs/environment_variables.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
- `ANGORA_CUSTOM_FN_CONTEXT=k` : Use only the last k ( 0 <= k <= 32) function call location as the context, e.g. `ANGORA_CUSTOM_FN_CONTEXT=8`. Angora disables context if k is 0.
77
- `ANGORA_GEN_ID_RANDOM=1` : Generate ids for predicates randomly instead of the hash of their locations.
88
- `ANGORA_OUTPUT_COND_LOC=1` : (Debug option) Output the location of each predicate during compiling.
9-
- `ANGORA_TAINT_CUSTOM_RULE=/path/to/object` : object contains those proxy function (how to propagate taints), e.g. `ANGORA_TAINT_CUSTOM_RULE=~/angora/bin/zlib-func.o` . You should add it as custom type in the file passed by `ANGORA_TAINT_RULE_LIST` first.
10-
- `ANGORA_TAINT_RULE_LIST=/path/to/list` : DataFlowSanitizer’s [ABI list](https://clang.llvm.org/docs/DataFlowSanitizer.html), e.g. `ANGORA_TAINT_RULE_LIST=~/angora/bin/extra_list.txt`.
9+
- `ANGORA_TAINT_CUSTOM_RULE=/path/to/object` : object contains those proxy function (how to propagate taints), e.g. `ANGORA_TAINT_CUSTOM_RULE=~/angora/bin/lib/zlib-func.o` . You should add it as custom type in the file passed by `ANGORA_TAINT_RULE_LIST` first.
10+
- `ANGORA_TAINT_RULE_LIST=/path/to/list` : DataFlowSanitizer’s [ABI list](https://clang.llvm.org/docs/DataFlowSanitizer.html), e.g. `ANGORA_TAINT_RULE_LIST=~/angora/bin/rules/zlib_abilist.txt`.
1111

1212
# Environment variables for running
1313

docs/exploitation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Exploitation
22

3-
As BuzzFuzz, Angora supports finding which input bytes were processed by "attack point" we defined by taint tracking. You can add your custom "attack point" in `llvm_mode/custom/exploitation_list.txt`, and then recompile the tested program.
3+
As BuzzFuzz, Angora supports finding which input bytes were processed by "attack point" we defined by taint tracking. You can add your custom "attack point" in `llvm_mode/rules/exploitation_list.txt`, and then recompile the tested program.
44

55
```
66
# the 2th(start from 0) argument of function memeset is an attack point

docs/lava-who-fix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ base and bound information for allcoations. This only requires modifications to
2727
the `__dfsw_*alloc()` functions. The HashMap insertion, deletion and querying
2828
operations are implemented in Rust. The HashMap uses base pointer values as the
2929
key and bound values as the value. Minimal instrumentation is required for this
30-
approach. The source code can be found in the repository under the `llvm_mode`
30+
approach. The source code can be found in the repository under the `llvm_mode/external_lib`
3131
directory.
3232

3333
## Path Coverage (Unsolved)

docs/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ and precise input generation which significantly increases input coverage.
3434
- `src/stats`: Statistical chart.
3535
- `src/branches`: Branch counting.
3636
- `llvm_mode`: Includes source code for instrumenting compilers and DFSan, the taint tracking framework.
37+
- `pin_mode`: Includes source code for instrumenting based on Intel Pin.
3738
- `runtime`: Taint tracking runtime library for target program.
3839
- `runtime_fast`: Branch and constraint information collection library for target program.
3940
- `tests`: Sample tests to evaluate fuzzer performance.

docs/pin_mode.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export LIBDFT_PATH=/path-to-libdft64
1515
## Build Pin mode
1616
```
1717
cd pin_mode
18-
make
18+
make OBJDIR=../bin/lib/
1919
```
2020

2121
## Build a target program

docs/troubleshoot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ directory is populated. Otherwise no branches can be found.
1919

2020
- Multiple inconsistent warnings. It caused by the fast and track programs has different behaviors. If most constraints are inconsistent, ensure they are compiled with the same environment. Otherwise, report us.
2121

22-
- Density is too large (> 10%). Please increase `MAP_SIZE_POW2` in `llvm_mode/config.h` and `MAP_LENGTH` in `common/src/config.rs`. Or disable function-call context by compiling with `ANGORA_DISABLE_CONTEXT=1` or `ANGORA_DIRECT_FN_CONTEXT=1` environment variable.
22+
- Density is too large (> 10%). Please increase `MAP_SIZE_POW2` in `common/src/config.rs`. Or disable function-call context(density > 50%) by compiling with `ANGORA_CUSTOM_FN_CONTEXT=k` (k is an integer and 0 <= k <= 32) environment variable. Angora disables context if k is 0.

docs/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Angora usage
22
```
33
# /path-to-angora/angora_fuzzer --help
4-
angora-fuzzer 1.2.0
4+
angora-fuzzer 1.2.1
55
fuzz some program
66
77
USAGE:

fuzzer/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "angora"
3-
version = "1.2.0"
3+
version = "1.2.1"
44
authors = ["spinpx <[email protected]>"]
55
edition = "2018"
66

@@ -19,7 +19,7 @@ byteorder = "1.2"
1919
chrono = "0.4"
2020
priority-queue = "0.6"
2121
num_cpus = "1.0"
22-
derive_more = "0.14"
22+
derive_more = "0.15"
2323
colored = "1.6"
2424
serde="1.0"
2525
serde_derive = "1.0"

fuzzer/src/command.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{check_dep, search, tmpfs};
2+
use angora_common::defs;
23
use std::{
34
env,
45
path::{Path, PathBuf},
@@ -105,27 +106,19 @@ impl CommandOpt {
105106
let track_bin;
106107
let mut track_args = Vec::<String>::new();
107108
if mode.is_pin_mode() {
108-
// ugly
109-
let exe_path = env::current_exe().unwrap();
110-
let project_dir = exe_path
111-
.parent()
112-
.unwrap()
113-
.parent()
114-
.unwrap()
115-
.parent()
116-
.unwrap();
117-
109+
let project_bin_dir = env::var(defs::ANGORA_BIN_DIR).expect("Please set ANGORA_PROJ_DIR");
110+
118111
let pin_root =
119112
env::var(PIN_ROOT_VAR).expect("You should set the environment of PIN_ROOT!");
120113
let pin_bin = format!("{}/{}", pin_root, "pin");
121114
track_bin = pin_bin.to_string();
122-
let pin_tool = project_dir
123-
.join("pin_mode")
124-
.join("obj-intel64")
115+
let pin_tool = Path::new(&project_bin_dir)
116+
.join("lib")
125117
.join("pin_track.so")
126118
.to_str()
127119
.unwrap()
128120
.to_owned();
121+
129122
track_args.push(String::from("-t"));
130123
track_args.push(pin_tool);
131124
track_args.push(String::from("--"));

fuzzer/src/stats/chart.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl ChartStats {
126126
impl fmt::Display for ChartStats {
127127
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
128128
if self.density.0 > 10.0 {
129-
warn!("Density is too large (> 10%). Please increase `MAP_SIZE_POW2` in `llvm_mode/config.h` and `MAP_LENGTH` in `common/src/config.rs`. Or disable function-call context(density > 50%) by compiling with `ANGORA_CUSTOM_FN_CONTEXT=k` (k is an integer and 0 <= k <= 32) environment variable. Angora disables context if k is 0.");
129+
warn!("Density is too large (> 10%). Please increase `MAP_SIZE_POW2` in and `common/src/config.rs`. Or disable function-call context(density > 50%) by compiling with `ANGORA_CUSTOM_FN_CONTEXT=k` (k is an integer and 0 <= k <= 32) environment variable. Angora disables context if k is 0.");
130130
}
131131

132132
if self.search.multiple_inconsist() {

llvm_mode/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required(VERSION 3.4)
2+
3+
project(angora_llvm_mode VERSION 1.2.1 LANGUAGES C CXX ASM)
4+
5+
include_directories(include)
6+
include_directories(dfsan_rt)
7+
include_directories(../runtime/include)
8+
9+
set(ANGORA_BIN_DIR ".")
10+
set(ANGORA_LIB_DIR "lib")
11+
set(ANGORA_RULE_DIR "rules")
12+
set(ANGORA_PASS_DIR "pass")
13+
14+
add_subdirectory(compiler)
15+
add_subdirectory(pass)
16+
add_subdirectory(rules)
17+
add_subdirectory(libcxx)
18+
add_subdirectory(external_lib)
19+
add_subdirectory(dfsan_rt)

llvm_mode/Makefile

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)