Skip to content

Commit 33ba39b

Browse files
authored
Merge pull request #145 from rust-secure-code/wasm
WASM support
2 parents 1a53658 + 6bca5e4 commit 33ba39b

28 files changed

Lines changed: 807 additions & 32 deletions

File tree

.github/workflows/linux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
- uses: actions-rs/toolchain@v1
2828
with:
2929
toolchain: ${{ matrix.toolchain }}
30+
target: "wasm32-unknown-unknown"
3031
profile: minimal
3132
override: true
3233
# multiple additional targets are not supported, so we invoke the action multiple times

.github/workflows/mac.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ jobs:
2929
toolchain: ${{ matrix.toolchain }}
3030
profile: minimal
3131
override: true
32+
target: "wasm32-unknown-unknown"
3233
- run: cargo test --all-features --workspace

.github/workflows/windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
toolchain: ${{ matrix.toolchain }}
3030
profile: minimal
3131
override: true
32-
target: "x86_64-pc-windows-msvc"
32+
target: "wasm32-unknown-unknown"
3333
- name: "Test on the native x86_64-pc-windows-mscv"
3434
run: cargo test --all-features --workspace
3535
- name: "Test when cross-compiling to x86_64-pc-windows-gnu"

Cargo.lock

Lines changed: 73 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Know the exact crate versions used to build your Rust executable. Audit binaries
44

55
This works by embedding data about the dependency tree in JSON format into a dedicated linker section of the compiled executable.
66

7-
Linux, Windows and Mac OS are officially supported. All other ELF targets should work, but are not tested on CI. WASM is currently not supported, but patches are welcome.
7+
Linux, Windows and Mac OS are officially supported. [WebAssembly](https://en.wikipedia.org/wiki/WebAssembly) is also supported starting with v0.6.3. All other ELF targets should work, but are not tested on CI.
88

99
The end goal is to get Cargo itself to encode this information in binaries. There is an RFC for an implementation within Cargo, for which this project paves the way: https://github.com/rust-lang/rfcs/pull/2801
1010

auditable-extract/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "auditable-extract"
3-
version = "0.3.2"
3+
version = "0.3.3"
44
authors = ["Sergey \"Shnatsel\" Davidoff <shnatsel@gmail.com>"]
55
license = "MIT OR Apache-2.0"
66
repository = "https://github.com/rust-secure-code/cargo-auditable"
@@ -12,3 +12,7 @@ edition = "2018"
1212

1313
[dependencies]
1414
binfarce = "0.2"
15+
wasmparser = { version = "0.206.0", optional = true }
16+
17+
[features]
18+
wasm = ["wasmparser"]

auditable-extract/fuzz/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target
2+
corpus
3+
artifacts
4+
coverage

auditable-extract/fuzz/Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = "auditable-extract-fuzz"
3+
version = "0.0.0"
4+
publish = false
5+
edition = "2018"
6+
7+
[package.metadata]
8+
cargo-fuzz = true
9+
10+
[dependencies]
11+
libfuzzer-sys = "0.4"
12+
13+
[dependencies.auditable-extract]
14+
path = ".."
15+
features = ["wasm"]
16+
17+
# Prevent this from interfering with workspaces
18+
[workspace]
19+
members = ["."]
20+
21+
[profile.release]
22+
debug = 1
23+
24+
[[bin]]
25+
name = "parse_wasm"
26+
path = "fuzz_targets/parse_wasm.rs"
27+
test = false
28+
doc = false
29+
30+
# The other format parsers are tested as part of the `binfarce` crate
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![no_main]
2+
3+
use libfuzzer_sys::fuzz_target;
4+
5+
fuzz_target!(|data: &[u8]| {
6+
let _ = auditable_extract::raw_auditable_data_wasm_for_fuzz(data);
7+
});

auditable-extract/src/lib.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//!
66
//! This crate parses platform-specific binary formats ([ELF](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format),
77
//! [PE](https://en.wikipedia.org/wiki/Portable_Executable),
8-
//! [Mach-O](https://en.wikipedia.org/wiki/Mach-O)) and obtains the compressed audit data.
8+
//! [Mach-O](https://en.wikipedia.org/wiki/Mach-O), [WASM](https://en.wikipedia.org/wiki/WebAssembly)) and obtains the compressed audit data.
99
//!
1010
//! Unlike other binary parsing crates, it is specifically designed to be resilient to malicious input.
1111
//! It 100% safe Rust (including all dependencies) and performs no heap allocations.
@@ -15,7 +15,7 @@
1515
//! **Note:** this is a low-level crate that only implements binary parsing. It rarely should be used directly.
1616
//! You probably want the higher-level [`auditable-info`](https://docs.rs/auditable-info) crate instead.
1717
//!
18-
//! The following snippet demonstrates full extraction pipeline, including decompression
18+
//! The following snippet demonstrates full extraction pipeline using this crate, including decompression
1919
//! using the safe-Rust [`miniz_oxide`](http://docs.rs/miniz_oxide/) and optional JSON parsing
2020
//! via [`auditable-serde`](http://docs.rs/auditable-serde/):
2121
//!
@@ -42,6 +42,22 @@
4242
//! Ok(())
4343
//! }
4444
//! ```
45+
//!
46+
//! ## WebAssembly support
47+
//!
48+
//! We use a third-party crate [`wasmparser`](https://crates.io/crates/wasmparser)
49+
//! created by Bytecode Alliance for parsing WebAssembly.
50+
//! It is a robust and high-quality parser, but its dependencies contain some `unsafe` code,
51+
//! most of which is not actually used in our build configuration.
52+
//!
53+
//! We have manually audited it and found it to be sound.
54+
//! Still, the security guarantees for it are not as ironclad as for other parsers.
55+
//! Because of that WebAssembly support is gated behind the optional `wasm` feature.
56+
//! Be sure to [enable](https://doc.rust-lang.org/cargo/reference/features.html#dependency-features)
57+
//! the `wasm` feature if you want to parse WebAssembly.
58+
59+
#[cfg(feature = "wasm")]
60+
mod wasm;
4561

4662
use binfarce::Format;
4763

@@ -75,10 +91,22 @@ pub fn raw_auditable_data(data: &[u8]) -> Result<&[u8], Error> {
7591
.ok_or(Error::NoAuditData)?;
7692
Ok(data.get(section.range()?).ok_or(Error::UnexpectedEof)?)
7793
}
78-
_ => Err(Error::NotAnExecutable),
94+
Format::Unknown => {
95+
#[cfg(feature = "wasm")]
96+
if data.starts_with(b"\0asm") {
97+
return wasm::raw_auditable_data_wasm(data);
98+
}
99+
100+
Err(Error::NotAnExecutable)
101+
}
79102
}
80103
}
81104

105+
#[cfg(all(fuzzing, feature = "wasm"))]
106+
pub fn raw_auditable_data_wasm_for_fuzz(input: &[u8]) -> Result<&[u8], Error> {
107+
wasm::raw_auditable_data_wasm(input)
108+
}
109+
82110
#[derive(Debug, Copy, Clone)]
83111
pub enum Error {
84112
NoAuditData,

0 commit comments

Comments
 (0)