]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
x86/fpu: Always use memcpy_and_pad() in arch_dup_task_struct()
authorOleg Nesterov <oleg@redhat.com>
Sat, 3 May 2025 14:38:50 +0000 (16:38 +0200)
committerIngo Molnar <mingo@kernel.org>
Sun, 4 May 2025 08:29:25 +0000 (10:29 +0200)
It makes no sense to copy the bytes after sizeof(struct task_struct),
FPU state will be initialized in fpu_clone().

A plain memcpy(dst, src, sizeof(struct task_struct)) should work too,
but "_and_pad" looks safer.

[ mingo: Simplify it a bit more. ]

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Chang S . Bae <chang.seok.bae@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250503143850.GA8997@redhat.com
arch/x86/kernel/process.c

index 7a1bfb61d86f49d066f43dd74a1aa61f02e6cd2b..9e6180777565af56e690368799257c86accd479f 100644 (file)
@@ -93,11 +93,8 @@ EXPORT_PER_CPU_SYMBOL_GPL(__tss_limit_invalid);
  */
 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
 {
-       /* init_task is not dynamically sized (incomplete FPU state) */
-       if (unlikely(src == &init_task))
-               memcpy_and_pad(dst, arch_task_struct_size, src, sizeof(init_task), 0);
-       else
-               memcpy(dst, src, arch_task_struct_size);
+       /* fpu_clone() will initialize the "dst_fpu" memory */
+       memcpy_and_pad(dst, arch_task_struct_size, src, sizeof(*dst), 0);
 
 #ifdef CONFIG_VM86
        dst->thread.vm86 = NULL;