[CRIU] [PATCH] [v2] test: check non-root shared mounts
Andrei Vagin
avagin at openvz.org
Wed Dec 14 11:35:38 PST 2016
From: Andrei Vagin <avagin at virtuozzo.com>
The idea of this test is to check non-root shared mounts
which lives in a few shared groups.
v2: fix the link description.
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
criu/sk-inet.c | 12 +--
criu/sk-tcp.c | 8 ++
soccr/soccr.c | 12 ++-
soccr/soccr.h | 2 +-
test/zdtm/static/Makefile | 1 +
test/zdtm/static/mntns_shared_bind03.c | 124 ++++++++++++++++++++++++++++++
test/zdtm/static/mntns_shared_bind03.desc | 1 +
7 files changed, 153 insertions(+), 7 deletions(-)
create mode 100644 test/zdtm/static/mntns_shared_bind03.c
create mode 100644 test/zdtm/static/mntns_shared_bind03.desc
diff --git a/criu/sk-inet.c b/criu/sk-inet.c
index eb798ce..079fc0d 100644
--- a/criu/sk-inet.c
+++ b/criu/sk-inet.c
@@ -628,27 +628,29 @@ static int open_inet_sk(struct file_desc *d)
if (restore_opt(sk, SOL_SOCKET, SO_REUSEADDR, &yes))
goto err;
- if (ie->src_port) {
- if (inet_bind(sk, ii))
- goto err;
- }
-
if (tcp_connection(ie)) {
if (!opts.tcp_established_ok) {
pr_err("Connected TCP socket in image\n");
goto err;
}
+ pr_err("\n");
mutex_lock(&ii->port->reuseaddr_lock);
if (restore_one_tcp(sk, ii)) {
mutex_unlock(&ii->port->reuseaddr_lock);
goto err;
}
mutex_unlock(&ii->port->reuseaddr_lock);
+ pr_err("\n");
goto done;
}
+ if (ie->src_port) {
+ if (inet_bind(sk, ii))
+ goto err;
+ }
+
/*
* Listen sockets are easiest ones -- simply
* bind() and listen(), and that's all.
diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c
index 6f04bdb..e7038a4 100644
--- a/criu/sk-tcp.c
+++ b/criu/sk-tcp.c
@@ -257,9 +257,11 @@ static int read_tcp_queue(struct libsoccr_sk *sk, struct libsoccr_sk_data *data,
if (read_img_buf(img, buf, len) < 0)
goto err;
+ pr_err("\n");
return libsoccr_set_queue_bytes(sk, queue, buf, SOCCR_MEM_EXCL);
err:
+ pr_err("\n");
xfree(buf);
return -1;
}
@@ -301,6 +303,7 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_
goto err_c;
}
+ pr_err("\n");
data.state = ii->ie->state;;
data.inq_len = tse->inq_len;
data.inq_seq = tse->inq_seq;
@@ -336,6 +339,7 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_
data.rcv_wup = tse->rcv_wup;
}
+ pr_err("\n");
if (restore_sockaddr(&sa_src,
ii->ie->family, ii->ie->src_port,
ii->ie->src_addr, 0) < 0)
@@ -345,6 +349,7 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_
ii->ie->dst_addr, 0) < 0)
goto err_c;
+ pr_err("\n");
libsoccr_set_addr(socr, 1, &sa_src, 0);
libsoccr_set_addr(socr, 0, &sa_dst, 0);
@@ -355,12 +360,15 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_
if (restore_prepare_socket(sk))
goto err_c;
+ pr_err("\n");
if (read_tcp_queues(socr, &data, img))
goto err_c;
+ pr_err("\n");
if (libsoccr_restore(socr, &data, sizeof(data)))
goto err_c;
+ pr_err("\n");
if (tse->has_nodelay && tse->nodelay) {
aux = 1;
if (restore_opt(sk, SOL_TCP, TCP_NODELAY, &aux))
diff --git a/soccr/soccr.c b/soccr/soccr.c
index ebd0374..a5c5812 100644
--- a/soccr/soccr.c
+++ b/soccr/soccr.c
@@ -449,6 +449,16 @@ static int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk,
if (data->state == TCP_LISTEN)
return -1;
+ if (sk->src_addr->sa.sa_family == AF_INET)
+ addr_size = sizeof(sk->dst_addr->v4);
+ else
+ addr_size = sizeof(sk->dst_addr->v6);
+
+ if (bind(sk->fd, &sk->src_addr->sa, addr_size)) {
+ loge("Can't connect inet socket back\n");
+ return -1;
+ }
+
if (mstate & (RCVQ_FIRST_FIN | RCVQ_SECOND_FIN))
data->inq_seq--;
@@ -841,7 +851,7 @@ int libsoccr_set_queue_bytes(struct libsoccr_sk *sk, int queue_id, char *bytes,
sk->recv_queue = bytes;
if (flags & SOCCR_MEM_EXCL)
sk->flags |= SK_FLAG_FREE_RQ;
- break;
+ return 0;
case TCP_SEND_QUEUE:
sk->send_queue = bytes;
if (flags & SOCCR_MEM_EXCL)
diff --git a/soccr/soccr.h b/soccr/soccr.h
index f46116a..a30129d 100644
--- a/soccr/soccr.h
+++ b/soccr/soccr.h
@@ -224,7 +224,7 @@ int libsoccr_set_queue_bytes(struct libsoccr_sk *sk, int queue_id, char *bytes,
int libsoccr_set_addr(struct libsoccr_sk *sk, int self, union libsoccr_addr *, unsigned flags);
/*
- * Performs restore actions on bind()-ed socket
+ * Performs restore actions on a socket
*/
int libsoccr_restore(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size);
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 42162f5..ec07303 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -261,6 +261,7 @@ TST_DIR = \
mntns_link_ghost \
mntns_shared_bind \
mntns_shared_bind02 \
+ mntns_shared_bind03 \
mntns_root_bind \
mntns_root_bind02 \
mntns_overmount \
diff --git a/test/zdtm/static/mntns_shared_bind03.c b/test/zdtm/static/mntns_shared_bind03.c
new file mode 100644
index 0000000..32d0869
--- /dev/null
+++ b/test/zdtm/static/mntns_shared_bind03.c
@@ -0,0 +1,124 @@
+#define _GNU_SOURCE
+#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 <sched.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include "zdtmtst.h"
+
+#ifndef CLONE_NEWNS
+#define CLONE_NEWNS 0x00020000
+#endif
+
+const char *test_doc = "Check shared non-root bind-mounts with different shared groups";
+const char *test_author = "Andrew Vagin <avagin at gmail.com>";
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+
+int main(int argc, char **argv)
+{
+ test_init(argc, argv);
+
+ if (mkdir(dirname, 0700)) {
+ pr_perror("mkdir");
+ return 1;
+ }
+
+ if (chdir(dirname))
+ return 1;
+
+ if (mkdir("1", 0700) || mkdir("2", 0700) || mkdir("3", 0700)) {
+ pr_perror("mkdir");
+ return 1;
+ }
+
+ if (mkdir("A", 0700)) {
+ pr_perror("mkdir");
+ return 1;
+ }
+
+ if (mkdir("B", 0700)) {
+ pr_perror("mkdir");
+ return 1;
+ }
+
+ if (mount("1", "1", NULL, MS_BIND, NULL) ||
+ mount(NULL, "1", NULL, MS_PRIVATE, NULL) ||
+ mount(NULL, "1", NULL, MS_SHARED, NULL)) {
+ pr_perror("mount");
+ return 1;
+ }
+
+ if (mount("1", "A", NULL, MS_BIND, NULL) ||
+ mount(NULL, "A", NULL, MS_PRIVATE, NULL) ||
+ mount(NULL, "A", NULL, MS_SHARED, NULL)) {
+ pr_perror("mount");
+ return 1;
+ }
+
+ if (mount("1", "B", NULL, MS_BIND, NULL) ||
+ mount(NULL, "B", NULL, MS_SLAVE, NULL)) {
+ pr_perror("mount");
+ return 1;
+ }
+
+ if (mkdir("1/D", 0700)) {
+ pr_perror("mkdir");
+ return 1;
+ }
+
+ if (mount("1/D", "2", NULL, MS_BIND, NULL)) {
+ pr_perror("mount");
+ return 1;
+ }
+
+ if (mount("1", "3", NULL, MS_BIND, NULL)) {
+ pr_perror("mount");
+ return 1;
+ }
+
+ test_daemon();
+ test_waitsig();
+
+ if (mkdir("1/D/test", 0700)) {
+ pr_perror("mkdir");
+ return 1;
+ }
+
+ if (mount("zdtm_shared", "1/D/test", "tmpfs", 0, NULL)) {
+ pr_perror("mount");
+ return 1;
+ }
+
+ if (mount(NULL, "3", NULL, MS_PRIVATE, NULL)) {
+ pr_perror("mount");
+ return 1;
+ }
+
+ if (umount("B/D/test")) {
+ pr_perror("umount");
+ return 1;
+ }
+ if (umount("2/test")) {
+ pr_perror("umount");
+ return 1;
+ }
+ if (umount("3/D/test")) {
+ pr_perror("umount");
+ return 1;
+ }
+
+ pass();
+
+ return 0;
+}
diff --git a/test/zdtm/static/mntns_shared_bind03.desc b/test/zdtm/static/mntns_shared_bind03.desc
new file mode 100644
index 0000000..a8849e0
--- /dev/null
+++ b/test/zdtm/static/mntns_shared_bind03.desc
@@ -0,0 +1 @@
+{'flavor': 'ns uns', 'flags': 'suid', 'feature': 'mnt_id'}
--
2.7.4
More information about the CRIU
mailing list