Re: [RFC PATCH] x86/entry/64: randomize kernel stack offset upon syscall
From: Andy Lutomirski
Date: Wed Mar 20 2019 - 10:51:06 EST
> On Mar 20, 2019, at 4:12 AM, David Laight <David.Laight@xxxxxxxxxx> wrote:
> From: Andy Lutomirski
>> Sent: 18 March 2019 20:16
>>> As a result this patch introduces 8 bits of randomness
>>> (bits 4 - 11 are randomized, bits 0-3 must be zero due to stack alignment)
>>> after pt_regs location on the thread stack.
>>> The amount of randomness can be adjusted based on how much of the
>>> stack space we wish/can trade for security.
>> Why do you need four zero bits at the bottom? x86_64 Linux only
>> maintains 8 byte stack alignment.
> ISTR that the gcc developers arbitrarily changed the alignment
> a few years ago.
> If the stack is only 8 byte aligned and you allocate a variable that
> requires 16 byte alignment you need gcc to generate the extra stack
> frame to align the stack.
> I don't remember seeing the relevant gcc options on the linux
> gcc command lines.
On older gcc, you *canât* set the relevant command line options because gcc was daft. So we just crossed out fingers and hope led for the best. On newer gcc, we set the options. Fortunately, 32-byte stack variable alignment works regardless.
AFAIK x86_64 Linux has never aligned the stack to 16 bytes.