Re: prctl(PR_SET_MM)

From: Amnon Shiloh
Date: Thu Feb 21 2013 - 02:46:58 EST


Cyrill Gorcunov wrote:

>> Another possibility is to have a dual #if:
>>
>> #if defined(CONFIG_CHECKPOINT_RESTORE) || defined(CONFIG_MM_FIELDS_SETTING)
>
> Thus this approach looks preferred. And MM_FIELDS_SETTING will be y by default.
> Mind to cook a patch and lets see if community accept it? Don't forget to
> CC Andrew Morton.

Very well, patch attached.

Amnon.
diff -Naur before/init/Kconfig after/init/Kconfig
--- before/init/Kconfig 2013-02-19 10:28:34.000000000 +1030
+++ after/init/Kconfig 2013-02-21 18:03:48.000000000 +1030
@@ -999,6 +999,22 @@

If unsure, say N here.

+config MM_FIELDS_SETTING
+ bool "Allow modifying per-process memory-region fields"
+ default y
+ help
+ Support "prctl(PR_SET_MM)" which allows applications to modify
+ the following in their "mm_struct":
+
+ start_code, end_code, start_data, end_data, start_brk, brk,
+ start_stack, arg_start, arg_end, env_start, env_end.
+
+ Also to modify their executable file ("/proc/self/exe").
+
+ This option is needed for reconstructing processes (such as when
+ restoring a process from a checkpoint; duplicating a process;
+ or migrating it to another computer).
+
menuconfig NAMESPACES
bool "Namespaces support" if EXPERT
default !EXPERT
diff -Naur before/kernel/sys.c after/kernel/sys.c
--- before/kernel/sys.c 2013-02-19 10:28:34.000000000 +1030
+++ after/kernel/sys.c 2013-02-21 17:19:10.000000000 +1030
@@ -1788,7 +1788,7 @@
return mask;
}

-#ifdef CONFIG_CHECKPOINT_RESTORE
+#if defined(CONFIG_CHECKPOINT_RESTORE) || defined(CONFIG_MM_FIELDS_SETTING)
static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
{
struct fd exe;
@@ -1981,18 +1981,22 @@
up_read(&mm->mmap_sem);
return error;
}
+#else /* CONFIG_CHECKPOINT_RESTORE || CONFIG_MM_FIELDS_SETTING */

-static int prctl_get_tid_address(struct task_struct *me, int __user **tid_addr)
-{
- return put_user(me->clear_child_tid, tid_addr);
-}
-
-#else /* CONFIG_CHECKPOINT_RESTORE */
static int prctl_set_mm(int opt, unsigned long addr,
unsigned long arg4, unsigned long arg5)
{
return -EINVAL;
}
+#endif
+
+#ifdef CONFIG_CHECKPOINT_RESTORE
+static int prctl_get_tid_address(struct task_struct *me, int __user **tid_addr)
+{
+ return put_user(me->clear_child_tid, tid_addr);
+}
+
+#else
static int prctl_get_tid_address(struct task_struct *me, int __user **tid_addr)
{
return -EINVAL;