[PATCH 1/1] arm64: syscall: Direct PRNG kstack randomization

Arnd Bergmann arnd at arndb.de
Thu Mar 7 14:02:44 PST 2024


On Thu, Mar 7, 2024, at 20:15, Kees Cook wrote:
> On Thu, Mar 07, 2024 at 12:10:34PM +0100, Arnd Bergmann wrote:
>> There is not even any attempt to use the most random bits of
>> the cycle counter, as both the high 22 to 24 bits get masked
>> out (to keep the wasted stack space small) and the low 3 or 4
>> bits get ignored because of stack alignment. If there was
>> any desire to make it more random, a trivial improvement
>> would be:
>> 
>> +++ b/include/linux/randomize_kstack.h
>> @@ -80,7 +80,7 @@ DECLARE_PER_CPU(u32, kstack_offset);
>>         if (static_branch_maybe(CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT, \
>>                                 &randomize_kstack_offset)) {            \
>>                 u32 offset = raw_cpu_read(kstack_offset);               \
>> -               offset ^= (rand);                                       \
>> +               offset = ror32(offset, 5) & (rand);                     \
>
> Shouldn't this stay ^ instead of & ?

Yes, my mistake.

>>                 raw_cpu_write(kstack_offset, offset);                   \
>>         }                                                               \
>>  } while (0)
>
> But yeah, we should likely make this change regardless.

Ok, do you want to send a patch, or should I?

     Arnd



More information about the linux-arm-kernel mailing list