Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Pasha Tatashin and committed by
Andrew Morton
d82893c5 90eb270d

+5 -5
+5 -5
kernel/fork.c
··· 280 280 if (!vm_area) 281 281 continue; 282 282 283 + if (memcg_charge_kernel_stack(vm_area)) { 284 + vfree(vm_area->addr); 285 + return -ENOMEM; 286 + } 287 + 283 288 /* Reset stack metadata. */ 284 289 kasan_unpoison_range(vm_area->addr, THREAD_SIZE); 285 290 ··· 292 287 293 288 /* Clear stale pointers from reused stack. */ 294 289 memset(stack, 0, THREAD_SIZE); 295 - 296 - if (memcg_charge_kernel_stack(vm_area)) { 297 - vfree(vm_area->addr); 298 - return -ENOMEM; 299 - } 300 290 301 291 tsk->stack_vm_area = vm_area; 302 292 tsk->stack = stack;