Why Linux Is Finally Moving to C11: The Bug That Changed the Kernel’s Language Standard

The Linux kernel community announced an upgrade from the decades‑old C89 standard to C11 after a subtle bug in the list_for_each_entry macro, exposed by a speculative‑execution vulnerability study, convinced Linus Torvalds to modernize the kernel’s C language version.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Why Linux Is Finally Moving to C11: The Bug That Changed the Kernel’s Language Standard

Last week the Linux kernel mailing list sparked industry attention by discussing whether the kernel should adopt a modern C language standard. The Linux open‑source community has now officially announced that the kernel’s C version will be upgraded to C11, expected to take effect after the 5.18 release in May.

A Bug‑Triggered Chain Reaction

PhD student Jakob Koschel, researching speculative‑execution vulnerabilities tied to kernel linked‑list primitives, discovered an issue with the widely used struct list_head double‑linked list:

struct list_head {
    struct list_head *next, *prev;
};

Developers embed this structure in other structs to create linked lists, and the kernel provides many macros for traversal, such as list_for_each_entry(). The problem lay in this macro.

Assuming a kernel structure like:

struct foo {
    int fooness;
    struct list_head list;
};

and a list head foo_list, the macro is used to iterate:

struct foo *iterator;

list_for_each_entry(iterator, &foo_list, list) {
    do_something_with(iterator);
}
/* Should not use iterator here */

The macro leaks the iterator variable outside the loop, causing errors in the USB subsystem when the iterator is accessed after the loop ends—a dangerous situation.

Linux’s Father Finally Convinced

Initially Linus Torvalds was not enthusiastic about the patch, unaware of its connection to speculative‑execution bugs. After Koschel’s detailed explanation, Linus recognized the issue as a common bug: the iterator must be declared outside the loop because C89 does not allow variable declarations within the loop construct.

Since the kernel still relies on the 1989 C89 standard, upgrading became necessary. While C99 would also work, the kernel’s minimum GCC requirement has been raised to version 5.1, making C11 a more feasible target without breaking older compiler support. Core developer Arnd Bergmann supports moving to C11, noting that C17 or C2x would disrupt GCC 5/6/7 compatibility.

Linus Torvalds ultimately backed the proposal, announcing an early trial in the 5.18 merge window. Although the transition to C11 may introduce unforeseen bugs, the move modernizes the kernel’s codebase and resolves the long‑standing limitation that prevented declaring loop‑local variables.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxC languagemacrobug fixC11
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.