Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2898373imu; Mon, 19 Nov 2018 07:46:46 -0800 (PST) X-Google-Smtp-Source: AJdET5euA6f4NOu0v2od6fctZqv0rz3Z2xTl/Mq+w4cc9dYE1m7l0QgSdm/t54lNcd98+nyiliQu X-Received: by 2002:a17:902:15a8:: with SMTP id m37-v6mr22848408pla.256.1542642406008; Mon, 19 Nov 2018 07:46:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542642405; cv=none; d=google.com; s=arc-20160816; b=Jt+g8TYeFAIHSMoNWNhYqMJaxJh0G9fSKF2aPRBDPqAWJK2of1LMSgoUbyjzDl8/FF CBuIUAOfYSjxsBiFC2X3p4Fb1+D6ONTtI2vMFYo1Cj/ssVmqlskD65+ByOzn1sEboem+ 7iVanJLvddjxYQyhWJAdPHZ3vzC/giuiwnqTCJiBGcHkFnWogkPLJPu7a1DmjHJJzmvx WuiTDoXxuIOr9/RSZAZB4MnEjEcPvWGgHSKFZQ0vGELKi4uOCHinMxQ/O8G8bgns5wB7 iRUul8ROmZ3zGDMdSjXD0VObmN2/d3rhNZ+u6QBGIeKPYKEz8kCwsI0R66Y57mZ9wwVf j0OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=jHVybUQ9M6gJ12vHD55v8+xqCNDNfGWTqEHtpBlXQQw=; b=VA9KIMoXxdJ70Sv8s8yOAM6PEAyMJ62ssZRP2JGF/x33xhi1ZPH40sU4BNZDYsLfcl qZfSO7x0pagsHerUBp0WXOMdg05pIDGtg2041zGsdv97OWgFbxrT7/ohKtvyrfspB4YB tu15S9ach3LMmkAlZf4XdfJSsFr2wSUUS6pxc+OO5cm/GEb8RCyG565wt7JLMbQ3MwRt g30fXhwY2LgbjT7/+cMHA6xPPKH4TSvkIQnkP4iuhGz7QJ2uMsVUX40h496Y/LNs+LhN 3CcxVSlbIgibG48jo+cWi2Gdo49wUIRXtsjCiAe0N98Ec2qFIFGXtB1K6Fyzxn5bcHaz 5PSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vZ+ZWZ7S; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 126si7452226pff.77.2018.11.19.07.46.30; Mon, 19 Nov 2018 07:46:45 -0800 (PST) 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=@kernel.org header.s=default header.b=vZ+ZWZ7S; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729880AbeKTCJR (ORCPT + 99 others); Mon, 19 Nov 2018 21:09:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:33820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729669AbeKTCJR (ORCPT ); Mon, 19 Nov 2018 21:09:17 -0500 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A56D02086A for ; Mon, 19 Nov 2018 15:45:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542642318; bh=Tcw/Wo+m3ueEd6NFGRGwrQwdl9NMGltANmuS+G5q8ak=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=vZ+ZWZ7SLRauoYx7RIv9A6G+lE60jWXTVX1zPgT/vJcinyvVoSUGPnJl20qMR5Vps IPrn0oQK4dieRYQYkwjF1sD1peH+TDOJ5d8DHQEnq/jqMN6VGalZNdOTW/eQCZv3PY lbu9FpF9E7CGYi2EXNnIzcnFmUiM7y930Ruvo2B4= Received: by mail-wm1-f43.google.com with SMTP id 125so3805447wmh.0 for ; Mon, 19 Nov 2018 07:45:18 -0800 (PST) X-Gm-Message-State: AA+aEWbCz9k/K997Rh4xcVge1/8wUXM8/GwMu7uIr4TYi8Q86niyb+N6 bPM1ToAODVzB58d8hZBZMKUayBmCpe7O6yMoUv5Byg== X-Received: by 2002:a1c:110b:: with SMTP id 11mr4827999wmr.83.1542642317128; Mon, 19 Nov 2018 07:45:17 -0800 (PST) MIME-Version: 1.0 References: <20181119103241.5229-1-christian@brauner.io> <20181119103241.5229-3-christian@brauner.io> In-Reply-To: <20181119103241.5229-3-christian@brauner.io> From: Andy Lutomirski Date: Mon, 19 Nov 2018 07:45:04 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v1 2/2] signal: add procfd_signal() syscall To: Christian Brauner Cc: "Eric W. Biederman" , LKML , "Serge E. Hallyn" , Jann Horn , Andrew Lutomirski , Andrew Morton , Oleg Nesterov , Aleksa Sarai , Al Viro , Linux FS Devel , Linux API , Daniel Colascione , Tim Murray , linux-man , Kees Cook Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 19, 2018 at 2:33 AM Christian Brauner wrote: > > The kill() syscall operates on process identifiers. After a process has > exited its pid can be reused by another process. If a caller sends a signal > to a reused pid it will end up signaling the wrong process. This issue has > often surfaced and there has been a push [1] to address this problem. > > A prior patch has introduced the ability to get a file descriptor > referencing struct pid by opening /proc/. This guarantees a stable > handle on a process which can be used to send signals to the referenced > process. Discussion has shown that a dedicated syscall is preferable over > ioctl()s. Thus, the new syscall procfd_signal() is introduced to solve > this problem. It operates on a process file descriptor. > The syscall takes an additional siginfo_t and flags argument. If siginfo_t > is NULL then procfd_signal() behaves like kill() if it is not NULL it > behaves like rt_sigqueueinfo. > The flags argument is added to allow for future extensions of this syscall. > It currently needs to be passed as 0. A few questions. First: you've made this work on /proc/PID, but should it also work on /proc/PID/task/TID to send signals to a specific thread? > +bool proc_is_procfd(const struct file *file) > +{ > + return d_is_dir(file->f_path.dentry) && > + (file->f_op == &proc_tgid_base_operations); > +} Maybe rename to proc_is_tgid_procfd() to leave room for proc_is_tid_procfd()? > + if (info) { > + ret = __copy_siginfo_from_user(sig, &kinfo, info); > + if (unlikely(ret)) > + goto err; > + /* > + * Not even root can pretend to send signals from the kernel. > + * Nor can they impersonate a kill()/tgkill(), which adds > + * source info. > + */ > + ret = -EPERM; > + if ((kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL) && > + (task_pid(current) != pid)) > + goto err; Is the exception for signaling yourself actually useful here?