Skip to content

Improve get_random_u8() for use in randomize kstack

Ard Biesheuvel linux-arm-kernel linux-hardening lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest6 patches 21 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6hexagon: Wire up cmpxchg64_local() to generic implementationarch/hexagon/include/asm/cmpxchg.h+4 -00 replies
2/6arc: Wire up cmpxchg64_local() to generic implementationarch/arc/include/asm/cmpxchg.h+3 -02 replies
3/6random: Use u32 to keep track of batched entropy generationdrivers/char/random.c+3 -32 replies
4/6random: Use a lockless fast path for get_random_uXX()drivers/char/random.c+31 -131 reply
5/6random: Plug race in preceding patchdrivers/char/random.c+1 -02 replies
6/6randomize_kstack: Use get_random_u8() at entry for entropyarch/Kconfig include/linux/randomize_kstack.h init/main.c+8 -380 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC/RFT PATCH 0/6] Improve get_random_u8() for use in randomize kstack

From: Ard Biesheuvel <[email protected]>

Ryan reports that get_random_u16() is dominant in the performance profiling of syscall entry when kstack randomization is enabled [0].

This is the reason many architectures rely on a counter instead, and that, in turn, is the reason for the convoluted way the (pseudo-)entropy is gathered and recorded in a per-CPU variable.

Let's try to make the get_random_uXX() fast path faster, and switch to get_random_u8() so that we'll hit the slow path 2x less often. Then, wire it up in the syscall entry path, replacing the per-CPU variable, making the logic at syscall exit redundant.

[0] https://lore.kernel.org/all/[email protected]/

Cc Kees Cook <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Will Deacon <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Jeremy Linton <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Jason A. Donenfeld <[email protected]>

Ard Biesheuvel (6):
hexagon: Wire up cmpxchg64_local() to generic implementation
arc: Wire up cmpxchg64_local() to generic implementation
random: Use u32 to keep track of batched entropy generation
random: Use a lockless fast path for get_random_uXX()
random: Plug race in preceding patch
randomize_kstack: Use get_random_u8() at entry for entropy

 arch/Kconfig                       |  9 ++--
 arch/arc/include/asm/cmpxchg.h     |  3 ++
 arch/hexagon/include/asm/cmpxchg.h |  4 ++
 drivers/char/random.c              | 49 ++++++++++++++------
 include/linux/randomize_kstack.h   | 36 ++------------
 init/main.c                        |  1 -
 6 files changed, 49 insertions(+), 53 deletions(-)

base-commit: ac3fd01e4c1efce8f2c054cdeb2ddd2fc0fb150d

Signature · 1 line
2.52.0.107.ga0afd4fd5b-goog