Thread (10 messages) 10 messages, 4 authors, 2026-01-02

Re: [PATCH v2 3/3] randomize_kstack: Unify random source across arches

From: Kees Cook <kees@kernel.org>
Date: 2025-12-16 08:27:39
Also in: linux-arm-kernel, linux-hardening, linux-riscv, linux-s390, lkml, loongarch

On Mon, Dec 15, 2025 at 04:35:17PM +0000, Ryan Roberts wrote:
quoted hunk ↗ jump to hunk
[...]
@@ -45,9 +46,22 @@ DECLARE_STATIC_KEY_MAYBE(CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT,
 #define KSTACK_OFFSET_MAX(x)	((x) & 0b1111111100)
 #endif
 
+DECLARE_PER_CPU(struct rnd_state, kstack_rnd_state);
+
+static __always_inline u32 get_kstack_offset(void)
+{
+	struct rnd_state *state;
+	u32 rnd;
+
+	state = &get_cpu_var(kstack_rnd_state);
+	rnd = prandom_u32_state(state);
+	put_cpu_var(kstack_rnd_state);
+
+	return rnd;
+}
[...]
-static inline void random_kstack_task_init(struct task_struct *tsk)
+static int random_kstack_init(void)
 {
-	tsk->kstack_offset = 0;
+	prandom_seed_full_state(&kstack_rnd_state);
+	return 0;
 }
+
+late_initcall(random_kstack_init);
Doesn't this need to be run for every CPU? (And how does hotplug work
for such things?) And doesn't it need a get_cpu_var?

-- 
Kees Cook
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help