Skip to content

Commit d82893c

Browse files
soleenakpm00
authored andcommitted
fork: check charging success before zeroing stack
No need to do zero cached stack if memcg charge fails, so move the charging attempt before the memset operation. [linus.walleij@linaro.org: rebased] Link: https://lkml.kernel.org/r/20250509-fork-fixes-v3-3-e6c69dd356f2@linaro.org Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com> Link: https://lore.kernel.org/20240311164638.2015063-6-pasha.tatashin@soleen.com Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 90eb270 commit d82893c

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

kernel/fork.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ static int alloc_thread_stack_node(struct task_struct *tsk, int node)
280280
if (!vm_area)
281281
continue;
282282

283+
if (memcg_charge_kernel_stack(vm_area)) {
284+
vfree(vm_area->addr);
285+
return -ENOMEM;
286+
}
287+
283288
/* Reset stack metadata. */
284289
kasan_unpoison_range(vm_area->addr, THREAD_SIZE);
285290

@@ -288,11 +293,6 @@ static int alloc_thread_stack_node(struct task_struct *tsk, int node)
288293
/* Clear stale pointers from reused stack. */
289294
memset(stack, 0, THREAD_SIZE);
290295

291-
if (memcg_charge_kernel_stack(vm_area)) {
292-
vfree(vm_area->addr);
293-
return -ENOMEM;
294-
}
295-
296296
tsk->stack_vm_area = vm_area;
297297
tsk->stack = stack;
298298
return 0;

0 commit comments

Comments
 (0)