[RFC][PATCH 04/24] kernel/fork: Allow arch-specific stack initialization
From: Dave Hansen
Date: Wed Oct 21 2026 - 15:53:27 EST
Right now, the entire thread_union has uniform permissions. Shadow
stacks obviously do not have the same page permissions as the rest
of the stacks. Add a new arch-specific hook so shadow stack page
permissions can be established.
Note: this is slow. It requires TLB invalidation in the arch code,
which is abhorrently stupid. It will be fixed up in due time.
---
b/include/linux/thread_info.h | 5 +++++
b/kernel/fork.c | 14 +++++++++++---
2 files changed, 16 insertions(+), 3 deletions(-)
diff -puN include/linux/thread_info.h~generic-arch_init_thread_stacks include/linux/thread_info.h
--- a/include/linux/thread_info.h~generic-arch_init_thread_stacks 2026-10-21 12:36:34.114873761 -0700
+++ b/include/linux/thread_info.h 2026-10-21 12:36:34.177873882 -0700
@@ -228,6 +228,11 @@ static inline int arch_within_stack_fram
static inline void arch_setup_new_exec(void) { }
#endif
+struct thread_stacks;
+#ifndef arch_init_thread_stacks
+static inline void arch_init_thread_stacks(struct thread_stacks *ts) { }
+#endif
+
void arch_task_cache_init(void); /* for CONFIG_SH */
void arch_release_task_struct(struct task_struct *tsk);
int arch_dup_task_struct(struct task_struct *dst,
diff -puN kernel/fork.c~generic-arch_init_thread_stacks kernel/fork.c
--- a/kernel/fork.c~generic-arch_init_thread_stacks 2026-10-21 12:36:34.175873878 -0700
+++ b/kernel/fork.c 2026-10-21 12:36:34.178873884 -0700
@@ -332,9 +332,17 @@ err:
static void *__vmalloc_thread_stack_node(int node)
{
- return __vmalloc_node(sizeof(union thread_union), THREAD_ALIGN,
- GFP_VMAP_STACK,
- node, __builtin_return_address(0));
+ union thread_union *tu;
+
+ tu = __vmalloc_node(sizeof(union thread_union), THREAD_ALIGN,
+ GFP_VMAP_STACK,
+ node, __builtin_return_address(0));
+ if (!tu)
+ return NULL;
+
+ arch_init_thread_stacks(&tu->stacks);
+
+ return tu;
}
static int alloc_thread_stack_node(struct task_struct *tsk, int node)
_