[CRIU] [PATCH] net: Create child with CLONE_VM in prepare_net_namespaces()

Kirill Tkhai ktkhai at virtuozzo.com
Wed Mar 15 07:41:22 PDT 2017


Some functions in prepare_net_ns() use vmalloc(), and this
memory should be visible to our children.

https://travis-ci.org/tkhai/criu/builds/211359724

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/net.c |   14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/criu/net.c b/criu/net.c
index 309e2bd66..89082f2ef 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -1756,20 +1756,27 @@ static int create_net_ns(void *arg)
 
 int prepare_net_namespaces()
 {
-	char stack[128] __stack_aligned__;
+	int status, stack_size;
 	struct ns_id *nsid;
-	int status;
+	char *stack;
 	pid_t pid;
 
 	if (!(root_ns_mask & CLONE_NEWNET))
 		return 0;
 
+	stack_size = 2 * 1024 * 1024;
+	stack = mmap(NULL, stack_size, PROT_WRITE | PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+	if (stack == MAP_FAILED) {
+		pr_perror("Can't allocate stack");
+		return -1;
+	}
+
 	for (nsid = ns_ids; nsid != NULL; nsid = nsid->next) {
 		if (nsid->nd != &net_ns_desc)
 			continue;
 
 		if (root_user_ns && nsid->user_ns != root_user_ns) {
-			pid = clone(create_net_ns, stack + 128, SIGCHLD, nsid);
+			pid = clone(create_net_ns, stack + stack_size, CLONE_VM | SIGCHLD, nsid);
 			if (pid < 0) {
 				pr_perror("Can't clone");
 				goto err;
@@ -1785,6 +1792,7 @@ int prepare_net_namespaces()
 			goto err;
 	}
 
+	munmap(stack, stack_size);
 	close_service_fd(NS_FD_OFF);
 
 	return 0;



More information about the CRIU mailing list