Commit ebb7087a authored by Andrei Vagin's avatar Andrei Vagin Committed by Pavel Emelyanov

pipe: reopen pipes via usernsd

If a pipe is inherited (external), it may be impossible to reopen it
from a restored user namespace due to lack of permession,
so in this case we have to reopen it via usernsd.

https://github.com/opencontainers/runc/issues/1333Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
Acked-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 1de7fdff
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "images/pipe.pb-c.h" #include "images/pipe.pb-c.h"
#include "images/pipe-data.pb-c.h" #include "images/pipe-data.pb-c.h"
#include "fcntl.h" #include "fcntl.h"
#include "namespaces.h"
static LIST_HEAD(pipes); static LIST_HEAD(pipes);
...@@ -213,10 +214,10 @@ err: ...@@ -213,10 +214,10 @@ err:
return ret; return ret;
} }
static int reopen_pipe(int fd, int flags) static int userns_reopen(void *_arg, int fd, pid_t pid)
{ {
int ret;
char path[PSFDS]; char path[PSFDS];
int ret, flags = *(int*)_arg;
sprintf(path, "/proc/self/fd/%d", fd); sprintf(path, "/proc/self/fd/%d", fd);
ret = open(path, flags); ret = open(path, flags);
...@@ -227,6 +228,26 @@ static int reopen_pipe(int fd, int flags) ...@@ -227,6 +228,26 @@ static int reopen_pipe(int fd, int flags)
return ret; return ret;
} }
static int reopen_pipe(int fd, int flags)
{
int ret;
char path[PSFDS];
sprintf(path, "/proc/self/fd/%d", fd);
ret = open(path, flags);
if (ret < 0) {
if (errno == EACCES) {
/* It may be an external pipe from an another userns */
ret = userns_call(userns_reopen, UNS_FDOUT,
&flags, sizeof(flags), fd);
} else
pr_perror("Unable to reopen the pipe %s", path);
}
close(fd);
return ret;
}
static int recv_pipe_fd(struct pipe_info *pi, int *new_fd) static int recv_pipe_fd(struct pipe_info *pi, int *new_fd)
{ {
int tmp, fd, ret; int tmp, fd, ret;
......
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