[v2,04/30] utils: Use daemon in open_fd_of_vpid() only its really need

Submitted by Kirill Tkhai on June 7, 2017, 11:24 a.m.

Details

Message ID 149683467254.4663.6701069056281410065.stgit@localhost.localdomain
State Accepted
Series "Support sockets leaked to child user_ns task"
Commit 170667afda99dfb1e954788d43b29d3af1065df9
Headers show

Commit Message

Kirill Tkhai June 7, 2017, 11:24 a.m.
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/util.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/util.c b/criu/util.c
index 5646b223f..e96ad36a2 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -1233,19 +1233,26 @@  int open_fd_of_vpid(pid_t pid, int fd, int flags)
 {
 	struct pstree_item *item;
 	char path[64];
+	bool daemon;
 	int ret;
 
 	item = pstree_pid_by_virt(pid)->item;
+	daemon = !can_access_userns(item->user_ns);
 	ret = sprintf(path, "%d/fd/%d", item->pid->real, fd) + 1;
 	pr_info("Opening /proc/%s on the criu side\n", path);
+
+#define MAYBE_CALL_IN_DAEMON(func, path, len)	\
+	(daemon ? userns_call(func, UNS_FDOUT, path, len, -1) : func(path, -1, -1))
 	if (flags == O_RDONLY)
-		ret = userns_call(fn_open_proc_r, UNS_FDOUT, path, ret, -1);
+		ret = MAYBE_CALL_IN_DAEMON(fn_open_proc_r, path, ret);
 	else if (flags == O_WRONLY)
-		ret = userns_call(fn_open_proc_w, UNS_FDOUT, path, ret, -1);
+		ret = MAYBE_CALL_IN_DAEMON(fn_open_proc_w, path, ret);
 	else if (flags == O_RDWR)
-		ret = userns_call(fn_open_proc_rw, UNS_FDOUT, path, ret, -1);
+		ret = MAYBE_CALL_IN_DAEMON(fn_open_proc_rw, path, ret);
 	else
 		BUG();
+#undef MAYBE_CALL_IN_DAEMON
+
 	return ret;
 }