[CRIU] [PATCH 4/8] parasite: Add @pad argument for syscall run

Cyrill Gorcunov gorcunov at openvz.org
Mon Oct 5 12:54:33 PDT 2015


We will need an extra space for memfd based
syscall (without poking the stack since it's
not that safe without additional tests).

So add @pad argument which will be used
to find proper memory for seized syscall
execution.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 parasite-syscall.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/parasite-syscall.c b/parasite-syscall.c
index ee339db5d344..7ab8db1d32d2 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -39,19 +39,23 @@
 #include "asm/restorer.h"
 #include "pie/pie-relocs.h"
 
-static int can_run_syscall(unsigned long ip, unsigned long start, unsigned long end)
+static int can_run_syscall(unsigned long ip, unsigned long start,
+			   unsigned long end, unsigned long pad)
 {
-	return ip >= start && ip < (end - code_syscall_size);
+	return ip >= start && ip < (end - code_syscall_size - pad);
 }
 
-static int syscall_fits_vma_area(struct vma_area *vma_area)
+static int syscall_fits_vma_area(struct vma_area *vma_area, unsigned long pad)
 {
 	return can_run_syscall((unsigned long)vma_area->e->start,
 			       (unsigned long)vma_area->e->start,
-			       (unsigned long)vma_area->e->end);
+			       (unsigned long)vma_area->e->end,
+			       pad);
 }
 
-static struct vma_area *get_vma_by_ip(struct list_head *vma_area_list, unsigned long ip)
+static struct vma_area *get_vma_by_ip(struct list_head *vma_area_list,
+				      unsigned long ip,
+				      unsigned long pad)
 {
 	struct vma_area *vma_area;
 
@@ -60,7 +64,7 @@ static struct vma_area *get_vma_by_ip(struct list_head *vma_area_list, unsigned
 			continue;
 		if (!(vma_area->e->prot & PROT_EXEC))
 			continue;
-		if (syscall_fits_vma_area(vma_area))
+		if (syscall_fits_vma_area(vma_area, pad))
 			return vma_area;
 	}
 
@@ -1099,7 +1103,7 @@ struct parasite_ctl *parasite_prep_ctl(pid_t pid, struct vm_area_list *vma_area_
 		return ctl;
 
 	/* Search a place for injecting syscall */
-	vma_area = get_vma_by_ip(&vma_area_list->h, REG_IP(ctl->orig.regs));
+	vma_area = get_vma_by_ip(&vma_area_list->h, REG_IP(ctl->orig.regs), 0);
 	if (!vma_area) {
 		pr_err("No suitable VMA found to run parasite "
 		       "bootstrap code (pid: %d)\n", pid);
-- 
2.4.3



More information about the CRIU mailing list