Skip to content

Commit a086e7c

Browse files
benzeagregkh
authored andcommitted
x86/fpu: Avoid copying dynamic FP state from init_task in arch_dup_task_struct()
[ Upstream commit 5d3b81d ] The init_task instance of struct task_struct is statically allocated and may not contain the full FP state for userspace. As such, limit the copy to the valid area of both init_task and 'dst' and ensure all memory is initialized. Note that the FP state is only needed for userspace, and as such it is entirely reasonable for init_task to not contain parts of it. Fixes: 5aaeb5c ("x86/fpu, sched: Introduce CONFIG_ARCH_WANTS_DYNAMIC_TASK_STRUCT and use it on x86") Signed-off-by: Benjamin Berg <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Oleg Nesterov <[email protected]> Link: https://lore.kernel.org/r/[email protected] ---- v2: - Fix code if arch_task_struct_size < sizeof(init_task) by using memcpy_and_pad. Signed-off-by: Sasha Levin <[email protected]>
1 parent 568aa55 commit a086e7c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

arch/x86/kernel/process.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ EXPORT_PER_CPU_SYMBOL_GPL(__tss_limit_invalid);
9292
*/
9393
int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
9494
{
95-
memcpy(dst, src, arch_task_struct_size);
95+
/* init_task is not dynamically sized (incomplete FPU state) */
96+
if (unlikely(src == &init_task))
97+
memcpy_and_pad(dst, arch_task_struct_size, src, sizeof(init_task), 0);
98+
else
99+
memcpy(dst, src, arch_task_struct_size);
100+
96101
#ifdef CONFIG_VM86
97102
dst->thread.vm86 = NULL;
98103
#endif

0 commit comments

Comments
 (0)