Urgent.News

What's breaking now, across hundreds of outlets.

Tech

11 year old unsoundness bugs found in Rust borrow checker

The Rust borrow checker has revealed two significant unsoundness bugs affecting the language's type system. These bugs, classified as `P-high` issues, were previously rated as `P-critical` due to their age and potential impact. The finding of these issues is particularly noteworthy as they have evaded detection during the program's 11-year existence.

The first bug is tied to a `Drop` implementation within a struct named `Q`. This implementation takes advantage of `Mutex` from Rust's `std::sync` module. The `Drop` function for `Q` checks if a value exists within a `Vec` stored in a `Mutex`, and if so, it moves the value into a new `Mutex` guarded by `KEPT`. This behavior is designed to store the dropped value in `KEPT`.

However, the unsoundness arises when an attempt is made to drop the `Q` struct within a context where a string literal is created. The process involves creating a string `l`, assigning a `Some` reference to `l` within the `Q` struct, and subsequently dropping the `Q` instance. The attempt to drop the `Q` struct triggers an unexpected memory unsafety condition due to the misuse of `Mutex` and the downcasting of `t` within the `Drop` trait.

The second unsoundness bug involves exploiting the first bug with a malicious `Drop` implementation. To exploit this, one needs to intentionally manipulate the `Drop` behavior in a way that compromises memory safety. The manipulation involves creating a `Vec` within `KEPT`, and inserting a boxed object when a `Q` instance is dropped. This object is then expected to be safely downcasted and referenced, leading to a memory unsafety condition.

In summary, these bugs highlight the critical need for thorough testing and validation of Rust's type system to maintain memory safety. The Type Team within Rust's development community is actively addressing these issues as part of their goals to improve the language's robustness and minimize the risk of unknown type system unsoundnesses.

Rewritten by urgent.news; may contain errors — check the original.

Source: github.com

Other reports of this story

Every outlet that reported this, and when →

Read the original at github.com →

Report a problem with this story

More in Tech

More from Tuesday 13 October →