enable Rust support in the kernel

Bug #2007654 reported by Andrea Righi
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Fix Released
Undecided
Unassigned
Lunar
Fix Released
Undecided
Unassigned
Mantic
Fix Released
Undecided
Unassigned

Bug Description

[Impact]

Rust support has been merged starting with linux 6.1.

This support allows to write external kernel modules using the Rust language. Modules written in this way are linked against the linux kernel and can be loaded/unloaded like any other .ko module.

Main advantages of writing modules in Rust are:
 - memory safety:
   - no out of bounds accesses
   - no use after free
   - data race safety
 - strongly typed and statically typed
 - code extremely compact

Roughly 70% of the security issues that the MSRC assigns a CVE to are memory safety issues:
 - Rust allows to write more secure and robust kernel code (reduce kernel CVEs)

We should provide a Rust-enabled kernel so that people have the possibility to implement their own external kernel modules in Rust.

[Test case]

Build the following "hello world" test module:

== hello_rust.rs ==

// SPDX-License-Identifier: GPL-2.0

//! Rust hello world example.

use kernel::prelude::*;

module! {
    type: HelloRust,
    name: "hello_rust",
    author: "Andrea Righi <email address hidden>",
    description: "Rust hello world example",
    license: "GPL",
}

struct HelloRust {
}

impl kernel::Module for HelloRust {
    fn init(_module: &'static ThisModule) -> Result<Self> {
        pr_info!("Hello from Rust\n");

        Ok(HelloRust { })
    }
}

impl Drop for HelloRust {
    fn drop(&mut self) {
        pr_info!("Goodbye from Rust\n");
    }
}

== Makefile ==

NAME=hello_rust

ifndef KERNELRELEASE
ifndef KDIR
KDIR:=/lib/modules/`uname -r`/build
endif
PWD := $(shell pwd)

all:
 $(MAKE) -C $(KDIR) M=$(PWD) modules
install:
 $(MAKE) -C $(KDIR) M=$(PWD) modules_install
clean:
 rm -f *.o *.ko *.mod* .*.cmd *.d Module.symvers modules.order
 rm -rf .tmp_versions
else
 obj-m := $(NAME).o
endif

[Fix]

Building the Rust support in the kernel requires specific versions of the Rust compiler and bindgen utility, same to build the external modules in Rust):
   - rustc 1.62.0
   - bindgen 0.56.0
   - clang/llvm (already required by BPF)

Archive should provide these versions (ideally with a version suffix to avoid conflicting with the stock versions, e.g., rustc-1.62 and bindgen-0.56).

In addition to that the kernel needs some packaging adjustments to use these special toolchain binaries and some special (not yet upstream) patches that would allow to enable mandatory features required in our generic kernel, such as:

 UBUNTU: SAUCE: allows to enable Rust with modversions
 UBUNTU: SAUCE: modpost: support arbitrary symbol length in modversion
 UBUNTU: SAUCE: scripts: Exclude Rust CUs with pahole
 UBUNTU: SAUCE: rust: allow to use INIT_STACK_ALL_ZERO

With all of the above we can enable CONFIG_RUST in the kernel and provide support to build external modules (.ko) using Rust.

[Regression potential]

We may see build regressions due to the inavailability of the proper toolchain versions. Moreover these toolchain dependencies need to be maintained, making sure to be always aligned with upstream requirements, when stable updates are applied to the kernel.

Moreover, hwe kernels require special attention, since this feature won't be available in old releases (unless the proper toolchain requirements are met).

Andrea Righi (arighi)
description: updated
Revision history for this message
Ubuntu Kernel Bot (ubuntu-kernel-bot) wrote : Missing required logs.

This bug is missing log files that will aid in diagnosing the problem. While running an Ubuntu kernel (not a mainline or third-party kernel) please enter the following command in a terminal window:

apport-collect 2007654

and then change the status of the bug to 'Confirmed'.

If, due to the nature of the issue you have encountered, you are unable to run this command, please add a comment stating that fact and change the bug status to 'Confirmed'.

This change has been made by an automated script, maintained by the Ubuntu Kernel Team.

Changed in linux (Ubuntu):
status: New → Incomplete
Andrea Righi (arighi)
description: updated
Jeremy Bícha (jbicha)
Changed in linux (Ubuntu Lunar):
status: Incomplete → Confirmed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package linux - 6.2.0-18.18

---------------
linux (6.2.0-18.18) lunar; urgency=medium

  * lunar/linux: 6.2.0-18.18 -proposed tracker (LP: #2011750)

  * lunar/linux 6.2 fails to boot on arm64 (LP: #2011748)
    - SAUCE: Revert "efi: random: fix NULL-deref when refreshing seed"
    - SAUCE: Revert "efi: random: refresh non-volatile random seed when RNG is
      initialized"

 -- Andrea Righi <email address hidden> Wed, 15 Mar 2023 23:54:18 +0100

Changed in linux (Ubuntu Lunar):
status: Confirmed → Fix Released
Revision history for this message
Ubuntu Kernel Bot (ubuntu-kernel-bot) wrote :

This bug is awaiting verification that the linux-azure/6.2.0-1009.9 kernel in -proposed solves the problem. Please test the kernel and update this bug with the results. If the problem is solved, change the tag 'verification-needed-lunar' to 'verification-done-lunar'. If the problem still exists, change the tag 'verification-needed-lunar' to 'verification-failed-lunar'.

If verification is not done by 5 working days from today, this fix will be dropped from the source code, and this bug will be closed.

See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Thank you!

tags: added: kernel-spammed-lunar-linux-azure verification-needed-lunar
Tim Gardner (timg-tpi)
tags: added: verification-done-lunar
removed: verification-needed-lunar
Revision history for this message
Ubuntu Kernel Bot (ubuntu-kernel-bot) wrote :

This bug is awaiting verification that the linux-oem-6.5/6.5.0-1002.2 kernel in -proposed solves the problem. Please test the kernel and update this bug with the results. If the problem is solved, change the tag 'verification-needed-jammy-linux-oem-6.5' to 'verification-done-jammy-linux-oem-6.5'. If the problem still exists, change the tag 'verification-needed-jammy-linux-oem-6.5' to 'verification-failed-jammy-linux-oem-6.5'.

If verification is not done by 5 working days from today, this fix will be dropped from the source code, and this bug will be closed.

See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Thank you!

tags: added: kernel-spammed-jammy-linux-oem-6.5-v2 verification-needed-jammy-linux-oem-6.5
Revision history for this message
Ubuntu Kernel Bot (ubuntu-kernel-bot) wrote :

This bug is awaiting verification that the linux-azure-6.5/6.5.0-1007.7~22.04.1 kernel in -proposed solves the problem. Please test the kernel and update this bug with the results. If the problem is solved, change the tag 'verification-needed-jammy-linux-azure-6.5' to 'verification-done-jammy-linux-azure-6.5'. If the problem still exists, change the tag 'verification-needed-jammy-linux-azure-6.5' to 'verification-failed-jammy-linux-azure-6.5'.

If verification is not done by 5 working days from today, this fix will be dropped from the source code, and this bug will be closed.

See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Thank you!

tags: added: kernel-spammed-jammy-linux-azure-6.5-v2 verification-needed-jammy-linux-azure-6.5
Revision history for this message
Ubuntu Kernel Bot (ubuntu-kernel-bot) wrote :

This bug is awaiting verification that the linux-aws-6.5/6.5.0-1008.8~22.04.1 kernel in -proposed solves the problem. Please test the kernel and update this bug with the results. If the problem is solved, change the tag 'verification-needed-jammy-linux-aws-6.5' to 'verification-done-jammy-linux-aws-6.5'. If the problem still exists, change the tag 'verification-needed-jammy-linux-aws-6.5' to 'verification-failed-jammy-linux-aws-6.5'.

If verification is not done by 5 working days from today, this fix will be dropped from the source code, and this bug will be closed.

See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Thank you!

tags: added: kernel-spammed-jammy-linux-aws-6.5-v2 verification-needed-jammy-linux-aws-6.5
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.