Skip to contentSkip to conversation

c/r update to prctl

PATCH New Cyrill Gorcunov 1 participant 3 messages Mar 9, 2012

lore
Share & tools
lore
#0 lore raw

cover c/r update to prctl

Hi,

this is a series to extend prctl a bit for c/r needs.

- new PR_SET_MM_EXE_FILE option to setup /proc/pid/exe symlink on restored program
- new PR_GET_TID_ADDRESS option to retrieve process' clear_tid_address

Andrew, please drop Oleg's exe_path patch from -mm tree

 | The patch titled
 |    Subject: mm/exec: rename mm->exe_file to mm->exe_path
 | has been added to the -mm tree.  Its filename is
 |    mm-exec-rename-mm-exe_file-to-mm-exe_path.patch

This patch was deprecated.

Cyrill

#1 lore raw

PATCH 1/2 c/r: prctl: Add ability to set new mm_struct::exe_file v6

When we do restore we would like to have a way to setup a former mm_struct::exe_file so that /proc/pid/exe would point to the original executable file a process had at checkpoint time.

For this the PR_SET_MM_EXE_FILE code is introduced. This option takes a file descriptor which will be set as a source for new /proc/$pid/exe symlink.

Note it allows to change /proc/$pid/exe iif there are no VM_EXECUTABLE vmas present for current process, simply because this feature is a special to C/R and mm::num_exe_file_vmas become meaningless after that.

This feature is available iif CONFIG_CHECKPOINT_RESTORE is set.

CC KOSAKI Motohiro <[email protected]>
CC Pavel Emelyanov <[email protected]>
CC Kees Cook <[email protected]>
CC Tejun Heo <[email protected]>
CC Matt Helsley <[email protected]>
---
 include/linux/prctl.h |    1 
 kernel/sys.c          |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
include/linux/prctl.h +1 -0
Index: linux-2.6.git/include/linux/prctl.h
===================================================================
@@ -118,5 +118,6 @@
 # define PR_SET_MM_ENV_START		10
 # define PR_SET_MM_ENV_END		11
 # define PR_SET_MM_AUXV			12
+# define PR_SET_MM_EXE_FILE		13
 
 #endif /* _LINUX_PRCTL_H */
kernel/sys.c +52 -0

70 lines not on this page · raw message

#2 lore raw

PATCH 2/2 c/r: prctl: Add ability to get clear_tid_address

In reply to Cyrill Gorcunov

Zero is written at clear_tid_address, when
the process exits. This functionality is used
by pthread_join().

We already have sys_set_tid_address() to change this address for current task but there is no way to obtain it from a user space.

Without ability to find this address and dump it we can't restore pthread'ed apps which do call pthread_join() once they have been restored.

This patch introduces PR_GET_TID_ADDRESS prctl option which allow current process to obtain own clear_tid_address.

This feature is available iif CONFIG_CHECKPOINT_RESTORE is set.

CC Pedro Alves <[email protected]>
CC Oleg Nesterov <[email protected]>
CC Pavel Emelyanov <[email protected]>
CC Tejun Heo <[email protected]>
---
 include/linux/prctl.h |    2 ++
 kernel/sys.c          |   13 +++++++++++++
 2 files changed, 15 insertions(+)
include/linux/prctl.h +2 -0
Index: linux-2.6.git/include/linux/prctl.h
===================================================================
@@ -120,4 +120,6 @@
 # define PR_SET_MM_AUXV			12
 # define PR_SET_MM_EXE_FILE		13
 
+#define PR_GET_TID_ADDRESS		36
+
 #endif /* _LINUX_PRCTL_H */
kernel/sys.c +13 -0
Index: linux-2.6.git/kernel/sys.c
===================================================================
@@ -1897,12 +1897,22 @@ out:
 	up_read(&mm->mmap_sem);
 	return error;
 }
+
+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;
 }
+static int prctl_get_tid_address(struct task_struct *me, int __user **tid_addr)
+{
+	return -EINVAL;
+}
 #endif
 
 SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
@@ -2057,6 +2067,9 @@ SYSCALL_DEFINE5(prctl, int, option, unsi
 		case PR_SET_MM:
 			error = prctl_set_mm(arg2, arg3, arg4, arg5);
 			break;
+		case PR_GET_TID_ADDRESS:
+			error = prctl_get_tid_address(me, (int __user **)arg2);
+			break;
 		default:
 			error = -EINVAL;
 			break;