From: Christian Brauner Date: Wed, 17 Apr 2019 20:50:25 +0000 (+0200) Subject: BACKPORT: signal: support CLONE_PIDFD with pidfd_send_signal X-Git-Tag: MMI-RSA31.Q1-48-36-11~14 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=351c66d97810422c5c5a93c09306d833aaffc237;p=GitHub%2FMotorolaMobilityLLC%2Fkernel-slsi.git BACKPORT: signal: support CLONE_PIDFD with pidfd_send_signal Let pidfd_send_signal() use pidfds retrieved via CLONE_PIDFD. With this patch pidfd_send_signal() becomes independent of procfs. This fullfils the request made when we merged the pidfd_send_signal() patchset. The pidfd_send_signal() syscall is now always available allowing for it to be used by users without procfs mounted or even users without procfs support compiled into the kernel. Signed-off-by: Christian Brauner Co-developed-by: Jann Horn Signed-off-by: Jann Horn Acked-by: Oleg Nesterov Cc: Arnd Bergmann Cc: "Eric W. Biederman" Cc: Kees Cook Cc: Thomas Gleixner Cc: David Howells Cc: "Michael Kerrisk (man-pages)" Cc: Andy Lutomirsky Cc: Andrew Morton Cc: Aleksa Sarai Cc: Linus Torvalds Cc: Al Viro (cherry picked from commit 2151ad1b067275730de1b38c7257478cae47d29e) Conflicts: kernel/sys_ni.c (1. Replaced COND_SYSCALL with cond_syscall.) Mot-CRs-fixed: (CR) Bug: 135608568 Test: test program using syscall(__NR_sys_pidfd_open,..) and poll() Change-Id: I621fe6547397e0e68c560d7da60ef7715deb290c Signed-off-by: Suren Baghdasaryan Reviewed-on: https://gerrit.mot.com/1505852 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Wang Wang Reviewed-by: Yonghui Jia Submit-Approved: Jira Key Reviewed-on: https://gerrit.mot.com/1796160 Reviewed-by: Xiangpo Zhao --- diff --git a/kernel/signal.c b/kernel/signal.c index 0fba758e1505..45b34181a763 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3048,7 +3048,6 @@ SYSCALL_DEFINE2(kill, pid_t, pid, int, sig) return kill_something_info(sig, &info, pid); } -#ifdef CONFIG_PROC_FS /* * Verify that the signaler and signalee either are in the same pid namespace * or that the signaler's pid namespace is an ancestor of the signalee's pid @@ -3070,6 +3069,14 @@ static bool access_pidfd_pidns(struct pid *pid) return true; } +static struct pid *pidfd_to_pid(const struct file *file) +{ + if (file->f_op == &pidfd_fops) + return file->private_data; + + return tgid_pidfd_to_pid(file); +} + static int copy_siginfo_from_user_any(siginfo_t *kinfo, siginfo_t __user *info) { #ifdef CONFIG_COMPAT @@ -3120,7 +3127,7 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, return -EBADF; /* Is this a pidfd? */ - pid = tgid_pidfd_to_pid(f.file); + pid = pidfd_to_pid(f.file); if (IS_ERR(pid)) { ret = PTR_ERR(pid); goto err; @@ -3159,7 +3166,6 @@ err: fdput(f); return ret; } -#endif /* CONFIG_PROC_FS */ static int do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info) diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index e91b8a5bebf0..b5189762d275 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -156,7 +156,6 @@ cond_syscall(compat_sys_io_submit); cond_syscall(compat_sys_io_getevents); cond_syscall(sys_sysfs); cond_syscall(sys_syslog); -cond_syscall(sys_pidfd_send_signal); cond_syscall(sys_process_vm_readv); cond_syscall(sys_process_vm_writev); cond_syscall(compat_sys_process_vm_readv);