A patch set discussion addressing vulnerabilities related to the Spectre class revealed that the issue could be solved more elegantly if the kernel allowed C code corresponding to a newer version of the standard. Currently, the kernel code being added must comply with the ANSI C (C89) specification established back in 1989.
The issue related to Spectre in the code was due to the continued use of a separately defined iterator after the loop — a macro is used for traversing the elements of the linked list, and since the loop iterator is passed to this macro, it is defined outside the loop itself and remains accessible afterwards. Using the C99 standard would allow for defining loop variables within the for() block, which would resolve the issue without devising workarounds.
Linus Torvalds agreed with the idea of implementing support for newer specifications and proposed switching to the C11 standard, published in 2011, in kernel version 5.18. A preliminary check showed that builds in GCC and Clang under the new mode ran without errors. If no unforeseen issues arise during more thorough testing, the build scripts for kernel 5.18 will change the option ‘—std=gnu89’ to ‘—std=gnu11 -Wno-shift-negative-value’. The possibility of adopting the C17 standard was also considered, but this would require raising the minimum supported version of GCC. However, enabling C11 support fits within the current GCC version requirements (5.1).
Forrás: opennet.ru
