(the forum limits the amount of links in a post, please check our readme for all links)
Today I am proud to announce rustig! to you. rustig! is a tool for statical analysis of Rust-generated ELF binaries, specifically to find paths that will lead to panic!.
Getting the tool
The source code is on my company’s GitHub.
A little explanation
The following paragraphs are sections from the README.md in the repository.
The name rustig! comes from the Dutch word rustig. Which translates to ‘calm down’ or equivalent in English. See it as the opposite of ‘panic’.
The idea for this tool was born while we were working on some code for Cortex-M processors. Using
grep you can easily prove that there is no
panic! in the code, because the optimizer has removed those functions from the resulting binary. For non
#[no_std] targets the optimizer cannot remove them because the binary is statically linked to the Rust standard libary which contains those functions. We wanted this this tool to be able to prove the abscence of paths to
panic! in Rust binaries that contain the standard libary. See the Results section to see why this turned out to be not so easy.
As a test case for this tool some well known crates from the Rust community were used. The results are shown below:
|Crate||Lines of Code||Number of panic paths|
The output of the tool in your terminal is overwhelming considering the numbers of paths shown. To reduce the output the whitelisting option is used. Using whitelisting you can drill down on the results showing only the paths you care about.
The biggest lesson learned we learned is this: even the smallest piece of Rust software (that uses std) written without calls to
unwrap() (or similar) still contains a lot of paths to panic!. Usually this comes from the use of
format!(...) (used in
info!(...) and friends) and from a lot of library functions that do allocation (which can fail).
This tool was written by four students from Delft University doing their Bachelor End Project at Technolution in the Netherlands. The initial idea was provided by Erwin Gribnau who mentored this project on behalf of Technolution. On behalf of Delft University, this project was mentored by Robbert Krebbers.
Their thesis about this project can be found in the repo at Delft University, see the repo for the link.