Google wants to add Rust programming language to Linux kernel

Get a free Techzine subscription!

Google has made its first moves to add support for Rust to the Linux kernel. The company sees the programming language as an opportunity to write better and more secure code for the kernel.

Kernels have been written primarily in C for almost half a century. This programming language provides the control and predictable performance that such a critical component of a system needs, says Google. Generally speaking, bugs in memory safety are not so common, as the code is well written and there are many checks to prevent bad code from ending up in the kernel. However, such bugs do occur, and they can cause huge security problems.

Memory-safe

Rust is a programming language that is very similar to C++, but thanks to its borrow checker, it protects the memory from programming errors, making it memory-safe. This means that, theoretically, bugs in memory safety are nearly impossible. For this reason, Google recently announced that it had incorporated the programming language into Android. The programming language can be used to develop drivers in the deeper layers of the operating system.

Rust for Linux

Now, the tech giant also wants to use Rust to tinker with the Linux kernel that Android is built on top of. The aim is not to replace all 30 million lines of code that make up the Linux kernel with Rust but to be able to add new code written in Rust. To make that happen, the company has joined the Rust for Linux organisation. That organisation was recently set up by Linux developer Miguel Ojeda, who shared his intentions with the Linux mailing list earlier this week with a request for input.

Documentation with best practices

Google sees adding a second programming language to the Linux kernel as an opportunity to adopt best practices in terms of documentation and uniformity right away. The company gives an example of how to deal with unsafe code, such as by documenting which requirements must be met before the code can be called.

In the blog post about the announcement, Google shows several examples of what using Rust in the Linux kernel would look like.

Tip: Rust programming language becomes independent