[v4,27/31] shmem: Fixup shmem_wait_and_open() opens foreign /proc/[pid]/fd/[i]

Submitted by Kirill Tkhai on Feb. 22, 2017, 11:34 a.m.

Details

Message ID 148776327203.17334.3362086457009424918.stgit@localhost.localdomain
State New
Series "Nested user namespaces support"
Headers show

Commit Message

Kirill Tkhai Feb. 22, 2017, 11:34 a.m.
When target process is in a user_ns, where we do not have a permissions,
we need use usernsd helper to get its fds.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/shmem.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/shmem.c b/criu/shmem.c
index fac4b83ef..21a9d8b9e 100644
--- a/criu/shmem.c
+++ b/criu/shmem.c
@@ -22,6 +22,7 @@ 
 #include "types.h"
 #include "page.h"
 #include "util.h"
+#include "pstree.h"
 #include "protobuf.h"
 #include "images/pagemap.pb-c.h"
 
@@ -450,7 +451,8 @@  static int shmem_wait_and_open(int pid, struct shmem_info *si, VmaEntry *vi)
 		si->pid, si->fd);
 
 	pr_info("Opening shmem [%s] \n", path);
-	ret = open_proc_rw(si->pid, "fd/%d", si->fd);
+	pid = pstree_pid_by_virt(si->pid)->real;
+	ret = open_fd_of_real_pid(pid, si->fd, O_RDWR);
 	futex_inc_and_wake(&si->lock);
 	if (ret < 0)
 		return -1;