Nick Desaulniers (), involved at Google in ensuring the Linux kernel builds using the Clang compiler, and also fix bugs in the Rust compiler, to hold at the conference a session to discuss enabling kernel component development in Rust. Nick is organizing a micro-conference focused on LLVM and believes it would be beneficial to discuss the technical aspects of potential integration support for Rust in the kernel (a working prototype for KBuild has already been prepared) and to understand whether such support is necessary at all and what limitations regarding Rust usage should be accepted.
Recall that in a recent discussion at the "Open Source Summit and Embedded Linux" conference, Linus Torvalds the possibility of bindings for developing non-core kernel subsystems (such as drivers) in languages like Rust. The ability to develop drivers in Rust could allow for the creation of safe and higher-quality drivers with minimal effort, eliminating issues such as accessing memory after it has been freed, dereferencing null pointers, and buffer overflows. There are already several third-party projects implementing such functionality:
- Developers from Fish in a Barrel A toolkit for writing loadable modules for the Linux kernel in Rust, using layers of abstraction over kernel interfaces and structures to enhance security. The layers are automatically generated based on existing kernel header files using a utility. . The Clang compiler is used to build the layers. The modules built, in addition to the layers, utilize the staticlib package.
- Researchers from the Chinese University of Hong Kong a project for developing Rust drivers for embedded systems and Internet of Things devices, which also uses bindgen to generate wrappers based on the kernel's header files. The framework aims to enhance driver safety without modifying the kernel — instead of creating additional isolation levels in the kernel for drivers, it proposes to address issues at the compilation stage by using the safer Rust language. It is expected that this approach may be sought after by hardware manufacturers who develop proprietary drivers hastily without due auditing.
- Developers of the framework for translating C code to Rust, Experiments on transforming kernel modules with minimal manual adjustments. Among the issues noted is the use of code in many parts of the kernel that employs GCC extensions not yet supported in C2Rust. To address this issue, C2Rust plans to add support for GCC attributes inline, cold, alias, used, and section, as well as to enhance the inline assembler capabilities and resolve problems with structures that are both aligned and packed (e.g., xregs_state). Significant challenges requiring manual intervention include the inability to translate non-trivial C macros into Rust macros and the need to redefine types, as C2Rust translates C types into definitions in the libc package, which cannot be used in kernel modules.
Source: opennet.ru
