For decades, systems software has been written in C and C++. Operating systems, browsers, databases, network stacks and embedded firmware all rely on their performance and control. They also share a well-known weakness: it is very easy to write code that reads or writes memory it should not.
This year, Rust crossed an important threshold. Linux 6.1, released on 11 December, includes initial support for writing kernel code in Rust, the first time a language other than C has been accepted into the mainline kernel. A few days earlier, Google reported that Rust accounts for a meaningful share of new native code in Android 13, and that memory-safety vulnerabilities in Android have fallen from 76% of the total in 2019 to 35% in 2022.
The memory-safety problem
Memory-safety bugs include buffer overflows, use-after-free, double frees and data races. In C and C++ the compiler does not prevent them, and they are often exploitable for remote code execution.
The numbers are consistent across large codebases:
- Microsoft has reported that around 70% of the vulnerabilities it assigns CVEs to each year are memory-safety issues.
- The Chromium project reports a similar proportion for serious security bugs.
- In November, the NSA published guidance recommending that organisations move to memory-safe languages where possible.
Decades of tooling (sanitisers, fuzzers, static analysis, hardening) have reduced but not eliminated these bugs. Rust takes a different approach: make them impossible to compile in the first place.
How Rust prevents them
Rust enforces a set of rules about ownership and borrowing at compile time:
- Every value has a single owner. When the owner goes out of scope, the value is freed, with no garbage collector needed.
- You can have either one mutable reference to a value or any number of immutable references, but not both at once.
- References can never outlive the data they point to.
The compiler's borrow checker rejects code that breaks these rules:
fn main() {
let names = vec![String::from("alice"), String::from("bob")];
let first = &names[0]; // immutable borrow
// names.push(String::from("carol"));
// ^ compile error: cannot borrow `names` as mutable because it is also borrowed as immutable.
// In C++, push_back could reallocate the vector and leave `first` dangling (use-after-free).
println!("{first}");
}The same rules eliminate data races in concurrent code: sharing mutable state across threads requires types like Mutex or Arc that make synchronisation explicit.
Rust still allows low-level control through unsafe blocks for things like hardware access and FFI, but they are explicit, small and easy to audit, instead of every line being potentially unsafe.
Why developers like it (beyond safety)
Rust has topped Stack Overflow's "most loved language" survey every year since 2016. Reasons developers give include:
- Performance comparable to C and C++, with zero-cost abstractions.
- Excellent tooling: Cargo for builds and dependencies,
rustfmt,clippyand good compiler error messages. - An expressive type system with enums, pattern matching and
Result-based error handling that makes failure cases explicit. - Fearless concurrency, thanks to the compiler catching data races.
The Rust Foundation, formed in 2021 with members including AWS, Google, Huawei, Microsoft and Mozilla, has given the language long-term backing.
The trade-offs
Rust is not free to adopt:
- Learning curve. The borrow checker takes time to internalise, especially for developers used to garbage-collected languages or C++'s freedom.
- Compile times are longer than many developers are used to.
- Interoperability with large existing C++ codebases needs careful boundaries.
- Ecosystem maturity varies. Some domains have excellent libraries, others are still young.
- Hiring is harder than for C++ or Java, though interest is growing quickly.
Adopting Rust sensibly
Rewriting working C++ in Rust is rarely the right first move. Teams that succeed usually:
- Start with new components, not rewrites. Google's Android data shows that most memory-safety bugs are in new code, so writing new code in Rust gives the biggest win.
- Target high-risk code: parsers, codecs, network protocol handlers and anything that processes untrusted input.
- Define clean FFI boundaries with tools such as
bindgenandcxx. - Invest in training and pair experienced Rust developers with newcomers.
- Keep
unsafeminimal and reviewed. Treat eachunsafeblock as a security review item.
Beyond systems programming
Rust is also increasingly used for command-line tools, WebAssembly modules, high-performance web services and developer tooling, where its performance and reliability are attractive even when memory safety is not the main concern.
The bottom line
Rust's rise is driven by a simple observation: a large fraction of critical vulnerabilities come from a class of bug that the language can rule out. With Linux and Android now committed to it, Rust is no longer an experiment. It is becoming a standard choice for new systems code where security matters.
Our secure SDLC team builds performance-critical components in Rust, and our secure code review covers memory-safety issues in C and C++ codebases.