From: Dmitry Safonov <dsafonov@virtuozzo.com>
To: <linux-kernel@vger.kernel.org>
Cc: <0x7f454c46@gmail.com>, Dmitry Safonov <dsafonov@virtuozzo.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Andy Lutomirski <luto@kernel.org>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
<x86@kernel.org>
Subject: [RFC 4/4] x86/arch_prctl: add ARCH_{GET,SET}_TASK_SIZE
Date: Fri, 30 Dec 2016 18:56:34 +0300 [thread overview]
Message-ID: <20161230155634.8692-5-dsafonov@virtuozzo.com> (raw)
In-Reply-To: <20161230155634.8692-1-dsafonov@virtuozzo.com>
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@virtuozzo.com>
---
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
next prev parent reply other threads:[~2016-12-30 16:15 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-30 15:56 [RFC 0/4] x86: keep TASK_SIZE in sync with mm->task_size Dmitry Safonov
2016-12-30 15:56 ` Dmitry Safonov
2016-12-30 15:56 ` Dmitry Safonov
2016-12-30 15:56 ` Dmitry Safonov
2016-12-30 15:56 ` Dmitry Safonov
2016-12-30 15:56 ` [RFC 1/4] mm: remove unused TASK_SIZE_OF() Dmitry Safonov
2016-12-30 15:56 ` Dmitry Safonov
2016-12-30 15:56 ` Dmitry Safonov
2016-12-30 15:56 ` Dmitry Safonov
2016-12-30 15:56 ` Dmitry Safonov
2016-12-31 1:36 ` Andy Lutomirski
2016-12-31 1:36 ` Andy Lutomirski
2016-12-31 1:36 ` Andy Lutomirski
2016-12-31 1:36 ` Andy Lutomirski
2017-01-02 6:57 ` Heiko Carstens
2017-01-02 6:57 ` Heiko Carstens
2017-01-02 6:57 ` Heiko Carstens
2017-01-02 6:57 ` Heiko Carstens
2017-01-02 9:53 ` Kirill A. Shutemov
2017-01-02 9:53 ` Kirill A. Shutemov
2017-01-02 9:53 ` Kirill A. Shutemov
2017-01-02 9:53 ` Kirill A. Shutemov
2017-01-05 9:51 ` David Laight
2017-01-05 9:51 ` David Laight
2017-01-05 9:51 ` David Laight
2017-01-05 9:51 ` David Laight
2017-01-05 17:54 ` Andy Lutomirski
2017-01-05 17:54 ` Andy Lutomirski
2017-01-05 17:54 ` Andy Lutomirski
2017-01-05 17:54 ` Andy Lutomirski
2016-12-30 15:56 ` [RFC 2/4] x86/thread_info: kill TIF_ADDR32 in favour of ADDR_LIMIT_32BIT Dmitry Safonov
2016-12-31 1:38 ` Andy Lutomirski
2016-12-30 15:56 ` [RFC 3/4] x86/mm: define TASK_SIZE as current->mm->task_size Dmitry Safonov
2016-12-30 15:56 ` Dmitry Safonov [this message]
2016-12-31 2:02 ` [RFC 4/4] x86/arch_prctl: add ARCH_{GET,SET}_TASK_SIZE Andy Lutomirski
2016-12-31 11:10 ` Dmitry Safonov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161230155634.8692-5-dsafonov@virtuozzo.com \
--to=dsafonov@virtuozzo.com \
--cc=0x7f454c46@gmail.com \
--cc=hpa@zytor.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.