The Chromium project will support the use of Rust libraries

Chromium

, the Chromium project will support the use of third-party C++ Rust libraries in Chromium

Google recently announced that the team behind the Chromium project is working on adding a production Rust toolchain to its build system.

For those who are still unaware of Rust, they should remember it well because this programming language, which was developed by Mozilla specifically for use in writing a browser, has begun to seep in and be accepted within many important projects, one of them being the Rust Kernel. Linux.

This will allow us to include the Rust code in the Chrome binary over the next year. The goal is to start small and set clear expectations for which libraries will be considered when they are ready.

It's logical, then, that Chromium is finally starting to develop this technology as well. For Google, the introduction of Rust in Chromium will fulfill the goal of providing an easier and more secure way to achieve the "rule of two," which consists of accelerating development and improving Chrome's security. Furthermore, it's improving security by eliminating memory errors and reducing bug density in the code.

We know that C++ and Rust can work very well together, thanks to tools like cxx, autocxx bindgen, cbindgen, diplomat, and (experimental) crubit. However, there are also limitations. We can expect the shape of these limitations to change over time with new or improved tools, but the decisions and descriptions here are based on the current state of technology.

The decision was made as part of an initiative to prevent memory errors from appearing in Chrome's codebase. According to statistics provided two years ago, 70% of critical and dangerous security issues in Chromium are due to memory errors.

Using the Rust language, which focuses on secure memory management and provides automatic memory management, will reduce the risk of vulnerabilities caused by issues such as accessing a memory area after it has been freed and buffer overflow.

The goal of bringing Rust to Chromium is to provide an easier (no IPC) and safer (less complex C++ in general, no sandboxed memory safety bugs) way to satisfy the rule of two, in order to speed up development (less code to write, fewer design documents, fewer security patches) and to improve security (more lines of code with no security bugs in memory, lower code bug density) of Chrome. Additionally, the company is confident that we can use third-party Rust libraries to achieve this goal.

In early 2022, the Chromium team had already experimented with Rust and, after a few months, concluded that the language is initially not suitable as a replacement for C++ for complex tasks with asynchronous code that needs to work alongside existing code.

Therefore, the planned use of Rust in Chromium is clearly limited at first . On the one hand, interoperability will only go in one direction: from C++ to Rust. On the other hand, initially only the use of third-party libraries is permitted. These function as standalone components and are independent of Chromium's internal components. The libraries must have a simple API for their specific task. The Chromium team will then review the libraries.

Finally, it's worth mentioning that adding support in Chromium will allow Rust code to be ported to Chrome binaries starting next year. The decision is primarily driven by security concerns: Rust offers greater security when writing to memory than C++ and prohibits potentially harmful behaviors such as reading unwritten variables, accessing values ​​beyond the limits set by arrays, dereferencing null or invalid pointers, and using invalidated iterators.

If you are interested in learning more, you can find the details at the following link.


Add as preferred source in Google