Commit 453a90e5 authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Andrei Vagin

ns: Fix wrong opened net ns file

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: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 35ad233f
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "namespaces.h" #include "namespaces.h"
#include "net.h" #include "net.h"
#include "cgroup.h" #include "cgroup.h"
#include "fdstore.h"
#include "protobuf.h" #include "protobuf.h"
#include "util.h" #include "util.h"
...@@ -515,8 +516,21 @@ static int open_ns_fd(struct file_desc *d, int *new_fd) ...@@ -515,8 +516,21 @@ 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 ns_file_info *nfi = container_of(d, struct ns_file_info, d);
struct pstree_item *item, *t; struct pstree_item *item, *t;
struct ns_desc *nd = NULL; struct ns_desc *nd = NULL;
struct ns_id *ns;
int nsfd_id, fd;
char path[64]; 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 == &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. * Find out who can open us.
...@@ -534,6 +548,10 @@ static int open_ns_fd(struct file_desc *d, int *new_fd) ...@@ -534,6 +548,10 @@ static int open_ns_fd(struct file_desc *d, int *new_fd)
item = t; item = t;
nd = &net_ns_desc; nd = &net_ns_desc;
break; 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) { } else if (ids->ipc_ns_id == nfi->nfe->ns_id) {
item = t; item = t;
nd = &ipc_ns_desc; nd = &ipc_ns_desc;
...@@ -567,6 +585,7 @@ static int open_ns_fd(struct file_desc *d, int *new_fd) ...@@ -567,6 +585,7 @@ static int open_ns_fd(struct file_desc *d, int *new_fd)
path[sizeof(path) - 1] = '\0'; path[sizeof(path) - 1] = '\0';
fd = open(path, nfi->nfe->flags); fd = open(path, nfi->nfe->flags);
check_open:
if (fd < 0) { if (fd < 0) {
pr_perror("Can't open file %s on restore", path); pr_perror("Can't open file %s on restore", path);
return fd; return fd;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment