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

From: Dmitry Safonov
Date: Fri Dec 30 2016 - 11:15:05 EST


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 <dsafonov@xxxxxxxxxxxxx>
---
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