Thread (13 messages) 13 messages, 6 authors, 2017-01-05

[RFC 4/4] x86/arch_prctl: add ARCH_{GET,SET}_TASK_SIZE

From: Dmitry Safonov <hidden>
Date: 2016-12-30 16:15:00
Subsystem: the rest, x86 architecture (32-bit and 64-bit) · Maintainers: Linus Torvalds, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen

Add arch_prctl getters/setters for size of virtual address space of task.
This adds ability to change task's virtual address space limit.
I need this for correctly restore virtual address space limits in CRIU.
Currently, on x86 there are three task sizes: 3GB for some old 32 bit java
apps, 4Gb for ordinary 32-bit compatible apps and 47-bits for native
x86_64 processes.
32-bit applications are restored by CRIU with the help of 64-bit clone()-d
child, and on restore we need to place correct address space limitations
back - otherwise 32-bit restored application may mmap() address over
4Gb space and as this address will not fit into 4-byte pointer, it
will silently reuse/corrupt the pointer that has the same lower 4-bytes.

Signed-off-by: Dmitry Safonov <redacted>
---
 arch/x86/include/uapi/asm/prctl.h |  3 +++
 arch/x86/kernel/process_64.c      | 13 +++++++++++++
 2 files changed, 16 insertions(+)
diff --git a/arch/x86/include/uapi/asm/prctl.h b/arch/x86/include/uapi/asm/prctl.h
index 835aa51c7f6e..122a8ce5b051 100644
--- a/arch/x86/include/uapi/asm/prctl.h
+++ b/arch/x86/include/uapi/asm/prctl.h
@@ -6,6 +6,9 @@
 #define ARCH_GET_FS 0x1003
 #define ARCH_GET_GS 0x1004
 
+#define ARCH_SET_TASK_SIZE 0x1005
+#define ARCH_GET_TASK_SIZE 0x1006
+
 #define ARCH_MAP_VDSO_X32	0x2001
 #define ARCH_MAP_VDSO_32	0x2002
 #define ARCH_MAP_VDSO_64	0x2003
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index 8ce30d40bb33..ed6a792f7932 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -599,6 +599,19 @@ long do_arch_prctl(struct task_struct *task, int code, unsigned long addr)
 	}
 
 #ifdef CONFIG_CHECKPOINT_RESTORE
+	case ARCH_SET_TASK_SIZE:
+		if (addr >= TASK_SIZE_MAX)
+			return -EINVAL;
+		if (find_vma(current->mm, addr) != 0)
+			return -ENOMEM;
+		current->mm->task_size = addr;
+		break;
+
+	case ARCH_GET_TASK_SIZE:
+		ret = put_user(current->mm->task_size,
+				(unsigned long __user *)addr);
+		break;
+
 # ifdef CONFIG_X86_X32_ABI
 	case ARCH_MAP_VDSO_X32:
 		return prctl_map_vdso(&vdso_image_x32, addr);
-- 
2.11.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help