[2/3] rst: No exe link restore for unpriviledged mode

Submitted by Pavel Emelianov on May 5, 2016, 8:31 p.m.

Details

Message ID 572BAD8E.4090104@virtuozzo.com
State Accepted
Series "unshare: Userns support"
Commit 5c54e815f678e81870b89572b041981605d8f378
Headers show

Commit Message

Pavel Emelianov May 5, 2016, 8:31 p.m.
When having uid and gid not zero exe link restore is not
allowed by the kernel.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/cr-restore.c   | 14 +++++++++-----
 criu/pie/restorer.c |  9 +++++++--
 2 files changed, 16 insertions(+), 7 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index ef77abe..797669d 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -79,7 +79,7 @@ 
 #include "fault-injection.h"
 #include "uffd.h"
 #include "sk-queue.h"
-
+#include "syscall-types.h"
 #include "parasite-syscall.h"
 
 #include "protobuf.h"
@@ -2644,11 +2644,15 @@  static int prepare_mm(pid_t pid, struct task_restore_args *args)
 		args->mm_saved_auxv[i] = (auxv_t)mm->mm_saved_auxv[i];
 	}
 
-	exe_fd = open_reg_by_id(mm->exe_file_id);
-	if (exe_fd < 0)
-		goto out;
+	if (!(opts.unshare_flags & UNSHARE_UNPRIVILEDGED)) {
+		exe_fd = open_reg_by_id(mm->exe_file_id);
+		if (exe_fd < 0)
+			goto out;
+
+		args->fd_exe_link = exe_fd;
+	} else
+		args->fd_exe_link = -1;
 
-	args->fd_exe_link = exe_fd;
 	ret = 0;
 out:
 	return ret;
diff --git a/criu/pie/restorer.c b/criu/pie/restorer.c
index 5fc8949..1058dbf 100644
--- a/criu/pie/restorer.c
+++ b/criu/pie/restorer.c
@@ -498,6 +498,9 @@  static long restore_self_exe_late(struct task_restore_args *args)
 {
 	int fd = args->fd_exe_link, ret;
 
+	if (fd == -1)
+		return 0;
+
 	pr_info("Restoring EXE link\n");
 	ret = sys_prctl_safe(PR_SET_MM, PR_SET_MM_EXE_FILE, fd, 0);
 	if (ret)
@@ -1282,8 +1285,10 @@  long __export_restore_task(struct task_restore_args *args)
 		 * new ones from image file.
 		 */
 		ret |= restore_self_exe_late(args);
-	} else
-		sys_close(args->fd_exe_link);
+	} else {
+		if (args->fd_exe_link != -1)
+			sys_close(args->fd_exe_link);
+	}
 
 	if (ret)
 		goto core_restore_end;