Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5312947yba; Wed, 10 Apr 2019 16:44:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyU2caIADv9nNUxTaTLWwxvPnYhJbi+Pij+kvblmBdrzelsx219u6kDI+fGRIqfcoNnBmmz X-Received: by 2002:a17:902:822:: with SMTP id 31mr21682958plk.41.1554939877268; Wed, 10 Apr 2019 16:44:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554939877; cv=none; d=google.com; s=arc-20160816; b=mdOKYk5I6BV2qCtZBMvdgg3rucm6i/7x43cAkHNpGVUi2Y7cTfML3Lbqcub2tR8yEk dr3tyhkT74kuzGHJ2zUofpYCIGejzePD9V8EnIWEO+Tr1sZ7u8osxITqHjsKjWxK41DG a6ikp0TKRs/973bfH2c4mYNYjD/pAzWkeQMwtkQdPtavgbwJSyyDpDTSp6vSG90IE6wa iNkm2hPHAba2uwVOkMogJr4sTz6XA2gZ44KSvWw2rnMDyCDlG9JErIWFB1BHNKigowrl 3uyw6zKOeAWLeFHTJb9+mxflrXYs7XvBNem8bPlVVGwwbpBD6kH+2xozsZIPQvyYTxpO h9ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AVX5reAEHqnZSbEGBIMo8Lhd3+eWF1qq+60vX7BrME8=; b=EQ9/cQ4DkX04nzrLXeVWgGBhK42wOO5k3mlshKdX5TXpeRleBrXgJUyNfzZL727m7p ZGwPKTSbV2kYkML26DvehKuhHm0L3XpDiz/tmJ4K2nelJCuUSeXjssNwfW5iSK4XTpjC rv+H0CJrPHHj8MpPi/HzDtF+0AyYLD2hR/S+A5+hMhegungklA4ztOVvZzOp+29VB231 VlRs4C+w+Wkt/Thm47TX1kVHYfbwJl9uxLoiZr/9D8aXlzUj1aD8kHgG9fwxQeMLhgc1 vFZCN58MlK8faoGzdMcTl2+whOtjf1SOL1HP3NoDODR7ttm2t0PB14PZcEyNI2Cnt0LQ CzaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=B2xydfKZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n74si16310741pfi.288.2019.04.10.16.44.21; Wed, 10 Apr 2019 16:44:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=B2xydfKZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726870AbfDJXnk (ORCPT + 99 others); Wed, 10 Apr 2019 19:43:40 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:44890 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726813AbfDJXnh (ORCPT ); Wed, 10 Apr 2019 19:43:37 -0400 Received: by mail-ed1-f67.google.com with SMTP id d11so3526983edp.11 for ; Wed, 10 Apr 2019 16:43:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AVX5reAEHqnZSbEGBIMo8Lhd3+eWF1qq+60vX7BrME8=; b=B2xydfKZ+g574j63z5QKy/gb2oZGMBXu7aRhxEhkQGMP5EcvGPfhsZI+yHTHNr/CMV NMZKTVuWnh/QH4tjo8rIKcbh1M03ilvOLg+RpJ/lkyTzFmw4GnHKFRloMYyUjjOPp3eG 30r5Ud/2XSrgACQnHNvsCelcp55pvIl1YoPHD4YGw0xIQqNGmlt9NwFAJBMA8cx+yPLa Z0cCl8uroFiRx9+a0OKxWJLh8yTG1jEkx5+KqCmlEv0nKdYWX9F652eZ9vBkynlA2Bmo q2nRAm2IHMIfoeMNdzqNnlbkyIpycmoRCgxpgAsNI7jDzGjlDNCMxlU6V1Gqv9e/CoWk sG5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AVX5reAEHqnZSbEGBIMo8Lhd3+eWF1qq+60vX7BrME8=; b=hxxxCt8tBRBOgKbAAekk5BGnIHJAbuBs72mJt3jbaUoJKlLDcyNljkmptPFIB869O4 iAgoBfKQbGsk8rzr9XVrUbgCh5P9rGhUDSQLh6qMa5j9wfYSE9usitS9cK43KtmHdxNw zKTRGiAlIpLD8nFDLRrOVoBWhegaHO7iLgf/v+h6D8wHEk7TV6o1YF5kdPjxfmw81SQP ne5qWgC7bQ+EhqGutRmDC6QIK78VdTEh3YkinuBlDb0TP7XEb15L1+6jCq+OYD+PVGhk PaSfgWvWGuNuWS0dDTqAHii/27ADa0wScQRol1UPcY4PdDsEthLTQrPbso4Bas3+yJBX G1Ig== X-Gm-Message-State: APjAAAVwBx6mjPyhDhARVs4DhEAarPAZu5AiNxUIg++nNtC4mycx0HC3 f2Edoxkz8zRCfMqeq9IWmjzXkg== X-Received: by 2002:a17:906:3589:: with SMTP id o9mr8163512ejb.193.1554939815378; Wed, 10 Apr 2019 16:43:35 -0700 (PDT) Received: from localhost.localdomain ([212.91.227.56]) by smtp.gmail.com with ESMTPSA id f8sm4833015edt.36.2019.04.10.16.43.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Apr 2019 16:43:34 -0700 (PDT) From: Christian Brauner To: torvalds@linux-foundation.org, viro@zeniv.linux.org.uk, jannh@google.com, dhowells@redhat.com, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Cc: serge@hallyn.com, luto@kernel.org, arnd@arndb.de, ebiederm@xmission.com, keescook@chromium.org, adobriyan@gmail.com, tglx@linutronix.de, mtk.manpages@gmail.com, bl0pbl33p@gmail.com, ldv@altlinux.org, akpm@linux-foundation.org, oleg@redhat.com, cyphar@cyphar.com, joel@joelfernandes.org, dancol@google.com, Christian Brauner Subject: [RFC-2 PATCH 3/4] signal: support CLONE_PIDFD with pidfd_send_signal Date: Thu, 11 Apr 2019 01:40:44 +0200 Message-Id: <20190410234045.29846-5-christian@brauner.io> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190410234045.29846-1-christian@brauner.io> References: <20190410234045.29846-1-christian@brauner.io> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Jann Horn Cc: Arnd Bergmann Cc: "Eric W. Biederman" Cc: Kees Cook Cc: Alexey Dobriyan Cc: Thomas Gleixner Cc: David Howells Cc: "Michael Kerrisk (man-pages)" Cc: Jonathan Kowalski Cc: "Dmitry V. Levin" Cc: Andy Lutomirsky Cc: Andrew Morton Cc: Oleg Nesterov Cc: Aleksa Sarai Cc: Linus Torvalds Cc: Al Viro --- kernel/signal.c | 14 ++++++++++---- kernel/sys_ni.c | 3 --- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/kernel/signal.c b/kernel/signal.c index f98448cf2def..cd83cc376767 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3513,7 +3513,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 @@ -3550,6 +3549,14 @@ static int copy_siginfo_from_user_any(kernel_siginfo_t *kinfo, siginfo_t *info) return copy_siginfo_from_user(kinfo, info); } +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); +} + /** * sys_pidfd_send_signal - send a signal to a process through a task file * descriptor @@ -3581,12 +3588,12 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, if (flags) return -EINVAL; - f = fdget_raw(pidfd); + f = fdget(pidfd); if (!f.file) 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; @@ -3620,7 +3627,6 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig, fdput(f); return ret; } -#endif /* CONFIG_PROC_FS */ static int do_send_specific(pid_t tgid, pid_t pid, int sig, struct kernel_siginfo *info) diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index d21f4befaea4..4d9ae5ea6caf 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -167,9 +167,6 @@ COND_SYSCALL(syslog); /* kernel/sched/core.c */ -/* kernel/signal.c */ -COND_SYSCALL(pidfd_send_signal); - /* kernel/sys.c */ COND_SYSCALL(setregid); COND_SYSCALL(setgid); -- 2.21.0