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

Submitted by Kirill Tkhai on Feb. 3, 2017, 4:16 p.m.

Details

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

Commit Message

Kirill Tkhai Feb. 3, 2017, 4:16 p.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 73f632f03..16a746dfd 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;