forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 58
Add RAPx tool description and CI workflow #491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DiuDiu777
wants to merge
2
commits into
model-checking:main
Choose a base branch
from
Artisan-Lab:rapx-verify-std
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: RAPx | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [main,rapx-verify-std] | ||
pull_request: | ||
branches: [main,rapx-verify-std] | ||
|
||
env: | ||
RAPx_VERSION: "2f8cefc8a4bbd7c347e02e97c61de1d8224776ba" | ||
SAFETY_TOOL_VERSION: "6b77419da66865bb5a36b6c9baec71b3e833d3c9" | ||
|
||
jobs: | ||
check-with-rapx: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: true | ||
|
||
- name: Clone and setup safety_tool | ||
run: | | ||
git clone https://github.com/Artisan-Lab/tag-std.git | ||
cd tag-std | ||
git checkout $SAFETY_TOOL_VERSION | ||
cargo install cargo-expand | ||
cd safety-tool | ||
TOOL_DIR=$(pwd) | ||
echo "TOOL_DIR=$TOOL_DIR" >> $GITHUB_ENV | ||
rm -f rust-toolchain.toml | ||
./gen_rust_toolchain_toml.rs std | ||
|
||
- name: Install safety_tool | ||
run: | | ||
export VERIFY_RUST_STD=1 | ||
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib | ||
cd tag-std/safety-tool | ||
cargo install --path . --locked -Fstd | ||
safety-tool --version | ||
safety-tool-rfl build-dev | ||
safety-tool-rfl --display-extra-rustc-args | ||
|
||
- name: Clone and install RAPx | ||
run: | | ||
rm -rf RAPx | ||
git clone https://github.com/Artisan-Lab/RAPx.git | ||
cd RAPx | ||
git checkout $RAPx_VERSION | ||
./install.sh | ||
|
||
- name: Set up RAPx environment | ||
run: | | ||
RUSTUP_TOOLCHAIN=$(rustup show active-toolchain | cut -d ' ' -f 1) | ||
echo "RUSTUP_TOOLCHAIN=$RUSTUP_TOOLCHAIN" >> $GITHUB_ENV | ||
CURRENT_DIR=$(pwd) | ||
RUST_SRC_PATH="$CURRENT_DIR/library" | ||
echo "__CARGO_TESTS_ONLY_SRC_ROOT=$RUST_SRC_PATH" >> $GITHUB_ENV | ||
|
||
- name: Run RAPx verification | ||
run: | | ||
cargo new dummy_crate | ||
cd dummy_crate | ||
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib | ||
export RUSTFLAGS="--cfg=rapx -L $TOOL_DIR/target/safety-tool/lib --extern=safety_macro -Zcrate-attr=feature(register_tool) -Zcrate-attr=register_tool(rapx)" | ||
cargo +$RUSTUP_TOOLCHAIN rapx -verify-std -- -Zbuild-std=panic_abort,core,std --target x86_64-unknown-linux-gnu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# RAPx | ||
RAPx is a static analysis platform for Rust programs. It can serve as a companion to the Rust compiler in detecting semantic bugs related to unsafe code. | ||
|
||
Using abstract interpretation, RAPx checks for undefined behavior (UB) by pre-tagging unsafe APIs. When a caller calls such a pre-tagged API, RAPx examines all program paths to verify whether the program state meets the tag's conditions—ensuring the caller remains sound under any input and does not trigger UB. Currently, RAPx can detect various types of UB, such as misaligned or dangling pointers, out-of-bounds memory access, and uninitialized memory usage. | ||
|
||
## Safety Property Verification | ||
This section will briefly describe several key steps of UB validation by RAPx. | ||
|
||
RAPx has a specialized verification module for unsafe Rust code that systematically prevents undefined behavior (UB) through two core steps: | ||
|
||
+ Audit Unit Generation: Segment code into verifiable units by analyzing unsafe code propagation patterns. | ||
|
||
+ Safety Property Verification: Use contract-based abstract interpretation to validate safety properties. | ||
|
||
For comprehensive methodology details and practical examples, see the [module of verification in RAPx-Book](https://artisan-lab.github.io/RAPx-Book/6.4-unsafe.html). | ||
|
||
## Installation | ||
See the [quick start section](https://github.com/Artisan-Lab/RAPx?tab=readme-ov-file#quick-start) to learn how to install RAPx. The version of rustc used by RAPx is continuously updated and tries to match the `verify-rust-std` project's version whenever possible. | ||
|
||
## Usage | ||
### Usage in verifying third-party crate | ||
After ensuring that RAPx with the correct rustc version has been installed, you can verify the soundness of your code by doing the following steps: | ||
+ Navigate to the root directory of the crate you wish to analyze: | ||
``` | ||
cd /to-be-verified-crate/ | ||
``` | ||
+ Set the required environment variables. Since RAPx by default checks all unsafe calls in the standard library, __CARGO_TESTS_ONLY_SRC_ROOT must point to a pre-annotated version of std. A fully annotated std repository for RAPx linking will be released in the future. | ||
``` | ||
export RUSTUP_TOOLCHAIN=$RUSTUP_TOOLCHAIN_OF_RAPX | ||
export __CARGO_TESTS_ONLY_SRC_ROOT=/path-to-pre-annotated-std-lib/library | ||
``` | ||
+ Run the verification using the -verify subcommand. RAPx requires linking to the annotated standard library, so the -Zbuild-std argument is necessary: | ||
``` | ||
# In Linux | ||
cargo +$RUSTUP_TOOLCHAIN rapx -verify -- -Zbuild-std=panic_abort,core,alloc,std --target x86_64-unknown-linux-gnu | ||
# In Mac(Arm) | ||
cargo +$RUSTUP_TOOLCHAIN rapx -verify -- -Zbuild-std=panic_abort,core,alloc,std --target aarch64-apple-darwin | ||
``` | ||
Upon completion, RAPx will output the analysis results regarding the contract compliance of APIs containing unsafe code: | ||
``` | ||
|RAP|INFO|: --------In safe function "alloc::vec::into_raw_parts_with_alloc"--------- | ||
|RAP|INFO|: Use unsafe api "core::ptr::read". | ||
|RAP|INFO|: Argument 1's passed Sps: {"ValidPtr", "Typed", "Align"} | ||
``` | ||
|
||
### Usage in verifying the the Rust Standard Library | ||
Apart from the need to set up a `dummy_crate` as the entry point for the verification command, the process is the same as validating third-party libraries. However, RAPx offers a customized command, `-verify-std`, specifically for standard library verification. When using this command, RAPx scans all APIs in the standard library and verifies those annotated with `proof` targets. For example: | ||
```rust | ||
#[cfg_attr(rapx, safety {proof})] | ||
pub fn pop(&mut self) -> Option<T> { | ||
... | ||
} | ||
``` | ||
This annotation will be conditionally expanded and verified during RAPx's compilation process. | ||
|
||
## Caveats | ||
RAPx provides sound detection of undefined behavior - if any path in the program contains UB, it will be reported. But this guarantee comes with inherent over-approximation of program paths, which may yield false positives where reported UB paths are infeasible in concrete execution. | ||
|
||
Besides, RAPx is still under heavy development and can currently validate some SPs mentioned in [tag-std](https://github.com/Artisan-Lab/tag-std/blob/main/primitive-sp.md#21-summary-of-primitive-sps). Continued development and integration are needed to support the verification of the remaining ones. | ||
|
||
Finally, RAPx ensures the absence of undefined behavior (UB) on all paths by (i) checking the callee’s preconditions or (ii) tracking subsequent [hazard conditions](https://github.com/Artisan-Lab/tag-std/blob/main/primitive-sp.md#1-overall-idea). RAPx can not provide any proof for the logic correctness of function. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,5 @@ check-cfg = [ | |
'cfg(no_global_oom_handling)', | ||
'cfg(no_rc)', | ||
'cfg(no_sync)', | ||
'cfg(rapx)' | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.