A additional Rust compiler pass to detect memory safe bugs of Rust programs.

Overview

SafeDrop

A additional Rust compiler pass to detect memory safe bugs of Rust programs. SafeDrop performs path-sensitive and field-sensitive inter-procedural static analysis based on the mid-level IR of Rust program. It uses the tarjan algorithm to deal with the complex control flow loop and function call loop, then performs alias analysis on each execution path, detecting potential problems and reporting errors depend on our summarized rules.

The associated paper titled SafeDrop: Detecting Memory Deallocation Bugs of Rust Programs via Static Data-Flow Analysis (TOSEM '22).

Requirement

  • First, git clone the Rust compiler source code.

    $ git clone https://github.com/rust-lang/rust.git
    

    Since this implementation is based on Rust 1.63.0, it need to switch to the corresponding tag.

    $ cd rust
    $ git checkout -b mycompiler 1.63.0
  • Make sure you can build the Rust compiler. The specific requirements and tutorial you can find in https://github.com/rust-lang/rust.

Usage

It need to add some code snippets to make this pass work.

  • Modify the compiler source code according to the need_to_modify.rs and lib.rs.

  • put the safedrop_check module under the rust/compiler/rustc_mir_transform/

    • rebuild the compiler, and we can get the compiler with safedrop checking: rust/build/(target_machine)/stage1/bin/rustc.
  • You can set this compiler in rust toolchain use:

    # link this compiler as safedrop in rust toolchains.
    $ rustup toolchain link safedrop path_to_rust/build/(target_machine)/stage1
    # set the default toolchain as safedrop.
    $ rustup default safedrop

    After that, you can use both rustc or cargo to compile rust programs with safedrop checking.

  • example:

    // a program with double-free bug
    use std::vec::Vec;
    fn main() {
        let mut a = vec![1,2];
        let ptr = a.as_mut_ptr();
        unsafe{
            let mut _v = Vec::from_raw_parts(ptr, 2, 2);
        }
    }

    We use this compiler to compile this program, and can get the following warning message:

    $ rustc test.rs
    =================================
    Function:DefId(0:6 ~ test[5105]::main)
    Double Free Bugs Exist:
    occurs in test.rs:9:1: 9:2 (#0)
    
You might also like...
Write Anchor-compatible Solana programs in Python

seahorse: Write Solana programs in Python The ease of Python with the safety of Rust. Seahorse lets you write Solana programs in Python. It is a commu

Gain intuition about the goings-on of your multithreaded/multicomponent programs
Gain intuition about the goings-on of your multithreaded/multicomponent programs

Intuition: a super simple profiler with a terminal ui based on tui-rs. Gain intuition about the goings-on of your multithreaded/multicomponent program

The Rust Compiler Collection is a collection of compilers for various languages, written with The Rust Programming Language.

rcc The Rust Compiler Collection is a collection of compilers for various languages, written with The Rust Programming Language. Compilers Language Co

Take your first step in writing a compiler. Implemented in Rust.

first-step-rust Take your first step in writing a compiler, using Rust. Building from Source Make sure the Rust toolchain is installed on your compute

A rust version of "the super tiny compiler"

The (Rust) super tiny compiler This project is a rust version of the super tiny compiler (the original one (JS) was created by Jamie Kyle). The output

Rust lib for fetching official protoc (Protocol Buffer compiler) releases

protoc-fetcher Rust library for fetching official Protocol Buffer compiler (protoc) releases, pegged to a specific version. protoc-fetcher downloads a

P523 is a classic compiler course taught by R. Kent Dybvig.

P523 is a classic compiler course taught by R. Kent Dybvig. This repo implements the course using Rust, provides a framework to help you master P523.

Bril: A Compiler Intermediate Representation for Learning

Bril: A Compiler Intermediate Representation for Learning Bril (the Big Red Intermediate Language) is a compiler IR made for teaching CS 6120, a grad

The first cesil transpiler/compiler in 50 years!
The first cesil transpiler/compiler in 50 years!

CesilC CESIL, or Computer Education in Schools Instruction Language, is a programming language designed to introduce pupils in British secondary schoo

Owner
Artisan-Lab (Fn*)
Artificial Intelligence for Software Analysis and System Reliability Lab @ Fudan University
Artisan-Lab  (Fn*)
fast rust implementation of online nonnegative matrix factorization as laid out in the paper "detect and track latent factors with online nonnegative matrix factorization"

ONMF status: early work in progress. still figuring this out. code still somewhat messy. api still in flux. fast rust implementation of online nonnega

null 2 Apr 10, 2020
Blazing fast, memory safe & modern Linux package manager written in Rust.

paket Blazing fast, memory safe & modern Linux package manager written in Rust. Roadmap Version: 0.1 Paket.toml file parsing. (#1, #2) CLI handling (p

null 4 Oct 19, 2023
Linked Atomic Random Insert Vector: a thread-safe, self-memory-managed vector with no guaranteed sequential insert.

Linked Atomic Random Insert Vector Lariv is a thread-safe, self-memory-managed vector with no guaranteed sequential insert. It internally uses a linke

Guillem Jara 8 Feb 1, 2023
Rust programs written entirely in Rust

mustang Programs written entirely in Rust Mustang is a system for building programs built entirely in Rust, meaning they do not depend on any part of

Dan Gohman 561 Dec 26, 2022
Small programs written in Rust. Warm up for the upcoming Selenium Manager

Rust Examples This repository contains several example programs written in Rust. Selenium Manager These examples are used as warm up for the upcoming

Boni García 5 Dec 30, 2022
Rust library for compiling and running other programs.

Exers ?? Exers is a rust library for compiling and running code in different languages and runtimes. Usage example fn main() { // Imports...

olix3001 5 Jun 10, 2023
Visualization for Timely Dataflow and Differential Dataflow programs

DDShow Visualization for Timely Dataflow and Differential Dataflow programs Getting started with ddshow First, install ddshow via cargo. As of now dds

Chase Wilson 61 Nov 25, 2022
🕶 Assorted checks and validations for writing safer Solana programs.

vipers ?? Assorted checks and validations for writing safer Solana programs. Motivation Solana's fee mechanism is unlike Ethereum's, in that the numbe

Saber 131 Sep 14, 2022
Complete code for the larger example programs from the book.

Code Examples for Programming Rust This repository contains complete code for the larger example programs from the book “Programming Rust”, by Jim Bla

Programming Rust 670 Jan 1, 2023
Cogo is a high-performance library for programming stackful coroutines with which you can easily develop and maintain massive concurrent programs.

Cogo is a high-performance library for programming stackful coroutines with which you can easily develop and maintain massive concurrent programs.

co-rs 47 Nov 17, 2022