NewsCrawler.org

Detecting a Rust compiler soundness bug in assembly with typed assembly checks

Rustは本当にメモリ安全なのか? コンパイラのバグを型付きアセンブリと形式検証で検出してみた
Image: zenn.dev

The author shows a Rust function with no unsafe code that a rustc version with a bug compiles, causing a use-after-free: an array element is moved during index calculation, freed with drop, and then read through a reference. The borrow checker should reject it, but it does not correctly handle possible overlap between constant and dynamic indexes, and Miri detected the problem in a GitHub issue. Such bugs are called soundness bug[1]; a 2026 study analyzed 30 soundness issues in rustc, and a separate LLVM optimization bug also caused invalid memory access from safe Rust.

To avoid trusting the compiler, the author proposes checking memory safety on the compiled assembly, adding type information and memory constraints based on Typed Assembly Language[2] and Proof-Carrying Code, ideas studied since the 1990s. The author develops NoCompiler[3], an open-source project that implements typed assembly and a type checker for RISC-V (RV64) and AArch64. On the test function, the checker rejected a load after deallocation, reporting that no capability provably covers the 4-byte access, while a control function passed.

The type checker's soundness is proven in Lean 4[4], a proof assistant, while the Rust-based checker is faster and uses less memory but is not formally proven. The author lists limits: the proof relies on trusted parts such as the Lean kernel and allocator contracts, inline assembly, MMIO, volatile access and concurrency are not fully covered, and compile time is a major open challenge.

Repository Rust github.com

Rust is a systems programming language focused on memory safety and performance, with a compiler (rustc) that checks code for errors before it runs.

Stars: 120,000Forks: 16,000License: Apache-2.0Updated:

Repository NoCompiler github.com

Open source typed assembly framework and type checker for RISC-V and AArch64 that verifies memory safety of compiled machine code, with proofs in Lean 4.

Stars: 120Forks: 12License: Apache-2.0Updated:

Read the original zenn.dev

Sources

  • Zenn JA

    Rustは本当にメモリ安全なのか? コンパイラのバグを型付きアセンブリと形式検証で検出してみた

    3 likes0 bookmarks0 comments

Published: First seen: Читать по-русски

Open as a page