Commit ef65d98a authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Andrei Vagin

clone_noasan: Allow to create CLONE_VM|CLONE_VFORK processes

Picked from patch "[PATCH RFC] namespaces: use CLONE_VFORK
with CLONE_VM when it is possible" by Andrew Vagin.

Currenly parent touches child's stack, as in moment of clone() call
its stack pointer is above the child's (we allocate char stack[128]
on parent's stack). This prevents to create CLONE_VM|CLONE_VFORK
processes, because the child uses stack addresses occupied by parent.

The patch changes clone_noasan() behaviour and allows to do that
with the same memory consumption. We give a child memory, which
is not used by parent clone(), so parent's and child's stacks
have no tntersection.

This allows to create CLONE_VM|CLONE_VFORK processes.
Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent badf42ca
#include <sched.h> #include <sched.h>
#include "common/compiler.h" #include "common/compiler.h"
#include "log.h"
#include "common/bug.h"
/* /*
* ASan doesn't play nicely with clone if we use current stack for * ASan doesn't play nicely with clone if we use current stack for
...@@ -19,15 +21,11 @@ ...@@ -19,15 +21,11 @@
*/ */
int clone_noasan(int (*fn)(void *), int flags, void *arg) int clone_noasan(int (*fn)(void *), int flags, void *arg)
{ {
void *stack_ptr = (void *)round_down((unsigned long)&stack_ptr - 256, 16);
BUG_ON((flags & CLONE_VM) && !(flags & CLONE_VFORK));
/* /*
* Reserve some space for clone() to locate arguments * Reserve some bytes for clone() internal needs
* and retcode in this place * and use as stack the address above this area.
*/ */
char stack[128] __stack_aligned__; return clone(fn, stack_ptr, flags, arg);
char *stack_ptr = &stack[sizeof(stack)];
int ret;
ret = clone(fn, stack_ptr, flags, arg);
return ret;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment