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

Kirill Tkhai ktkhai at virtuozzo.com
Sat Jul 15 16:50:05 MSK 2017


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 at virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/clone-noasan.c |   16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

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);
 }
-



More information about the Devel mailing list