In brief
Rust is a systems language that catches memory errors at compile time: use of freed memory, data races between threads, out-of-bounds access in safe code. It does this without a garbage collector, so it suits embedded software, drivers, and services with predictable timing. In critical systems its value lies in removing a whole class of vulnerabilities that in C and C++ have to be caught by reviews, tests, and tools. It is usually introduced gradually, in new components.
Why memory safety matters
Memory safety errors are mistakes in memory management that, in languages such as C and C++, lead to crashes or to an attacker taking control of the program. They include buffer overflow, use of memory after it has been freed (use-after-free), double free, reading uninitialized memory, and data races.
The scale of the problem is shown by data from the vendors themselves. The Chromium security team reports that about 70% of serious security bugs in that project are memory safety problems. In its December 2023 publication "The Case for Memory Safe Roadmaps," the US agency CISA encourages software manufacturers to develop plans for moving to memory-safe languages.
In a critical system, such as a vehicle controller, medical device software, or a telecom operator's network element, such a bug means not only a vulnerability but also a risk to people or to service continuity.
How Rust delivers memory safety
Rust enforces the rules of memory use in its type system, so the compiler rejects a program that could break them. Three mechanisms:
- Ownership. Every value has exactly one owner. When the owner goes out of scope, the memory is freed automatically, at a predictable point, without a garbage collector.
- Borrowing. A value can have many read-only references or one write reference, never both at once. This eliminates data races.
- Lifetimes. The compiler checks that no reference outlives the value it points to.
An example: code that in C would compile and access freed memory will not compile in Rust.
fn main() {
let odczyt;
{
let bufor = vec![1, 2, 3];
odczyt = &bufor; // błąd kompilacji: `bufor` nie żyje wystarczająco długo
}
println!("{:?}", odczyt);
}On top of that come runtime array bounds checking, no `null` value (the `Option` type instead), and a duty to handle errors returned as `Result`.
The `unsafe` boundary
Rust lets you turn off some checks in `unsafe` blocks, e.g. when accessing hardware registers or calling a C library. This is not a loophole but a clearly marked place where responsibility passes to the programmer. In code review and audits these blocks get special attention, and good practice is to confine them to small, tested modules with a safe interface.
Where Rust fits in critical systems
Rust fits best where the choice used to fall on C or C++ for performance and control over memory. Example uses:
- Embedded software and drivers. Rust runs without an operating system (`no_std`) on microcontrollers. The Linux kernel also supports Rust and allows parts of drivers to be written in it.
- Parsers and protocol handling. Code that reads data from the network or from user files is a typical place for buffer overflows. In an industrial gateway or a telecom operator's network element, a parser in Rust removes this class of risk.
- Low-latency network services. No garbage collector means no pauses, which matters in payment systems and in telecommunications.
- Cryptographic and security tools. Libraries in which a memory error means leaked keys.
In industries with functional safety standards, a qualified compiler is important. Ferrocene, a qualified distribution of the Rust compiler, is according to its vendor qualified for ISO 26262 (ASIL D), IEC 61508 (SIL 3), and IEC 62304 (class C). Tool qualification does not, however, exempt you from the process the standard requires: risk analysis, requirements traceability, testing, and verification.
Rust alongside C and C++: how to introduce it
Rewriting a mature system from scratch rarely pays off. Rust is usually introduced gradually:
- New components in Rust. A new module, e.g. a parser for a new message format, is written in Rust and connects to the rest through a C interface (FFI).
- Replacing the riskiest places. Code that processes untrusted data and has a history of vulnerabilities is the first candidate for a rewrite.
- A shared pipeline. Build, tests, static analysis (`clippy`), dependency scanning (`cargo audit`), and formatting in the same CI as the rest of the project.
- Rules for `unsafe` and FFI. Who may write `unsafe` blocks, and how they are documented and reviewed.
The boundary between Rust and C is a place of particular risk: Rust's guarantees end at the call into a C function. Tests of this boundary, fuzzing, and tools for detecting memory errors in C code remain necessary.
You also need to count the costs honestly. Rust has a steep learning curve, especially in the first weeks of working with the borrowing mechanism. Compiling large projects takes longer than in C. The library ecosystem for some chips and industrial protocols is thinner than for C. The introduction plan should include team training and time for the first, smaller components.
Memory safety is not all of security
Rust removes one large class of errors, but it does not make a program correct. Logic errors, poorly designed permissions, SQL injection, vulnerabilities in dependencies, and misconfiguration occur in every language. That is why code review, security testing with SAST, DAST, and SCA, and management of the software supply chain remain. Software manufacturers in the European Union are also subject to requirements from the Cyber Resilience Act, regardless of the language chosen.
B2Bnetwork engineers develop and test embedded software and systems for industry, automotive, and telecommunications. The scope of services is described in the What we do section.
Questions and answers
Is Rust slower than C++?
In typical uses the performance of Rust and C++ is comparable, because both compile to native code and use no garbage collector. Array bounds checking costs little, and the compiler often removes it. Differences depend more on algorithms and code quality than on the language, and have to be measured on the specific case.
Can Rust code have memory errors?
Safe Rust code is protected from memory errors by the compiler. Errors can appear in `unsafe` blocks, in C libraries called through FFI, and in bugs in the compiler or libraries themselves. That is why `unsafe` blocks are kept to a minimum, reviewed especially carefully, and surrounded by tests and fuzzing.
Can Rust be used in projects under ISO 26262?
Yes, provided the standard's requirements for tools and process are met. There is a qualified Rust compiler on the market with ISO 26262 qualification at the highest level, ASIL D. The project still has to go through the full process: requirements, safety analysis, verification, and testing, just as with C code.
Where do you start introducing Rust in a C and C++ team?
With one small, well-isolated component, ideally one that processes untrusted data, e.g. a message parser. In parallel the team takes training in ownership and borrowing, and the pipeline gets steps for Rust. After the first deployment it is easier to assess the costs, the learning pace, and which further parts are worth moving.