[CRIU] [PATCH] dump: use vmas pointer

Ruslan Kuprieiev kupruser at gmail.com
Wed Oct 2 05:39:34 PDT 2013


Hi!

When dump/pre-dump failed before initializing vmas, free_mappings(&vmas) 
is called and this cause segfault. So lets use vmas pointer, initialize 
it with NULL, xmalloc where needed and check for NULL in free_mappings().

Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
-------------- next part --------------
---
diff --git a/cr-dump.c b/cr-dump.c
index 8e8d332..8ade81a 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -106,6 +106,9 @@ void free_mappings(struct vm_area_list *vma_area_list)
 {
 	struct vma_area *vma_area, *p;
 
+	if (!vma_area_list)
+		return;
+
 	list_for_each_entry_safe(vma_area, p, &vma_area_list->h, list) {
 		if (vma_area->vm_file_fd > 0)
 			close(vma_area->vm_file_fd);
@@ -1291,7 +1294,7 @@ err:
 static int pre_dump_one_task(struct pstree_item *item, struct list_head *ctls)
 {
 	pid_t pid = item->pid.real;
-	struct vm_area_list vmas;
+	struct vm_area_list *vmas = NULL;
 	struct parasite_ctl *parasite_ctl;
 	int ret = -1;
 	struct parasite_dump_misc misc;
@@ -1308,14 +1311,18 @@ static int pre_dump_one_task(struct pstree_item *item, struct list_head *ctls)
 	if (item->state == TASK_DEAD)
 		return 0;
 
-	ret = collect_mappings(pid, &vmas);
+	vmas = xmalloc(sizeof(*vmas));
+	if (!vmas)
+		goto err;
+
+	ret = collect_mappings(pid, vmas);
 	if (ret) {
 		pr_err("Collect mappings (pid: %d) failed with %d\n", pid, ret);
 		goto err;
 	}
 
 	ret = -1;
-	parasite_ctl = parasite_infect_seized(pid, item, &vmas, NULL, 0);
+	parasite_ctl = parasite_infect_seized(pid, item, vmas, NULL, 0);
 	if (!parasite_ctl) {
 		pr_err("Can't infect (pid: %d) with parasite\n", pid);
 		goto err_free;
@@ -1329,7 +1336,7 @@ static int pre_dump_one_task(struct pstree_item *item, struct list_head *ctls)
 
 	parasite_ctl->pid.virt = item->pid.virt = misc.pid;
 
-	ret = parasite_dump_pages_seized(parasite_ctl, &vmas, &parasite_ctl->mem_pp);
+	ret = parasite_dump_pages_seized(parasite_ctl, vmas, &parasite_ctl->mem_pp);
 	if (ret)
 		goto err_cure;
 
@@ -1337,7 +1344,7 @@ static int pre_dump_one_task(struct pstree_item *item, struct list_head *ctls)
 		pr_err("Can't cure (pid: %d) from parasite\n", pid);
 	list_add_tail(&parasite_ctl->pre_list, ctls);
 err_free:
-	free_mappings(&vmas);
+	free_mappings(vmas);
 err:
 	return ret;
 
@@ -1350,7 +1357,7 @@ err_cure:
 static int dump_one_task(struct pstree_item *item)
 {
 	pid_t pid = item->pid.real;
-	struct vm_area_list vmas;
+	struct vm_area_list *vmas = NULL;
 	struct parasite_ctl *parasite_ctl;
 	int ret = -1;
 	struct parasite_dump_misc misc;
@@ -1388,7 +1395,11 @@ static int dump_one_task(struct pstree_item *item)
 		goto err;
 	}
 
-	ret = collect_mappings(pid, &vmas);
+	vmas = xmalloc(sizeof(*vmas));
+	if (!vmas)
+		goto err;
+
+	ret = collect_mappings(pid, vmas);
 	if (ret) {
 		pr_err("Collect mappings (pid: %d) failed with %d\n", pid, ret);
 		goto err;
@@ -1407,7 +1418,7 @@ static int dump_one_task(struct pstree_item *item)
 	}
 
 	ret = -1;
-	parasite_ctl = parasite_infect_seized(pid, item, &vmas, dfds, proc_args.timer_n);
+	parasite_ctl = parasite_infect_seized(pid, item, vmas, dfds, proc_args.timer_n);
 	if (!parasite_ctl) {
 		pr_err("Can't infect (pid: %d) with parasite\n", pid);
 		goto err;
@@ -1421,7 +1432,7 @@ static int dump_one_task(struct pstree_item *item)
 		}
 	}
 
-	ret = parasite_fixup_vdso(parasite_ctl, pid, &vmas);
+	ret = parasite_fixup_vdso(parasite_ctl, pid, vmas);
 	if (ret) {
 		pr_err("Can't fixup vdso VMAs (pid: %d)\n", pid);
 		goto err_cure_fdset;
@@ -1475,7 +1486,7 @@ static int dump_one_task(struct pstree_item *item)
 		}
 	}
 
-	ret = parasite_dump_pages_seized(parasite_ctl, &vmas, NULL);
+	ret = parasite_dump_pages_seized(parasite_ctl, vmas, NULL);
 	if (ret)
 		goto err_cure;
 
@@ -1527,7 +1538,7 @@ static int dump_one_task(struct pstree_item *item)
 		goto err;
 	}
 
-	ret = dump_task_mappings(pid, &vmas, cr_fdset);
+	ret = dump_task_mappings(pid, vmas, cr_fdset);
 	if (ret) {
 		pr_err("Dump mappings (pid: %d) failed with %d\n", pid, ret);
 		goto err;
@@ -1555,7 +1566,7 @@ static int dump_one_task(struct pstree_item *item)
 err:
 	close_pid_proc();
 err_free:
-	free_mappings(&vmas);
+	free_mappings(vmas);
 	xfree(dfds);
 	return ret;
 


More information about the CRIU mailing list