Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ cover several other security-related topics. Stay tuned for updates from our tea
### Upcoming (!)

- kAFL
- Rust
- Formal verification and Tamarin

## Custom queries for static analysis tools
Expand Down
2 changes: 1 addition & 1 deletion content/docs/languages/rust/10-security-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ weight: 10

## Safety and security

The Rust compiler guarantees the memory safety of *safe* Rust: absent `unsafe` code, no undefined behavior or data race will happen during runtime, no matter the inputs. This guarantee does not extend to `unsafe` code—including `unsafe` code hidden in dependencies—which can cause undefined behavior if it is unsound.
The Rust compiler guarantees the memory safety of Rust: no undefined behavior or data race will happen during runtime, no matter the inputs.

Therefore, when security-testing Rust programs, it’s important to understand what is and what is not considered undefined behavior (UB). There is no sense in looking for double-free bugs in (safe) Rust, right? For the guarantees made by the Rust compiler, see the ["Behavior considered undefined"](https://doc.rust-lang.org/reference/behavior-considered-undefined.html) Rust Reference page.

Expand Down
10 changes: 4 additions & 6 deletions content/docs/languages/rust/20-dynamic-analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ mod tests {

Once you have the unit tests written and all of them pass, let’s improve on them.

{{< hint info >}}
To speed up the CI pipeline, use [`cargo-line-test`](https://github.com/trailofbits/cargo-line-test). It executes only the tests that exercise modified files and lines. It may be especially useful when using advanced but slow testing methods described later in this section.
{{< /hint >}}

## Randomization

### Test order shuffling
Expand Down Expand Up @@ -669,7 +665,7 @@ Three popular tools wrap the above engines for easier consumption in Rust projec
| Output format | LCOV, JSON, HTML, Cobertura, Coveralls+, Markdown, ADE | Text, LCOV, JSON, HTML, Cobertura, Codecov | Text, LCOV, JSON, HTML, XML |
| To exclude files | `--ignore` | [`--ignore-filename-regex`](https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#exclude-file-from-coverage) | `--exclude-files` |
| To exclude functions | With in-code markers and regexes | [With attributes](https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#exclude-code-from-coverage) | [With attributes](https://github.com/xd009642/tarpaulin?tab=readme-ov-file#ignoring-code-in-files) |
| To exclude test coverage | No | [With external module](https://github.com/taiki-e/coverage-helper/tree/v0.2.0) | `--ignore-tests` |
| To exclude test coverage | No | [Yes](https://github.com/taiki-e/cargo-llvm-cov/issues/123) | `--ignore-tests` |
| To enable coverage for C/C++ | Unknown | [`--include-ffi`](https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#get-coverage-of-cc-code-linked-to-rust-librarybinary) | Unknown |
| Merges runs across different builds? | No | [Yes](https://github.com/taiki-e/cargo-llvm-cov?tab=readme-ov-file#merge-coverages-generated-under-different-test-conditions) | [Yes](https://github.com/xd009642/tarpaulin?tab=readme-ov-file#command-line) (but only shows delta) |

Expand All @@ -679,9 +675,11 @@ Branch coverage from the LLVM source-based engine—the `branches` cells for `gr

While checking coverage statistics from a command line and using one of many coverage visualizers, an HTML report is often what you need.

<!-- Below we use ?: in links to make them open in a new tab -->

| HTML output/tool | `grcov` | `llvm-cov` | `tarpaulin` |
| :---- | :---- | :---- | :---- |
| Examples | [Open `grcov`]({{% staticref "/languages/rust/coverage/grcov_llvm/" %}}) [Open `grcov` with `lcov`]({{% staticref "/languages/rust/coverage/grcov_llvm_lcov/" %}}) | [Open `llvm-cov`]({{% staticref "/languages/rust/coverage/llvm_cov/" %}}) [Open `llvm-cov-pretty`]({{% staticref "/languages/rust/coverage/llvm_cov_pretty/" %}}) | [Open `tarpaulin`]({{% staticref "/languages/rust/coverage/tarpaulin-report.html" %}}) |
| Examples | [Open `grcov`]({{% staticref "/languages/rust/coverage/grcov_llvm/?:" %}}) [Open `grcov` with `lcov`]({{% staticref "/languages/rust/coverage/grcov_llvm_lcov/?:" %}}) | [Open `llvm-cov`]({{% staticref "/languages/rust/coverage/llvm_cov/?:" %}}) [Open `llvm-cov-pretty`]({{% staticref "/languages/rust/coverage/llvm_cov_pretty/?:" %}}) | [Open `tarpaulin`]({{% staticref "/languages/rust/coverage/tarpaulin-report.html?:" %}}) |
| Handles Rust constructs? | Yes | Yes | Yes |
| Expands Rust’s generics? | No | `--show-instantiations` | No |
| Includes number of hits? | Yes | Yes | Yes |
Expand Down
2 changes: 1 addition & 1 deletion content/docs/languages/rust/40-gotchas.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This section provides a checklist that can be used during manual Rust code revie
- [ ] Check string conversions to other data types (like `Vec`) and vice versa. These may come with UTF-8 encoding issues. Options for handling bytes that may not be valid UTF-8:
- `from_utf8` with `unwrap`—strict, panics on non-convertible data
- `from_utf8_lossy`—lossy, replaces invalid UTF-8 sequences with U+FFFD (replacement character)
- `OsStr`/`OsString`—for platform-native strings that may not be valid UTF-8 (e.g., paths, environment variables, and `argv`); it is not a UTF-8/bytes converter, and there is no portable way to get its raw bytes (`as_bytes` is Unix-only; `as_encoded_bytes` uses a non-portable encoding)
- `OsStr`/`OsString`—for platform-native strings; their `to_str` methods return None for non-UTF-8 data
- [ ] Verify that the `with_capacity` method of the `Vec`, `HashMap`, `HashSet`, and `indexmap::IndexSet` types (and possibly other types) is not called with user-controlled data. Large values can lead to denial of service.
- Also check that the provided capacity is smaller than the `isize::MAX` bytes [to prevent panics](https://doc.rust-lang.org/std/vec/struct.Vec.html#panics).
- Note that some methods—[like Serde’s `size_hint`](https://github.com/serde-rs/serde/issues/744)—may indirectly expose the `with_capacity` method.
Expand Down
3 changes: 2 additions & 1 deletion content/docs/languages/rust/80-supply-chain-analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ cargo deny check bans --exclude-dev
Look for `warning[duplicate]` outputs.
{{< /hint >}}

Similarly, a dependency that is obtained from multiple sources (e.g., crates.io and github.com) may indicate some issues. To report such offending dependencies, use [`cargo-deny`](https://github.com/EmbarkStudios/cargo-deny)'s `sources` check.
Similarly, a dependency that is obtained from multiple sources (e.g., crates.io and github.com) may indicate some issues. To report such offending dependencies, use [`cargo vendor`](https://doc.rust-lang.org/cargo/commands/cargo-vendor.html) or `cargo-deny`'s `sources` check.

```sh
cargo vendor --locked ./tmp_path
cargo deny check sources
```

Expand Down
2 changes: 1 addition & 1 deletion content/docs/languages/rust/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ u128|Box::new(std::iter::successors(Some(n),|&n|Some(n>>8)
</div>
{{< /rawHtml >}}

Start your review with our [rust-review](https://github.com/trailofbits/skills/tree/main/plugins/rust-review) skill. It covers basic issues.
Start your review with [rust-review](https://github.com/trailofbits/skills/tree/main/plugins/rust-review) skill. It covers basic issues.

{{< section >}}
Loading