[CRIU] [PATCH v3 5/6] ns: Fix wrong opened net ns file
Kirill Tkhai
ktkhai at virtuozzo.com
Sat Apr 1 04:37:55 PDT 2017
Since net ns is assigned after prepare_fds() and,
in common case, at the moment of open_ns_fd() call
task points to a net ns, which differs to its target
net ns, we can't get the ns from a task. So, get it
from fdstore. Also, support userns ns fds.
v2: Add comment
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
criu/namespaces.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 1cfe8bec..14492f5f 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -563,8 +563,23 @@ static int open_ns_fd(struct file_desc *d, int *new_fd)
struct ns_file_info *nfi = container_of(d, struct ns_file_info, d);
struct pstree_item *item, *t;
struct ns_desc *nd = NULL;
+ struct ns_id *ns;
+ int nsfd_id, fd;
char path[64];
- int fd;
+
+ for (ns = ns_ids; ns != NULL; ns = ns->next) {
+ if (ns->id != nfi->nfe->ns_id)
+ continue;
+ /* Check for CLONE_XXX as we use fdstore only if flag is set */
+ if (ns->nd == &user_ns_desc && (root_ns_mask & CLONE_NEWUSER))
+ nsfd_id = ns->user.nsfd_id;
+ else if (ns->nd == &net_ns_desc && (root_ns_mask & CLONE_NEWNET))
+ nsfd_id = ns->net.nsfd_id;
+ else
+ break;
+ fd = fdstore_get(nsfd_id);
+ goto check_open;
+ }
/*
* Find out who can open us.
@@ -582,6 +597,10 @@ static int open_ns_fd(struct file_desc *d, int *new_fd)
item = t;
nd = &net_ns_desc;
break;
+ } else if (ids->user_ns_id == nfi->nfe->ns_id) {
+ item = t;
+ nd = &user_ns_desc;
+ break;
} else if (ids->ipc_ns_id == nfi->nfe->ns_id) {
item = t;
nd = &ipc_ns_desc;
@@ -615,6 +634,7 @@ static int open_ns_fd(struct file_desc *d, int *new_fd)
path[sizeof(path) - 1] = '\0';
fd = open(path, nfi->nfe->flags);
+check_open:
if (fd < 0) {
pr_perror("Can't open file %s on restore", path);
return fd;
More information about the CRIU
mailing list