* [patch 0/2] c/r update to prctl @ 2012-03-09 21:41 Cyrill Gorcunov 2012-03-09 21:41 ` [patch 1/2] c/r: prctl: Add ability to set new mm_struct::exe_file v6 Cyrill Gorcunov 2012-03-09 21:41 ` [patch 2/2] c/r: prctl: Add ability to get clear_tid_address Cyrill Gorcunov 0 siblings, 2 replies; 6+ messages in thread From: Cyrill Gorcunov @ 2012-03-09 21:41 UTC (permalink / raw) To: LKML, Andrew Morton Cc: Matt Helsley, KOSAKI Motohiro, Pavel Emelyanov, Kees Cook, Tejun Heo, Oleg Nesterov 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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [patch 1/2] c/r: prctl: Add ability to set new mm_struct::exe_file v6 2012-03-09 21:41 [patch 0/2] c/r update to prctl Cyrill Gorcunov @ 2012-03-09 21:41 ` Cyrill Gorcunov 2012-03-09 21:41 ` [patch 2/2] c/r: prctl: Add ability to get clear_tid_address Cyrill Gorcunov 1 sibling, 0 replies; 6+ messages in thread From: Cyrill Gorcunov @ 2012-03-09 21:41 UTC (permalink / raw) To: LKML, Andrew Morton Cc: Matt Helsley, KOSAKI Motohiro, Pavel Emelyanov, Kees Cook, Tejun Heo, Oleg Nesterov, Cyrill Gorcunov [-- Attachment #1: c-r-prctl-add-SET_MM-new-4 --] [-- Type: text/plain, Size: 3370 bytes --] 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. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Reviewed-by: Oleg Nesterov <oleg@redhat.com> CC: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> CC: Pavel Emelyanov <xemul@parallels.com> CC: Kees Cook <keescook@chromium.org> CC: Tejun Heo <tj@kernel.org> CC: Matt Helsley <matthltc@us.ibm.com> --- include/linux/prctl.h | 1 kernel/sys.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) Index: linux-2.6.git/include/linux/prctl.h =================================================================== --- linux-2.6.git.orig/include/linux/prctl.h +++ 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 */ Index: linux-2.6.git/kernel/sys.c =================================================================== --- linux-2.6.git.orig/kernel/sys.c +++ linux-2.6.git/kernel/sys.c @@ -36,6 +36,8 @@ #include <linux/personality.h> #include <linux/ptrace.h> #include <linux/fs_struct.h> +#include <linux/file.h> +#include <linux/mount.h> #include <linux/gfp.h> #include <linux/syscore_ops.h> #include <linux/version.h> @@ -1701,6 +1703,53 @@ static bool vma_flags_mismatch(struct vm (vma->vm_flags & banned); } +static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd) +{ + struct file *exe_file; + struct dentry *dentry; + int err; + + /* + * Setting new mm::exe_file is only allowed + * when no VM_EXECUTABLE vma's left. This is + * a special C/R case when a restored program + * need to change own /proc/$pid/exe symlink. + * After this call mm::num_exe_file_vmas become + * meaningless. + */ + if (mm->num_exe_file_vmas) + return -EBUSY; + + exe_file = fget(fd); + if (!exe_file) + return -EBADF; + + dentry = exe_file->f_path.dentry; + + /* + * Because the original mm->exe_file + * points to executable file, make sure + * this one is executable as well to not + * break an overall picture. + */ + err = -EACCES; + if (!S_ISREG(dentry->d_inode->i_mode) || + exe_file->f_path.mnt->mnt_flags & MNT_NOEXEC) + goto exit; + + err = inode_permission(dentry->d_inode, MAY_EXEC); + if (err) + goto exit; + + down_write(&mm->mmap_sem); + set_mm_exe_file(mm, exe_file); + up_write(&mm->mmap_sem); + +exit: + fput(exe_file); + return err; +} + static int prctl_set_mm(int opt, unsigned long addr, unsigned long arg4, unsigned long arg5) { @@ -1715,6 +1764,9 @@ static int prctl_set_mm(int opt, unsigne if (!capable(CAP_SYS_RESOURCE)) return -EPERM; + if (opt == PR_SET_MM_EXE_FILE) + return prctl_set_mm_exe_file(mm, (unsigned int)addr); + if (addr >= TASK_SIZE) return -EINVAL; ^ permalink raw reply [flat|nested] 6+ messages in thread
* [patch 2/2] c/r: prctl: Add ability to get clear_tid_address 2012-03-09 21:41 [patch 0/2] c/r update to prctl Cyrill Gorcunov 2012-03-09 21:41 ` [patch 1/2] c/r: prctl: Add ability to set new mm_struct::exe_file v6 Cyrill Gorcunov @ 2012-03-09 21:41 ` Cyrill Gorcunov 1 sibling, 0 replies; 6+ messages in thread From: Cyrill Gorcunov @ 2012-03-09 21:41 UTC (permalink / raw) To: LKML, Andrew Morton Cc: Matt Helsley, KOSAKI Motohiro, Pavel Emelyanov, Kees Cook, Tejun Heo, Oleg Nesterov, Andrew Vagin, Cyrill Gorcunov, Pedro Alves [-- Attachment #1: c-r-prctl-add-PR_GET_TID_ADDRESS --] [-- Type: text/plain, Size: 2295 bytes --] 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. Signed-off-by: Andrew Vagin <avagin@openvz.org> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> CC: Pedro Alves <palves@redhat.com> CC: Oleg Nesterov <oleg@redhat.com> CC: Pavel Emelyanov <xemul@parallels.com> CC: Tejun Heo <tj@kernel.org> --- include/linux/prctl.h | 2 ++ kernel/sys.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) Index: linux-2.6.git/include/linux/prctl.h =================================================================== --- linux-2.6.git.orig/include/linux/prctl.h +++ 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 */ Index: linux-2.6.git/kernel/sys.c =================================================================== --- linux-2.6.git.orig/kernel/sys.c +++ 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; ^ permalink raw reply [flat|nested] 6+ messages in thread
* [patch 0/2] [PATCH 0/2] prctl extension in a sake of c/r @ 2012-03-16 20:55 Cyrill Gorcunov 2012-03-16 20:55 ` [patch 2/2] c/r: prctl: Add ability to get clear_tid_address Cyrill Gorcunov 0 siblings, 1 reply; 6+ messages in thread From: Cyrill Gorcunov @ 2012-03-16 20:55 UTC (permalink / raw) To: LKML Cc: Andrew Morton, Oleg Nesterov, KOSAKI Motohiro, Pavel Emelyanov, Kees Cook, Tejun Heo, Matt Helsley Hi, this series is resulting one from long discuss about ability to restore /proc/pid/exe. Hope it will fit everyone. While exe symlink has been reviewed (and actually fixed, thanks a lot Oleg!) I've got no opinions on "Add ability to get clear_tid_address" one. Anyway both patches have been tested intensively. Cyrill ^ permalink raw reply [flat|nested] 6+ messages in thread
* [patch 2/2] c/r: prctl: Add ability to get clear_tid_address 2012-03-16 20:55 [patch 0/2] [PATCH 0/2] prctl extension in a sake of c/r Cyrill Gorcunov @ 2012-03-16 20:55 ` Cyrill Gorcunov 2012-03-19 16:51 ` Kees Cook 0 siblings, 1 reply; 6+ messages in thread From: Cyrill Gorcunov @ 2012-03-16 20:55 UTC (permalink / raw) To: LKML Cc: Andrew Morton, Oleg Nesterov, KOSAKI Motohiro, Pavel Emelyanov, Kees Cook, Tejun Heo, Matt Helsley, Andrew Vagin, Cyrill Gorcunov, Pedro Alves [-- Attachment #1: c-r-prctl-add-PR_GET_TID_ADDRESS --] [-- Type: text/plain, Size: 2295 bytes --] 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. Signed-off-by: Andrew Vagin <avagin@openvz.org> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> CC: Pedro Alves <palves@redhat.com> CC: Oleg Nesterov <oleg@redhat.com> CC: Pavel Emelyanov <xemul@parallels.com> CC: Tejun Heo <tj@kernel.org> --- include/linux/prctl.h | 2 ++ kernel/sys.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) Index: linux-2.6.git/include/linux/prctl.h =================================================================== --- linux-2.6.git.orig/include/linux/prctl.h +++ 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 */ Index: linux-2.6.git/kernel/sys.c =================================================================== --- linux-2.6.git.orig/kernel/sys.c +++ linux-2.6.git/kernel/sys.c @@ -1901,12 +1901,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, @@ -2061,6 +2071,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; ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch 2/2] c/r: prctl: Add ability to get clear_tid_address 2012-03-16 20:55 ` [patch 2/2] c/r: prctl: Add ability to get clear_tid_address Cyrill Gorcunov @ 2012-03-19 16:51 ` Kees Cook 2012-03-19 16:55 ` Cyrill Gorcunov 0 siblings, 1 reply; 6+ messages in thread From: Kees Cook @ 2012-03-19 16:51 UTC (permalink / raw) To: Cyrill Gorcunov Cc: LKML, Andrew Morton, Oleg Nesterov, KOSAKI Motohiro, Pavel Emelyanov, Tejun Heo, Matt Helsley, Andrew Vagin, Pedro Alves On Fri, Mar 16, 2012 at 1:55 PM, Cyrill Gorcunov <gorcunov@openvz.org> wrote: > 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. Is it worth introducing a syscall for this just for symmetry? I suspect not, in which case: Acked-by: Kees Cook <keescook@chromium.org> -Kees -- Kees Cook ChromeOS Security ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch 2/2] c/r: prctl: Add ability to get clear_tid_address 2012-03-19 16:51 ` Kees Cook @ 2012-03-19 16:55 ` Cyrill Gorcunov 0 siblings, 0 replies; 6+ messages in thread From: Cyrill Gorcunov @ 2012-03-19 16:55 UTC (permalink / raw) To: Kees Cook Cc: LKML, Andrew Morton, Oleg Nesterov, KOSAKI Motohiro, Pavel Emelyanov, Tejun Heo, Matt Helsley, Andrew Vagin, Pedro Alves On Mon, Mar 19, 2012 at 09:51:36AM -0700, Kees Cook wrote: > On Fri, Mar 16, 2012 at 1:55 PM, Cyrill Gorcunov <gorcunov@openvz.org> wrote: > > 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. > > Is it worth introducing a syscall for this just for symmetry? I > suspect not, in which case: > > Acked-by: Kees Cook <keescook@chromium.org> > Thanks Kees! syscall was considered as "no-no" in previous convesation about this patch, so we switched to prctl. Cyrill ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-03-19 16:55 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-03-09 21:41 [patch 0/2] c/r update to prctl Cyrill Gorcunov 2012-03-09 21:41 ` [patch 1/2] c/r: prctl: Add ability to set new mm_struct::exe_file v6 Cyrill Gorcunov 2012-03-09 21:41 ` [patch 2/2] c/r: prctl: Add ability to get clear_tid_address Cyrill Gorcunov 2012-03-16 20:55 [patch 0/2] [PATCH 0/2] prctl extension in a sake of c/r Cyrill Gorcunov 2012-03-16 20:55 ` [patch 2/2] c/r: prctl: Add ability to get clear_tid_address Cyrill Gorcunov 2012-03-19 16:51 ` Kees Cook 2012-03-19 16:55 ` Cyrill Gorcunov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®