[CRIU] [PATCH] auxv: Use real size of the auxv vector

Cyrill Gorcunov gorcunov at openvz.org
Sat Oct 27 05:22:30 EDT 2012


The size of vector depends on the kernel config
so use the real size of a vector dumped. Otherwise
we might fail on restore.

Reported-by: Stanislav Kinsbursky <skinsbursky at parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-dump.c          |    5 +++--
 cr-restore.c       |    5 +++--
 include/restorer.h |    1 +
 restorer.c         |    3 +--
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index d9b8e1c..84609e0 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -537,7 +537,7 @@ static int dump_task_creds(struct parasite_ctl *ctl, const struct cr_fdset *fds)
 #define assign_reg(dst, src, e)		do { dst->e = (__typeof__(dst->e))src.e; } while (0)
 #define assign_array(dst, src, e)	memcpy(dst->e, &src.e, sizeof(src.e))
 
-static int get_task_auxv(pid_t pid, MmEntry *mm)
+static int get_task_auxv(pid_t pid, MmEntry *mm, size_t *size)
 {
 	int fd, ret, i;
 
@@ -560,6 +560,7 @@ static int get_task_auxv(pid_t pid, MmEntry *mm)
 		}
 	}
 
+	*size = i;
 	ret = 0;
 err:
 	close_safe(&fd);
@@ -591,7 +592,7 @@ static int dump_task_mm(pid_t pid, const struct proc_pid_stat *stat,
 	if (!mme.mm_saved_auxv)
 		goto out;
 
-	if (get_task_auxv(pid, &mme))
+	if (get_task_auxv(pid, &mme, &mme.n_mm_saved_auxv))
 		goto out;
 	pr_info("OK\n");
 
diff --git a/cr-restore.c b/cr-restore.c
index a4a3242..dfe6fdb 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1208,13 +1208,14 @@ static int prepare_mm(pid_t pid, struct task_restore_core_args *args)
 	args->mm.n_mm_saved_auxv = 0;
 	args->mm.mm_saved_auxv = NULL;
 
-	if (mm->n_mm_saved_auxv != AT_VECTOR_SIZE) {
+	if (mm->n_mm_saved_auxv > AT_VECTOR_SIZE) {
 		pr_err("Image corrupted on pid %d\n", pid);
 		goto out;
 	}
 
+	args->mm_saved_auxv_size = pb_repeated_size(mm, mm_saved_auxv);
 	memcpy(args->mm_saved_auxv, mm->mm_saved_auxv,
-	       pb_repeated_size(mm, mm_saved_auxv));
+	       args->mm_saved_auxv_size);
 
 	exe_fd = open_reg_by_id(args->mm.exe_file_id);
 	if (exe_fd < 0)
diff --git a/include/restorer.h b/include/restorer.h
index 732180c..1fb6301 100644
--- a/include/restorer.h
+++ b/include/restorer.h
@@ -109,6 +109,7 @@ struct task_restore_core_args {
 
 	MmEntry				mm;
 	u64				mm_saved_auxv[AT_VECTOR_SIZE];
+	u32				mm_saved_auxv_size;
 	u64				clear_tid_addr;
 	u64				blk_sigset;
 	char				comm[TASK_COMM_LEN];
diff --git a/restorer.c b/restorer.c
index 14958d5..01eaf45 100644
--- a/restorer.c
+++ b/restorer.c
@@ -463,8 +463,7 @@ long __export_restore_task(struct task_restore_core_args *args)
 	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,
-								sizeof(args->mm_saved_auxv));
+	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;
 
-- 
1.7.7.6



More information about the CRIU mailing list