diff options
| author | Karl Mehltretter <kmehltretter@gmail.com> | 2026-07-10 14:39:57 +0200 |
|---|---|---|
| committer | Andrew Morton <akpm@linux-foundation.org> | 2026-09-29 23:14:55 -0700 |
| commit | 6e420ed44bbc818b3ecd005acb841bee09058cdf (patch) | |
| tree | 5dfdf0620eab07e3c60f68d2c57c4af696709110 /kernel | |
| parent | eb60c5c74f196915123c17e9e35033188c6e4ed5 (diff) | |
| download | linux-next-6e420ed44bbc818b3ecd005acb841bee09058cdf.tar.gz linux-next-6e420ed44bbc818b3ecd005acb841bee09058cdf.zip | |
fork: honor task_struct's declared alignment
Since commit cb7ca40a3882 ("x86/fpu: Make task_struct::thread constant
size"), struct task_struct is declared __attribute__((aligned(64))) on all
architectures.
But fork_init() still sets the task_struct slab cache's alignment to
align = max(L1_CACHE_BYTES, ARCH_MIN_TASKALIGN)
which is smaller than 64 on architectures whose cache lines are below 64
bytes: e.g. 32 on ARMv5.
In practice plain SLUB happens to hand out 64-byte-aligned objects anyway.
With CONFIG_SLUB_DEBUG_ON the red-zone padding shifts objects to the
requested alignment.
With CONFIG_UBSAN_ALIGNMENT=y a boot on QEMU versatilepb (ARM926EJ-S,
v7.2-rc2, gcc 13.3) floods the console with reports like:
UBSAN: misaligned-access in include/linux/sched.h:2087:9
member access within misaligned address c295d7e0 for type 'struct task_struct'
which requires 64 byte alignment
CPU: 0 UID: 0 PID: 15 Comm: pr/ttyAMA-1 Not tainted 7.2.0-rc2 #1 VOLUNTARY
Set the slab alignment to at least the type's declared alignment.
Link: https://lore.kernel.org/20260710123957.31774-1-kmehltretter@gmail.com
Fixes: cb7ca40a3882 ("x86/fpu: Make task_struct::thread constant size")
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Bradley Morgan <include@grrlz.net>
Assisted-by: Claude:claude-fable-5
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: <stable@vger.kernel.org>
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/fork.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index 10f2d05d816a..4558150fd133 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -858,7 +858,8 @@ void __init fork_init(void) #ifndef ARCH_MIN_TASKALIGN #define ARCH_MIN_TASKALIGN 0 #endif - int align = max_t(int, L1_CACHE_BYTES, ARCH_MIN_TASKALIGN); + int align = max3(L1_CACHE_BYTES, ARCH_MIN_TASKALIGN, + __alignof__(struct task_struct)); unsigned long useroffset, usersize; /* create a slab on which task_structs can be allocated */ |
