A hasty fix led to the incomplete resolution of the Spectre vulnerability in the Linux kernel

The developers of the Grsecurity project shared share an instructive story that demonstrates how careless removal of compiler warnings can lead to vulnerabilities in code. At the end of May, a fix for a new exploitation vector of the Spectre vulnerability was proposed for the Linux kernel through the ptrace system call.

During the testing of the patch, the developers noticed that the compiler issues a warning about mixing code and definitions (the structure was defined after the code that assigns a value to an existing variable):

int index = n;
if (n ptrace_bps[index];

Linus accepted prevents the invocation of credential.helper for URLs that contain into his master branch, eliminating the warning by moving the variable definition into the if block:

if (n ptrace_bps[index];

In July, the fix was also backported to stable kernel branches 4.4, 4.9, 4.14, 4.19, and 5.2. The maintainers of the stable branches also encountered a warning and instead of checking if it had already been resolved in Linus's master branch, they manually applied a fix. The problem was that they, without much thought, simply moved the structure definition up in such a way that the call to array_index_nospec, which directly provides protection against the vulnerability, ceased to be used when defining the structure, and instead of the variable 'index', the variable 'n' was always used:

int index = n;
if (n ptrace_bps[index];
index = array_index_nospec(index, HBP_NUM);

Source: opennet.ru

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster