[Devel,CRIU,3/6] clone_noasan: Allow to create CLONE_VM|CLONE_VFORK processes

Submitted by Kirill Tkhai on July 15, 2017, 1:50 p.m.

Details

Message ID 150012660551.9540.11034453154782270614.stgit@localhost.localdomain
State New
Series "Switch user_ns before mount binfmt_misc"
Headers show

Commit Message

Kirill Tkhai July 15, 2017, 1:50 p.m.
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: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 criu/clone-noasan.c |   16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/clone-noasan.c b/criu/clone-noasan.c
index c5171b11f..0d98c2ed8 100644
--- a/criu/clone-noasan.c
+++ b/criu/clone-noasan.c
@@ -1,5 +1,7 @@ 
 #include <sched.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
@@ -19,15 +21,11 @@ 
  */
 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
-	 * and retcode in this place
+	 * Reserve some bytes for clone() internal needs
+	 * and use as stack the address above this area.
 	 */
-	char stack[128] __stack_aligned__;
-	char *stack_ptr = &stack[sizeof(stack)];
-	int ret;
-
-	ret = clone(fn, stack_ptr, flags, arg);
-	return ret;
+	return clone(fn, stack_ptr, flags, arg);
 }
-