[CRIU] [net_ns] Problem of restoring tun in nested net namespace

Kirill Tkhai ktkhai at virtuozzo.com
Fri Mar 24 07:06:23 PDT 2017


Hi, Andrew,

there is a problem with restoring tun device in root net ns, when a child net ns exists.
This problem is related to net_ns only, and the below patch shows how to reproduce it.

1) Fast investigation shows, that tun restored in net ns of pid=16632 on diagram (i.e., NS_CRIU):
16615 pts/2    S+     0:00  |   |           \_ python2 ./test/zdtm.py run -t zdtm/static/tun
16627 pts/2    S+     0:00  |   |               \_ ./zdtm_ct zdtm.py
16628 pts/2    S+     0:00  |   |                   \_ python2 zdtm.py
16632 pts/2    S+     0:00  |   |                       \_ python2 zdtm.py
16726 ?        Ss     0:00  |   |                       \_ ./tun --pidfile=tun.pid --outfile=tun.out
16749 ?        Ss     0:00  |   |                           \_ ./tun --pidfile=tun.pid --outfile=tun.out
16750 ?        S      0:00  |   |                               \_ ./tun --pidfile=tun.pid --outfile=tun.out

2)I added noauto to this test to prevent crappy travis reports. Please, run the test manually.

3)Test should fails like the below:
14:04:21.671:     5: FAIL: tun.c:267: Address mismatch on tap 4a:ffffffa9 -> ffffffa6:fffffff6 (errno = 16 (Device or resource busy))

Kirill

---
diff --git a/test/zdtm/static/tun.c b/test/zdtm/static/tun.c
index c53b8fa8..4543b148 100644
--- a/test/zdtm/static/tun.c
+++ b/test/zdtm/static/tun.c
@@ -1,3 +1,19 @@
+#define _GNU_SOURCE
+#include <sched.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdio.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <dirent.h>
 #include <unistd.h>
 #include <string.h>
 #include <fcntl.h>
@@ -6,6 +22,7 @@
 #include <linux/if.h>
 #include <linux/if_tun.h>
 
+#include "lock.h"
 #include "zdtmtst.h"
 
 const char *test_doc	= "Test TUN/TAP devices\n";
@@ -112,13 +129,35 @@ static int dev_get_hwaddr(int fd, char *a)
 	return 0;
 }
 
+futex_t *futex;
+
+int child(void *unused)
+{
+	futex_wait_while_lt(futex, 1);
+	return 0;
+}
+
 int main(int argc, char **argv)
 {
 	int fds[5], ret;
-	char addr[ETH_ALEN], a2[ETH_ALEN];
+	char addr[ETH_ALEN], a2[ETH_ALEN], stack[128];
+	pid_t pid;
 
 	test_init(argc, argv);
 
+	futex = mmap(NULL, sizeof(*futex), PROT_WRITE | PROT_READ, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+	if (futex == MAP_FAILED) {
+		fail("mmap futex\n");
+		return 1;
+	}
+	futex_init(futex);
+
+	pid = clone(child, stack + 128, CLONE_NEWNET | SIGCHLD, NULL);
+	if (pid < 0) {
+		pr_perror("clone");
+		return 1;
+	}
+
 	/* fd[0] -- opened file */
 	fds[0] = __open_tun();
 	if (fds[0] < 0) {
diff --git a/test/zdtm/static/tun.desc b/test/zdtm/static/tun.desc
index 8c7cfe86..eac32c2d 100644
--- a/test/zdtm/static/tun.desc
+++ b/test/zdtm/static/tun.desc
@@ -1 +1 @@
-{'flavor': 'ns uns', 'flags': 'suid', 'feature': 'tun'}
+{'flavor': 'ns uns', 'flags': 'suid noauto', 'feature': 'tun'}


More information about the CRIU mailing list