# Rust was supposed to save the kernel, but the flood of AI-found fixes is landing in Linux's C

- **Published on:** 2026-11-17
- **Category:** News
- **Original page:** https://free-linux.com/articles/linux-7-4-rust-c-ai-fixes

Greg Kroah-Hartman says Rust would prevent a large share of kernel bugs, yet 98.5% of the lines in Linux 7.3 are still C. We measured the tree, counted the CVEs and wrote the same function in classic C, in C with guard()/__free() and in Rust to show why AI-generated patches end up in C, and what that means for reviewers and for anyone running Linux.

---

At Rust Week in Utrecht last May, **Greg Kroah-Hartman** opened his talk with a line that has been quoted ever since: he was there to talk about untrusted data in Linux "and how Rust is going to save us". Six months on, the Linux 7.4 merge window has been the largest on record, and a noticeable part of that volume is small fixes found with AI tools. Nearly all of them touch C, because that is what the kernel is made of: in Linux 7.3, C source and headers account for **98.5%** of the lines, and Rust for **0.5%**.

We measured the tree ourselves, counted CVEs in the kernel's own repository and went back to the original emails to separate what is confirmed from what has been repeated without a source.

## The bug that keeps coming back: error paths and locks

Kroah-Hartman has seen every kernel security bug go by since 2005, and in his talk he described most of them as "tiny, minor stuff", according to the quotes published by ZDNet: error conditions that aren't checked, locks that aren't released, memory that leaks. One of his examples was a Xen bug where, on an error path, "we forgot to unlock".

For readers who don't write kernel code, a quick explanation. A kernel function usually acquires resources as it goes: it allocates memory with `kmalloc()`, takes a mutex so nobody else touches a structure, bumps a reference count. When everything works, it gives them back in order at the end. The trouble is the early exits, the **error paths**. If something fails halfway and the function returns without giving back what it took, you get a **memory leak** (that memory is gone until reboot) or, worse, a **forgotten lock**: the mutex stays held and the next thread that asks for it blocks forever. If instead of forgetting the lock the code reads the data without taking it, you get a **race**, two threads changing the same thing at once.

Human reviewers are bad at spotting these, because correct and broken code look almost identical and error paths rarely run in testing. Kroah-Hartman put it this way in Utrecht: he wants these checks to happen "at build time, not review time", so that he doesn't have to ask on every patch whether the error value was checked or the locks were taken in the right place. He also offered a number, framed as his own estimate: Rust would wipe out "60% of the bugs in the kernel" through those two properties alone. Later, talking about an `Untrusted` type to mark data coming from user space or hardware, he went further with what he called an "unscientific quote": 80% of all CVEs. Neither figure comes from a published study, so read them as the instinct of someone who has seen a lot of patches, not as data.

He has argued this before. In February 2025, in the thread on the kernel's Rust policy, he wrote that most bugs ("quantity, not quality/severity") come from "the stupid little corner cases in C that are totally gone in Rust": memory overwrites, error-path cleanups, unchecked error values and use-after-free. In the same email he pointed out that the kernel has "30 million lines of C code" that isn't going anywhere.

## The same function, three times

<figure>
  <img src="/articles/linux-7-4-rust-c-ia/tres-versiones-c-guard-rust.webp" alt="Three columns with the same foo_probe function: in C with goto err, a return -ENODEV boxed exits without mutex_unlock or kfree; in C with __free(kfree) and guard(mutex) every return releases the lock and the memory automatically; in Rust, KBox::new and dev.state.lock() return a Guard and every exit, including the ? operator, unlocks and frees at the end of scope" loading="lazy" decoding="async">
  <figcaption>The same function in classic C, in C with cleanup.h and in Rust: + marks what is acquired, − what is released by hand and » what the compiler releases at the end of scope · Esquema propio</figcaption>
</figure>


Code makes it easier. This is a simplified example written for this article: a function that allocates a buffer, takes a mutex, initialises a device and registers it. First, in classic C, with the `goto err` pattern the kernel has used for decades:

```c
static int foo_probe(struct foo_dev *fd)
{
	struct foo_buf *buf;
	int ret;

	buf = kzalloc(sizeof(*buf), GFP_KERNEL);
	if (!buf)
		return -ENOMEM;

	mutex_lock(&fd->lock);
	if (fd->dead)
		return -ENODEV;		/* BUG: no unlock, no kfree */

	ret = foo_hw_init(fd, buf);
	if (ret)
		goto err_unlock;

	ret = foo_register(fd, buf);
	if (ret)
		goto err_unlock;

	fd->buf = buf;
	mutex_unlock(&fd->lock);
	return 0;

err_unlock:
	mutex_unlock(&fd->lock);
	kfree(buf);
	return ret;
}
```

The two marked lines are the classic mistake: someone adds a new check months later, writes a plain `return` instead of `goto err_unlock`, and the function leaves with the mutex held and the buffer lost. The compiler doesn't complain, and if `fd->dead` is almost never true, neither do the tests.

Since 2023 the kernel has had another way to write this. **Peter Zijlstra** added `include/linux/cleanup.h`, built on the `cleanup` attribute in GCC and Clang: you attach a cleanup function to a local variable and the compiler calls it whenever the variable goes out of scope, however the function exits. The file's own documentation makes the case in its first paragraph: the "goto error" pattern is "notorious for introducing subtle resource leaks". With those macros the same function looks like this:

```c
static int foo_probe(struct foo_dev *fd)
{
	struct foo_buf *buf __free(kfree) =
		kzalloc(sizeof(*buf), GFP_KERNEL);
	int ret;

	if (!buf)
		return -ENOMEM;

	guard(mutex)(&fd->lock);
	if (fd->dead)
		return -ENODEV;		/* automatic unlock and kfree */

	ret = foo_hw_init(fd, buf);
	if (ret)
		return ret;

	ret = foo_register(fd, buf);
	if (ret)
		return ret;

	fd->buf = no_free_ptr(buf);	/* success: don't free */
	return 0;
}
```

`__free(kfree)` calls `kfree()` when the variable leaves scope, `guard(mutex)` calls `mutex_unlock()`, and `no_free_ptr()` disarms the cleanup when the buffer has to outlive the function. Cleanups run in reverse order of declaration, so the lock is dropped first and the memory freed after. All of this is in Linux 7.3 as shown: `DEFINE_FREE(kfree, ...)` lives in `cleanup.h` itself and the mutex guard in `include/linux/mutex.h`. The documentation spells out one important rule: don't mix `goto` and these macros in the same function, because a jump can cross scopes in unexpected ways.

In Rust the idea is the same, but the language enforces it. The in-tree `kernel` crate defines `Mutex<T>`, whose `lock()` method returns a `Guard` that implements `Drop`: when the guard goes away, the lock is released. Memory works the same way, since `KBox` frees on scope exit unless ownership has been moved elsewhere:

```rust
fn probe(dev: &FooDev) -> Result {
    let buf = KBox::new(FooBuf::new(), GFP_KERNEL)?;

    let mut st = dev.state.lock();   // Guard<'_, State, MutexBackend>
    if st.dead {
        return Err(ENODEV);          // Drop: unlock and free buf
    }

    hw_init(&mut st, &buf)?;         // `?` exits through Drop too
    register(&mut st, &buf)?;

    st.buf = Some(buf);              // moved: no longer freed here
    Ok(())
}                                    // Guard dropped: unlock
```

The real difference is the part you can't see. In C, the mutex and the data it protects are separate things: nothing stops you from reading `fd->dead` without holding `fd->lock`. In Rust, the `dead` field lives **inside** `Mutex<State>`, and the only way to reach it is to call `lock()`. Kroah-Hartman described it in his talk: you can't write code that touches those values without the lock, "the compiler will not let you". Rust doesn't prevent every bug (he mentioned a memory bug in the Rust code that draws the panic QR code himself), but it does rule out this particular class.

## What we measured in the tree

<figure>
  <img src="/articles/linux-7-4-rust-c-ia/linux-7-3-lineas-wc.webp" alt="Terminal in a Linux v7.3 clone: git describe returns v7.3 and a loop with git ls-files and wc -l counts 37383 .c files with 26733180 lines, 27189 .h with 10968186, 1348 .S with 374671 and 496 .rs with 191669; total 38267706 lines, C+h 98.52%, assembly 0.98% and Rust 0.50%" loading="lazy" decoding="async">
  <figcaption>Physical line count (comments and blanks included) by extension in Linux 7.3 · Captura propia</figcaption>
</figure>


Rather than trust second-hand numbers, we checked out the **v7.3** tag (released 18 October 2026) and **v6.1** (December 2022, the first release with Rust) from Linus Torvalds' tree and counted with `git ls-files` and `wc -l`. The criteria: `.c`, `.h`, `.S` (assembly) and `.rs` files, counting **physical lines**, comments and blank lines included.

| Linux 7.3 | Files | Lines | Share |
|---|---:|---:|---:|
| C (`.c`) | 37,383 | 26,733,180 | 69.86% |
| Headers (`.h`) | 27,189 | 10,968,186 | 28.66% |
| Assembly (`.S`) | 1,348 | 374,671 | 0.98% |
| Rust (`.rs`) | 496 | 191,669 | 0.50% |

C and headers add up to **98.52%**. Counting only code lines, without comments or blanks (we used `cloc` for that), the split barely moves: 98.8% for C and headers, 0.79% for assembly and 0.42% for Rust, with 120,019 lines of Rust code. Kroah-Hartman spoke in May of 36 million lines of C and 113,000 of Rust, which fits our 7.3 numbers.

A couple of comparisons from the same count:

- **Rust went from 29 files and 10,359 lines in 6.1 to 496 files and 191,669 lines in 7.3.** Fast growth, but from a very low base, and much of it is bindings so Rust can call existing C.
- **Assembly is flat**: 375,330 physical lines in 6.1 against 374,671 in 7.3. In code lines without comments it goes the other way, 225,827 against 226,541. Essentially unchanged in four years.

## C is learning too: guard() and __free()

<figure>
  <img src="/articles/linux-7-4-rust-c-ia/linux-7-3-guard-free.webp" alt="Terminal in Linux v7.3: git grep finds 2375 .c files, out of 33429 outside tools and samples, using guard, scoped_guard, scoped_cond_guard or __free; the breakdown of occurrences is 7061 guard, 2410 scoped_guard, 1702 __free and 61 scoped_cond_guard" loading="lazy" decoding="async">
  <figcaption>Kernel .c files already using the cleanup.h macros in Linux 7.3, excluding tools/ and samples/ · Captura propia</figcaption>
</figure>


The other way to tackle the same problem is to bring automatic cleanup to C without changing language, and that route has spread much faster than Rust. In the kernel proper, **2,375 of 33,429 `.c` files (7.1%) already use `guard()`, `scoped_guard()` or `__free()`**, with 11,234 occurrences: 7,061 `guard()`, 2,410 `scoped_guard()`, 1,702 `__free()` and 61 `scoped_cond_guard()`. We left out `tools/` and `samples/`, which are user-space code with their own functions by those names; include them and you get 2,502 of 37,383. Nearly six in ten of those files are under `drivers/`, and in 6.1, before `cleanup.h` existed, there were none.

Kroah-Hartman was open about where the idea came from: "We stole this from Rust. Thank you." He added that even if Rust disappeared tomorrow, the kernel's C is already cleaner for having borrowed its ideas.

## Why the flood lands on C

<figure>
  <img src="/articles/linux-7-4-rust-c-ia/vulns-cve-2026-meses.webp" alt="Terminal in the kernel CNA's vulns.git repository on 17 November 2026: git log and awk count published CVEs still in place by month, 246 in January, 220 in February, 178 in March, 377 in April and 1027 in May highlighted, 513 in June, 835 in July, 1643 in August, 2107 in September, 1051 in October and 88 in November" loading="lazy" decoding="async">
  <figcaption>Kernel CVEs published per month in 2026, by the date each record entered vulns.git · Captura propia</figcaption>
</figure>


There's no mystery in AI-generated fixes touching C: that's where the code is, especially old driver code nobody has gone through carefully in years. LLM-based analysis tools are good at finding exactly the kind of bug described above, an error path that doesn't release something, and each finding becomes a patch of a few lines.

The numbers show it. When Torvalds released **Linux 7.3-rc6** on 4 October, he wrote that the commit counts were normal "for the new 'AI normal' with a lot of small error path handling fixes". A month later the 7.4 merge window closed on 1 November with almost 20,000 commits, the biggest ever, as we covered in [Linux 7.4-rc1](/articles/linux-7-4-rc1). The rc2 on 8 November was big as well.

Security follows the same curve, because the kernel assigns a CVE to almost every fix that reaches a stable release (we explained why in [the kernel CVE flood](/articles/linux-kernel-cve-flood-cna)). Counting in the kernel CNA's `vulns.git` repository the date each still-published record was added, as of 17 November:

| 2026 | CVEs published |
|---|---:|
| March | 178 |
| April | 377 |
| May | 1,027 |
| June | 513 |
| July | 835 |
| August | 1,643 |
| September | 2,107 |
| October | 1,051 |

The count nearly triples from April to May, exactly the stretch Kroah-Hartman referred to in Utrecht when he said he was coming off "a long month or two" on the kernel security list.

There is one subsystem where the kernel has put its foot down. On **3 August**, Kroah-Hartman sent the list an email titled "LLM policy for drivers/staging/ going forward". `drivers/staging` is the corner of the kernel meant for newcomers to learn with easy cleanups, and using an LLM to do them, he wrote, defeats the point of it existing. Since then he rejects LLM-generated patches for that directory, with one exception: a security fix found with AI is accepted if the author has **tested it on the actual hardware** for the driver and explains how. His reasoning is worth keeping in mind anywhere: even with the best tools, he says, "at least 1/3" of what they produce is "flat out wrong or harmful".

## Who reviews all this

A three-line patch costs little to write and as much as ever to review, and that's the bottleneck. Kroah-Hartman spoke in Utrecht of more than 5,000 developers and around 700 maintainers, and of a kernel that optimises for code that is easy to review: if a patch uses `guard()`, the reviewer can see at a glance that the lock gets dropped.

On 16 October, **Lorenzo Stoakes**, from memory management, wrote on the `workflows` list that an already unsustainable review load has "doubled, or tripled" with the wave of AI slop, and that he works evenings and weekends to the point of burnout. In November he stepped back from reviewing outside the areas he maintains, as we reported in [AI and kernel maintainers](/articles/ai-maintainers-kernel-stoakes-git-vote).

Torvalds doesn't share the tone. Three days earlier, in that same thread, he had told another developer he doesn't understand "this whole idiotic concept of 'don't use AI for X'" and, in his usual style, proposed banning compilers and text editors too. His position is that the tool doesn't matter, the result does. The practical problem is that somebody still has to look at the result.

## Rust is no longer an experiment, but it isn't rewriting anything

In December 2025, after the Maintainers Summit, **Miguel Ojeda** removed the section of the documentation that described Rust as an experiment. The commit sums it up: the experiment is done, "Rust is here to stay". That doesn't mean the kernel is being rewritten. Kroah-Hartman was clear when asked in Utrecht: no rewrites unless you maintain that file, Rust for new code, and leave existing C alone. The known exception is Binder, Android's inter-process communication mechanism, which has both a C and a Rust implementation; its owners plan to delete the C one once the Rust version reaches parity.

The ground rules were set in February 2025, when a maintainer tried to block a Rust driver that used his API. Torvalds replied on the list that the change didn't touch his code, and that a maintainer is in charge of his code but not of who uses the end result or how. Nobody is forced to take Rust into their subsystem, he said in effect, but whoever chooses to ignore it also gives up any say over Rust code that uses their C interfaces.

## Rust in 7.4: how much goes in and where it builds

<figure>
  <img src="/articles/linux-7-4-rust-c-ia/linux-7-4-ventana-rust.webp" alt="Terminal in Torvalds' tree: between v7.3 and v7.4-rc1 there are 19780 commits, 18591 excluding merges, and 256 of them touch .rs files or the rust/ directory, 1.38%; git grep on v7.3 shows HAVE_RUST in arm, arm64, loongarch, powerpc, riscv, s390, um and x86, out of 21 directories under arch" loading="lazy" decoding="async">
  <figcaption>Commits in the 7.4 merge window touching Rust, and architectures selecting HAVE_RUST in Linux 7.3 · Captura propia</figcaption>
</figure>


For 7.4, Torvalds merged Ojeda's Rust changes on **21 October**: a `zerocopy` crate update, KUnit tests generated from doctests, new `mem` and `ratelimit` modules in the `kernel` crate and other infrastructure work. Across the whole merge window, excluding merges, **256 of 18,591 commits (1.4%)** touched a `.rs` file or the `rust/` directory. Of those 256, 75 belong to the `nova-core` driver for NVIDIA GPUs, largely written by NVIDIA engineers such as John Hubbard, Joel Fernandes and Alistair Popple; the single most active author is Gary Guo, also with 75.

Rust doesn't build everywhere. In Linux 7.3, **8 of the 21 directories under `arch/`** select `HAVE_RUST`: x86 (64-bit only), arm64 and arm (ARMv7 little-endian), riscv (64-bit, with LLVM), loongarch, powerpc, s390 and um (User-Mode Linux). The table in `Documentation/rust/arch-support.rst` lists seven; PowerPC is in its `Kconfig` but not in that table. What's left out are older or niche architectures such as alpha, m68k, parisc, sparc or sh, which still work fine in C.

The reason is the compiler. `rustc` generates code through LLVM, and LLVM doesn't have a backend for every architecture GCC supports. There are two ways to close the gap: **gccrs**, a Rust front end written from scratch inside GCC, and **rustc_codegen_gcc**, which uses GCC as a backend for `rustc`. Neither builds a usable kernel today; the gccrs developers acknowledged at RustConf in September that they can't yet. Until that changes, no essential part of the kernel can be written only in Rust, which caps how far it can go.

## What it means if you run Linux

In the short term, not much you'll notice. **Linux 7.3 will be the next LTS release** barring surprises. Kroah-Hartman said so on 2 November in reply to the 7.4-rc1 announcement, and added that if people tried to "force" stuff into 7.4 to make it the LTS, that would be the best possible reason not to. It's the natural candidate for long-term-support distributions shipping in 2027, and it's a kernel with 0.5% Rust and thousands of error-path fixes already in. With LTS kernels the kernel's own advice hasn't changed: take your distribution's full stable updates instead of chasing individual CVEs.

Whatever Rust reaches your machine will mostly arrive through new drivers: Binder on Android devices that enable it, the Nova driver for NVIDIA GPUs, or the Apple Silicon GPU driver used by Asahi Linux. If your distribution builds its kernel with Rust enabled, you already have it; if not, nothing changes, because the kernel works the same without it. We covered what 7.4 brings for RISC-V in [Linux 7.4 and RISC-V](/articles/linux-7-4-risc-v), and kernel versions with their support dates are on the [Linux page](/linux-kernel).

What does affect everyone is the pace. As long as AI keeps finding bugs in C faster than people can review the fixes, the kernel depends on two things: `guard()` and `__free()` continuing to spread through old code, and the handful of maintainers doing the reviewing not burning out along the way.

**Sources:** [talk "Untrusted data in Linux — How Rust is going to save us"](https://www.youtube.com/watch?v=Nzmj7K0FNRY) by Greg Kroah-Hartman at Rust Week 2026 (RustNL video) and [ZDNet's write-up](https://www.zdnet.com/article/rust-will-save-linux-from-ai-says-greg-kroah-hartman/) with his quotes; [Kroah-Hartman's email in "Rust kernel policy"](https://lore.kernel.org/all/2025021954-flaccid-pucker-f7d9@gregkh/) (19 Feb 2025) and [Linus Torvalds' reply](https://lore.kernel.org/all/CAHk-=wgLbz1Bm8QhmJ4dJGSmTuV5w_R0Gwvg5kHrYr4Ko9dUHQ@mail.gmail.com/) (20 Feb 2025); [include/linux/cleanup.h](https://github.com/torvalds/linux/blob/v7.3/include/linux/cleanup.h), [rust/kernel/sync/lock.rs](https://github.com/torvalds/linux/blob/v7.3/rust/kernel/sync/lock.rs) and [Documentation/rust/arch-support.rst](https://docs.kernel.org/rust/arch-support.html) in Linux 7.3; [commit "rust: conclude the Rust experiment"](https://github.com/torvalds/linux/commit/9fa7153c31a3e5fe578b83d23bc9f185fde115da); [merge "rust-7.4"](https://github.com/torvalds/linux/commit/12d5fc96ebbb3b948861805b32a4c3a96105ccd9); announcements of [Linux 7.3-rc6](https://lore.kernel.org/all/CAHk-=wgYMaZik+wZYTE1bv7x5OUNsorG0WU16gFSZpX4TomMbQ@mail.gmail.com/), [Linux 7.3](https://lore.kernel.org/all/CAHk-=wgwnBm2zDdRM7u016NVHkv9KqbZW7AZ=8wZrqGyv_V+5A@mail.gmail.com/) and [Linux 7.4-rc2](https://lore.kernel.org/all/CAHk-=wgAHC=GJMQm7DM0iJgUCsaMpYJ1zO2FW_+FQLcGzfYZzg@mail.gmail.com/); [LLM policy for drivers/staging](https://lore.kernel.org/all/2026080354-skater-urgent-31b2@gregkh/) (3 Aug 2026); [Lorenzo Stoakes' message](https://lore.kernel.org/all/atI_TSQXzAQFWBfx@gremlin/) (16 Oct 2026) and [Torvalds' reply](https://lore.kernel.org/all/CAHk-=whTs09_ozN+e09GU68N1wPP56MUzDjrg9rnKxQUa0A_4Q@mail.gmail.com/) (13 Oct 2026) in the "docs: remove Assisted-by references" thread; [Kroah-Hartman on 7.3 as the LTS](https://lore.kernel.org/all/2026110241-yarn-tweak-084d@gregkh/) (2 Nov 2026); the kernel CNA's [vulns.git repository](https://git.kernel.org/pub/scm/linux/security/vulns.git/) (our own count as of 17 Nov 2026); [gccrs status on Rust for Linux](https://rust-for-linux.com/gccrs). Our own line counts on the v6.1 and v7.3 tags of [Torvalds' tree](https://github.com/torvalds/linux).
