[CRIU] [PATCH 09/11] restore: use new interface to set mm arguments

Andrey Vagin avagin at openvz.org
Wed Aug 13 00:51:36 PDT 2014


From: Cyrill Gorcunov <gorcunov at openvz.org>

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-check.c      | 22 ----------------------
 include/prctl.h | 19 +++++++++++++++++++
 pie/restorer.c  | 56 ++++++++++++++++++++------------------------------------
 3 files changed, 39 insertions(+), 58 deletions(-)

diff --git a/cr-check.c b/cr-check.c
index df51484..563b58f 100644
--- a/cr-check.c
+++ b/cr-check.c
@@ -153,7 +153,6 @@ static int check_kcmp(void)
 
 static int check_prctl(void)
 {
-	unsigned long user_auxv = 0;
 	unsigned int *tid_addr;
 	int ret;
 
@@ -163,27 +162,6 @@ static int check_prctl(void)
 		return -1;
 	}
 
-	ret = sys_prctl(PR_SET_MM, PR_SET_MM_BRK, sys_brk(0), 0, 0);
-	if (ret) {
-		if (ret == -EPERM)
-			pr_msg("prctl: One needs CAP_SYS_RESOURCE capability to perform testing\n");
-		else
-			pr_msg("prctl: PR_SET_MM is not supported\n");
-		return -1;
-	}
-
-	ret = sys_prctl(PR_SET_MM, PR_SET_MM_EXE_FILE, -1, 0, 0);
-	if (ret != -EBADF) {
-		pr_msg("prctl: PR_SET_MM_EXE_FILE is not supported (%d)\n", ret);
-		return -1;
-	}
-
-	ret = sys_prctl(PR_SET_MM, PR_SET_MM_AUXV, (long)&user_auxv, sizeof(user_auxv), 0);
-	if (ret) {
-		pr_msg("prctl: PR_SET_MM_AUXV is not supported\n");
-		return -1;
-	}
-
 	return 0;
 }
 
diff --git a/include/prctl.h b/include/prctl.h
index b815b96..c8b718a 100644
--- a/include/prctl.h
+++ b/include/prctl.h
@@ -38,8 +38,27 @@
 # define PR_SET_MM_ENV_END		11
 # define PR_SET_MM_AUXV			12
 # define PR_SET_MM_EXE_FILE		13
+# define PR_SET_MM_MAP			14
+# define PR_SET_MM_MAP_SIZE		15
 #endif
 
+struct prctl_mm_map {
+	unsigned long	start_code;
+	unsigned long	end_code;
+	unsigned long	start_data;
+	unsigned long	end_data;
+	unsigned long	start_brk;
+	unsigned long	brk;
+	unsigned long	start_stack;
+	unsigned long	arg_start;
+	unsigned long	arg_end;
+	unsigned long	env_start;
+	unsigned long	env_end;
+	unsigned long	*auxv;
+	unsigned int	auxv_size;
+	int		exe_fd;
+};
+
 #ifndef PR_GET_TID_ADDRESS
 # define PR_GET_TID_ADDRESS	40
 #endif
diff --git a/pie/restorer.c b/pie/restorer.c
index 6388fd5..fd172a4 100644
--- a/pie/restorer.c
+++ b/pie/restorer.c
@@ -381,19 +381,6 @@ core_restore_end:
 	return -1;
 }
 
-static long restore_self_exe_late(struct task_restore_args *args)
-{
-	int fd = args->fd_exe_link, ret;
-
-	pr_info("Restoring EXE link\n");
-	ret = sys_prctl_safe(PR_SET_MM, PR_SET_MM_EXE_FILE, fd, 0);
-	if (ret)
-		pr_err("Can't restore EXE link (%d)\n", ret);
-	sys_close(fd);
-
-	return ret;
-}
-
 static unsigned long restore_mapping(const VmaEntry *vma_entry)
 {
 	int prot	= vma_entry->prot;
@@ -891,29 +878,26 @@ long __export_restore_task(struct task_restore_args *args)
 	 * Tune up the task fields.
 	 */
 	ret |= sys_prctl_safe(PR_SET_NAME, (long)args->comm, 0, 0);
-
-	ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_START_CODE,	(long)args->mm.mm_start_code, 0);
-	ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_END_CODE,	(long)args->mm.mm_end_code, 0);
-	ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_START_DATA,	(long)args->mm.mm_start_data, 0);
-	ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_END_DATA,	(long)args->mm.mm_end_data, 0);
-	ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_START_STACK,	(long)args->mm.mm_start_stack, 0);
-	ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_START_BRK,	(long)args->mm.mm_start_brk, 0);
-	ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_BRK,		(long)args->mm.mm_brk, 0);
-	ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_ARG_START,	(long)args->mm.mm_arg_start, 0);
-	ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_ARG_END,	(long)args->mm.mm_arg_end, 0);
-	ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_ENV_START,	(long)args->mm.mm_env_start, 0);
-	ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_ENV_END,	(long)args->mm.mm_env_end, 0);
-	ret |= sys_prctl_safe(PR_SET_MM, PR_SET_MM_AUXV,	(long)args->mm_saved_auxv, args->mm_saved_auxv_size);
-	if (ret)
-		goto core_restore_end;
-
-	/*
-	 * Because of requirements applied from kernel side
-	 * we need to restore /proc/pid/exe symlink late,
-	 * after old existing VMAs are superseded with
-	 * new ones from image file.
-	 */
-	ret = restore_self_exe_late(args);
+	if (!ret) {
+		struct prctl_mm_map prctl_map = {
+			.start_code	= args->mm.mm_start_code,
+			.end_code	= args->mm.mm_end_code,
+			.start_data	= args->mm.mm_start_data,
+			.end_data	= args->mm.mm_end_data,
+			.start_stack	= args->mm.mm_start_stack,
+			.start_brk	= args->mm.mm_start_brk,
+			.brk		= args->mm.mm_brk,
+			.arg_start	= args->mm.mm_arg_start,
+			.arg_end	= args->mm.mm_arg_end,
+			.env_start	= args->mm.mm_env_start,
+			.env_end	= args->mm.mm_env_end,
+			.auxv_size	= args->mm_saved_auxv_size,
+			.auxv		= args->mm_saved_auxv,
+			.exe_fd		= args->fd_exe_link,
+		};
+		ret = sys_prctl_safe(PR_SET_MM, PR_SET_MM_MAP, (long)&prctl_map, sizeof(prctl_map));
+		sys_close(args->fd_exe_link);
+	}
 	if (ret)
 		goto core_restore_end;
 
-- 
1.9.3



More information about the CRIU mailing list