Skip to content

Commit

Permalink
Partial MacOS Support (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
njelich authored Mar 17, 2024
1 parent 84f2d4d commit 4c36a1f
Show file tree
Hide file tree
Showing 69 changed files with 569 additions and 25 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/darwin-arm64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: darwin-arm64

on:
push:
branches: [master]
pull_request:
branches: [master]
env:
CARGO_TERM_COLOR: always
jobs:
darwin-arm64:
runs-on: macos-14

steps:
- uses: actions/checkout@v4
- name: Install x86 Brew
run: arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
- name: Brew packages
continue-on-error: true
run: |
arch -x86_64 /usr/local/bin/brew update
arch -x86_64 /usr/local/bin/brew install gdb curl python llvm \
openjdk ca-certificates gnupg nodejs --overwrite
- name: Build
run: cargo build --all-features --verbose
- name: NPM packages
run: |
sudo npm install -g jsfuzz
sudo npm install --save-dev @jazzer.js/core
- name: Rust packages
run: |
curl https://sh.rustup.rs -o rustup.sh && chmod +x rustup.sh && \
./rustup.sh -y && rm rustup.sh
rustup install nightly
export PATH=/root/.cargo/bin:$PATH
cargo install cargo-fuzz
- name: Run tests
run: |
cargo test --release --verbose --lib -- --test-threads 1
cargo test --release --verbose --package casr
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![amd64](https://github.com/ispras/casr/actions/workflows/amd64.yml/badge.svg?branch=master)](https://github.com/ispras/casr/actions/workflows/amd64.yml)
[![aarch64](https://github.com/ispras/casr/actions/workflows/aarch64.yml/badge.svg?branch=master)](https://github.com/ispras/casr/actions/workflows/aarch64.yml)
[![riscv64](https://github.com/ispras/casr/actions/workflows/riscv64.yml/badge.svg?branch=master)](https://github.com/ispras/casr/actions/workflows/riscv64.yml)
[![darwin-arm64](https://github.com/ispras/casr/actions/workflows/darwin-arm64.yml/badge.svg?branch=master)](https://github.com/ispras/casr/actions/workflows/darwin-arm64.yml)
[![fuzzing](https://github.com/ispras/casr/actions/workflows/fuzzing.yml/badge.svg?branch=master)](https://github.com/ispras/casr/actions/workflows/fuzzing.yml)

# CASR: Crash Analysis and Severity Report
Expand Down
28 changes: 18 additions & 10 deletions casr/src/bin/casr-san.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use clap::{Arg, ArgAction, ArgGroup};
use gdb_command::mappings::{MappedFiles, MappedFilesExt};
use gdb_command::stacktrace::StacktraceExt;
use gdb_command::*;
use linux_personality::personality;
use regex::Regex;

use std::env;
Expand Down Expand Up @@ -141,15 +140,24 @@ fn main() -> Result<()> {
if argv.len() > 1 {
sanitizers_cmd.args(&argv[1..]);
}
let sanitizers_cmd = unsafe {
sanitizers_cmd.pre_exec(|| {
if personality(linux_personality::ADDR_NO_RANDOMIZE).is_err() {
panic!("Cannot set personality");
}
Ok(())
})
};
let sanitizers_result = util::get_output(sanitizers_cmd, timeout, true)?;
#[cfg(target_os = "macos")]
{
sanitizers_cmd.env("DYLD_NO_PIE", "1");
}
#[cfg(target_os = "linux")]
{
use linux_personality::{personality, ADDR_NO_RANDOMIZE};

unsafe {
sanitizers_cmd.pre_exec(|| {
if personality(ADDR_NO_RANDOMIZE).is_err() {
panic!("Cannot set personality");
}
Ok(())
})
};
}
let sanitizers_result = util::get_output(&mut sanitizers_cmd, timeout, true)?;
let sanitizers_stderr = String::from_utf8_lossy(&sanitizers_result.stderr);

if sanitizers_stderr.contains("Cannot set personality") {
Expand Down
45 changes: 45 additions & 0 deletions casr/tests/casr_tests/darwin_Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
all: test_returnAv test_segFaultOnPc test_abort test_destAv test_destAvNearNull test_sourceAv test_sourceAvNearNull test_callAv test_callAvTainted test_heapError test_canary test_badInstruction test_safeFunc test_stackOverflow test_destAvTainted test_DivByZero test_sigbus test_sig_me

test_returnAv: test_returnAv.c
gcc -g -O0 -fno-stack-protector test_returnAv.c -o ./mac_bin/test_returnAv
test_segFaultOnPc: test_segFaultOnPc.c
gcc -g -O0 -fno-stack-protector test_segFaultOnPc.c -o ./mac_bin/test_segFaultOnPc
test_abort: test_abort.c
gcc -g -O0 -D_FORTIFY_SOURCE=2 test_abort.c -o ./mac_bin/test_abort
test_destAv: test_destAv.c
gcc -g -O0 test_destAv.c -o ./mac_bin/test_destAv
test_destAvNearNull:
gcc -g test_destAvNearNull.c -o ./mac_bin/test_destAvNearNull
test_sourceAv: test_sourceAv.c
gcc -g test_sourceAv.c -o ./mac_bin/test_sourceAv
test_sourceAvNearNull: test_sourceAvNearNull.c
gcc -g test_sourceAvNearNull.c -o ./mac_bin/test_sourceAvNearNull
test_callAvTainted: test_callAv.c
gcc -g -O0 test_callAv.c -o ./mac_bin/test_callAvTainted
test_callAv: test_callAv.c
gcc -g -O2 test_callAv.c -o ./mac_bin/test_callAv
test_heapError: test_heapError.c
gcc -g -O0 test_heapError.c -o ./mac_bin/test_heapError
test_canary: test_returnAv.c
gcc -g -O0 -fstack-protector-all test_returnAv.c -o ./mac_bin/test_canary
test_safeFunc: test_returnAv.c
gcc -g -O2 test_returnAv.c -o ./mac_bin/test_safeFunc
test_badInstruction: test_badInstruction.c
gcc -O0 ./test_badInstruction.c -o ./mac_bin/test_badInstruction
test_stackOverflow: test_stackOverflow.c
gcc -O0 ./test_stackOverflow.c -o ./mac_bin/./test_stackOverflow
test_destAvTainted: test_destAvTainted.c
gcc -O0 ./test_destAvTainted.c -o ./mac_bin/./test_destAvTainted
test_DivByZero:
gcc -g test_DivByZero.c -o ./mac_bin/test_DivByZero
test_sigbus:
gcc -g test_sigbus.c -o ./mac_bin/test_sigbus
test_sig_me:
gcc -g test_sig_me.c -o ./mac_bin/test_sig_me

clean:
cd mac_bin && rm -f test_stackOverflow \
test_badInstruction test_safeFunc test_returnAv test_segFaultOnPc \
test_abort test_destAv test_destAvNearNull test_sourceAv \
test_sourceAvNearNull test_callAv test_heapError \
test_canary test_callAvTainted test_DivByZero test_destAvTainted
Binary file added casr/tests/casr_tests/mac_bin/test_DivByZero
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.test_DivByZero</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
triple: 'x86_64-apple-darwin'
binary-path: './mac_bin/test_DivByZero'
relocations:
- { offsetInCU: 0x26, offset: 0x26, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003F20, symSize: 0x65 }
- { offsetInCU: 0x41, offset: 0x41, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003F20, symSize: 0x65 }
...
Binary file added casr/tests/casr_tests/mac_bin/test_abort
Binary file not shown.
20 changes: 20 additions & 0 deletions casr/tests/casr_tests/mac_bin/test_abort.dSYM/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.test_abort</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
triple: 'x86_64-apple-darwin'
binary-path: './mac_bin/test_abort'
relocations:
- { offsetInCU: 0x26, offset: 0x26, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003F10, symSize: 0x61 }
- { offsetInCU: 0x41, offset: 0x41, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003F10, symSize: 0x61 }
...
Binary file added casr/tests/casr_tests/mac_bin/test_badInstruction
Binary file not shown.
Binary file added casr/tests/casr_tests/mac_bin/test_callAv
Binary file not shown.
20 changes: 20 additions & 0 deletions casr/tests/casr_tests/mac_bin/test_callAv.dSYM/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.test_callAv</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
triple: 'x86_64-apple-darwin'
binary-path: './mac_bin/test_callAv'
relocations:
- { offsetInCU: 0x26, offset: 0x26, size: 0x8, addend: 0x0, symName: _func1, symObjAddr: 0x0, symBinAddr: 0x100003F20, symSize: 0x10 }
- { offsetInCU: 0x33, offset: 0x33, size: 0x8, addend: 0x0, symName: _func1, symObjAddr: 0x0, symBinAddr: 0x100003F20, symSize: 0x10 }
- { offsetInCU: 0x48, offset: 0x48, size: 0x8, addend: 0x0, symName: _func2, symObjAddr: 0x10, symBinAddr: 0x100003F30, symSize: 0x10 }
- { offsetInCU: 0x5D, offset: 0x5D, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x20, symBinAddr: 0x100003F40, symSize: 0x50 }
...
Binary file added casr/tests/casr_tests/mac_bin/test_callAvTainted
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.test_callAvTainted</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
triple: 'x86_64-apple-darwin'
binary-path: './mac_bin/test_callAvTainted'
relocations:
- { offsetInCU: 0x26, offset: 0x26, size: 0x8, addend: 0x0, symName: _func1, symObjAddr: 0x0, symBinAddr: 0x100003EF0, symSize: 0x10 }
- { offsetInCU: 0x33, offset: 0x33, size: 0x8, addend: 0x0, symName: _func1, symObjAddr: 0x0, symBinAddr: 0x100003EF0, symSize: 0x10 }
- { offsetInCU: 0x48, offset: 0x48, size: 0x8, addend: 0x0, symName: _func2, symObjAddr: 0x10, symBinAddr: 0x100003F00, symSize: 0x10 }
- { offsetInCU: 0x5D, offset: 0x5D, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x20, symBinAddr: 0x100003F10, symSize: 0x87 }
...
Binary file added casr/tests/casr_tests/mac_bin/test_canary
Binary file not shown.
20 changes: 20 additions & 0 deletions casr/tests/casr_tests/mac_bin/test_canary.dSYM/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.test_canary</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
triple: 'x86_64-apple-darwin'
binary-path: './mac_bin/test_canary'
relocations:
- { offsetInCU: 0x26, offset: 0x26, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003ED0, symSize: 0x96 }
- { offsetInCU: 0x41, offset: 0x41, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003ED0, symSize: 0x96 }
...
Binary file added casr/tests/casr_tests/mac_bin/test_destAv
Binary file not shown.
20 changes: 20 additions & 0 deletions casr/tests/casr_tests/mac_bin/test_destAv.dSYM/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.test_destAv</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
triple: 'x86_64-apple-darwin'
binary-path: './mac_bin/test_destAv'
relocations:
- { offsetInCU: 0x26, offset: 0x26, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003ED0, symSize: 0x96 }
- { offsetInCU: 0x53, offset: 0x53, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003ED0, symSize: 0x96 }
...
Binary file added casr/tests/casr_tests/mac_bin/test_destAvNearNull
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.test_destAvNearNull</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
triple: 'x86_64-apple-darwin'
binary-path: './mac_bin/test_destAvNearNull'
relocations:
- { offsetInCU: 0x26, offset: 0x26, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003EC0, symSize: 0xB0 }
- { offsetInCU: 0x53, offset: 0x53, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003EC0, symSize: 0xB0 }
...
Binary file added casr/tests/casr_tests/mac_bin/test_destAvTainted
Binary file not shown.
Binary file added casr/tests/casr_tests/mac_bin/test_heapError
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.test_heapError</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
triple: 'x86_64-apple-darwin'
binary-path: './mac_bin/test_heapError'
relocations:
- { offsetInCU: 0x26, offset: 0x26, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003EE0, symSize: 0x8E }
- { offsetInCU: 0x41, offset: 0x41, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003EE0, symSize: 0x8E }
...
Binary file added casr/tests/casr_tests/mac_bin/test_returnAv
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.test_returnAv</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file not shown.
Loading

0 comments on commit 4c36a1f

Please sign in to comment.