Linux kernel C language will be upgraded


According to the Linux kernel mailing list, the community has recently discussed whether to adopt the modern C language standard for the kernel.
While the Linux kernel is growing rapidly, it also relies on some very old tools, one of which is that the kernel code still uses the 1989 version of the C language standard – written more than 30 years ago before the kernel project started . Judging from the results of the discussion, this situation is expected to change in the 5.18 version of the kernel.

Jakob Koschel’s patch to Linus Torvalds (…) fixes a speculative execution vulnerability related to kernel linked lists.

The Linux kernel C language will be upgraded The Linux kernel C language will be upgraded

The reason is that Jakob found a problem, the Linux kernel widely uses the doubly linked list defined by struct list_head:

structlist_head{ structlist_headnext,prev;};
Such structs are often embedded in other structs, and in this way, developers can make linked lists using any type of struct that interests them. In addition, the kernel also provides a large number of functions and macros that can be used to traverse and manipulate linked lists. One of them is list_for_each_entry(), a macro masquerading as a control structure. To see how to use this macro, assume that the kernel contains the following structure:

The list member can be used to create a doubly linked list of foo structures. Suppose we have a structure declaration called foo_list as the head of such a linked list. The following code can be used to traverse this list:

struct foo *iterator;
list_for_each_entry(iterator, &foo_list, list) {
/ Should not use iterator here /
The list argument tells the macro the name of the list_head structure in the foo structure. This loop will execute once for each element in the list to which the iterator points. This leads to a bug in the USB subsystem: the iterator passed to this macro can still be used after exiting the macro.

Koschel solved the problem by rewriting the offending code to stop using the iterator after the loop.

However, Linus was puzzled by the problem of the patch, and did not see its relationship with the speculative execution vulnerability. Koschel further explained this, which Linus thinks is just a generic bug. But it wasn’t long before Linus discovered the source of the problem: the iterator passed to the list traversal macro had to be declared in a scope outside the loop itself.

Later, Linus thought that perhaps a more straightforward fix like block-level variable declarations could be employed. But C89 does not support it, and the C99 standard released in 1999 supports it. So maybe it’s time for the Linux kernel to move to the C99 standard.

Linus said that one of the reasons why the kernel code has been stuck in C89 is that the old version of the compiler gcc will have strange problems, causing the initialization program to be destroyed. But now that the minimum version of GCC required by the kernel has been raised to v5.1, those bugs may no longer be relevant.

Arnd Bergmann, another kernel developer who keeps an eye on the architecture-compiler issue, proposes a direct upgrade to C11 or even C2x, though he’s not sure if C11 will bring anything new to the kernel. However, if you upgrade to C17 or C2x, it will destroy the support for gcc-5/6/7, so upgrading to C11 is easier to implement, and the kernel community may not accept it if it spans too large.

Linus was in favor of the idea, and after Bergmann confirmed that it should be possible to do so, Linus announced that he would try to use the C11 standard in the next kernel version, v5.18. If all goes well, the C language standard used in the next kernel version is expected to be upgraded to C11.

Recommended Today

“Oracle” client PL/SQL DEVELOPER installation and use

Author: threedayman source:Hang Seng LIGHT Cloud Community background Compared with the command line, the client has richer visual interface information. At the same time, in order to run large sql files more conveniently, choose to install the client. Download and install PL/SQL DEVELOPER download address the appropriate version to install. Download Instantclient download address After […]