Skip to content

Commit 546c42b

Browse files
Sebastian Andrzej SiewiorKAGA-KOKO
authored andcommitted
fork: Duplicate task_struct before stack allocation
alloc_thread_stack_node() already populates the task_struct::stack member except on IA64. The stack pointer is saved and populated again because IA64 needs it and arch_dup_task_struct() overwrites it. Allocate thread's stack after task_struct has been duplicated as a preparation for further changes. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Andy Lutomirski <luto@kernel.org> Link: https://lore.kernel.org/r/20220217102406.3697941-3-bigeasy@linutronix.de
1 parent be9a227 commit 546c42b

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

kernel/fork.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,10 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
888888
if (!tsk)
889889
return NULL;
890890

891+
err = arch_dup_task_struct(tsk, orig);
892+
if (err)
893+
goto free_tsk;
894+
891895
stack = alloc_thread_stack_node(tsk, node);
892896
if (!stack)
893897
goto free_tsk;
@@ -897,8 +901,6 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
897901

898902
stack_vm_area = task_stack_vm_area(tsk);
899903

900-
err = arch_dup_task_struct(tsk, orig);
901-
902904
/*
903905
* arch_dup_task_struct() clobbers the stack-related fields. Make
904906
* sure they're properly initialized before using any stack-related
@@ -912,9 +914,6 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)
912914
refcount_set(&tsk->stack_refcount, 1);
913915
#endif
914916

915-
if (err)
916-
goto free_stack;
917-
918917
err = scs_prepare(tsk, node);
919918
if (err)
920919
goto free_stack;

0 commit comments

Comments
 (0)