Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3117916imu; Mon, 19 Nov 2018 10:53:50 -0800 (PST) X-Google-Smtp-Source: AFSGD/XOTHu9QBb3NmflRBHW6MRWCZsvtePx2Hr8S2Z0T7aYaJ+1MpPsrGhYkQpL01NuyE5SqFl8 X-Received: by 2002:a63:d450:: with SMTP id i16mr1276112pgj.246.1542653630153; Mon, 19 Nov 2018 10:53:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542653630; cv=none; d=google.com; s=arc-20160816; b=X682MOu274A2LTN3glUTmOI/O8xxzbbYDIWyraVeTn2WVmODdtGYcwAyFGDng4vdev ElE7WTWyxhZV+GnCuB3wKfBjX/OrhUgDdVXrl7mZO37BcHwjfjAxJ+hXt1ruxXNGkcMQ CE+aabCrumWr9OExIxeo6PGgAuqLPLCeBc03gsJiNepRhakP8KiZM4mtr8+3bxNx/pWi bor5YckBwRxe3Qg4Ivitc0YLhmznMAf0TdpKdSB2ofG957nC5yW/CMM/IzSEDUYeo5ND ZYETUQ02FxjNFdFXUTxuSWBCpDqoCXbHAfuphnbq8nVurr3/ZJGfop15mukvLvIPWKFO pnvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=HKIWS2FQiKNrZ3s55kmI7ISTRafazkCOx7CAN32DNq0=; b=furL5tsNItHjzCoYODUdIlOP20GJZQ8kMcWjnyhHAoriiJcDVDj6ke2sVwMEerfIMF wFJQ6PYO3O01X/qOYIPg/Aiku7mfEiI01+b2uV4mvYOTgQv4HSfHVjCdVce8bZ36IwaF r7b6tAFGwqU6Xt7HjF/IyCH49sdyIjTfkImn5SaD3T0kzhLmqpvuUMLxGZou0xwQPBO0 zU4eA2w36osHUOKdu3XO+1GBaTC2Wi+ZD/qUDZ5plDz9jDjGvKlr8arkMergq9Ek5Q9S kuuC6oHETVjlrVqmiTMTCD1IbmjMmQtMphob8Qu+dPdQ33Aa3qqys2AK5oIqdwNxd1Vc Wf0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=SnWZZLMn; 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 q61-v6si40815749plb.418.2018.11.19.10.53.34; Mon, 19 Nov 2018 10:53:50 -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=@brauner.io header.s=google header.b=SnWZZLMn; 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 S1726250AbeKTFEc (ORCPT + 99 others); Tue, 20 Nov 2018 00:04:32 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:37213 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726042AbeKTFEc (ORCPT ); Tue, 20 Nov 2018 00:04:32 -0500 Received: by mail-pg1-f196.google.com with SMTP id 80so14206218pge.4 for ; Mon, 19 Nov 2018 10:39:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HKIWS2FQiKNrZ3s55kmI7ISTRafazkCOx7CAN32DNq0=; b=SnWZZLMnSkw2PT4vVbfnrHOsuOdERX6WcUXgM4quQKWuVdHN6m0ERuVDkb80g7Pp8/ PN1p8N8eVmYOhwW+kV1Q5hIMMEBlisY7CR3Px6N7YrZL0Z03djLSI0086sFZuoGYzeQw UFOYPdhzrWg4pdoId3JmzcsTa49roAEaZ6o3T6CRxYRwRXSf2bUjiRaTWIzERZhDuury CxzGN3PF1E6P9tsobRYiOEMjZnBQ9S5EEKzLP6oYMAoEgK57dQWVbZcaObx5iOPqcxvJ hWvlaV1tFalkSE/2DWGno3xnYkMKno26yZmG4CM6JmkcG4yif3dySmuJJgNpGbhW2gNF HDOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HKIWS2FQiKNrZ3s55kmI7ISTRafazkCOx7CAN32DNq0=; b=KcG95BEqo1cYpfyCGlR7pmrhHdT4Jo4JdvL/IcaJeYAHrrb7heMOYVseRvD+TuQTgf YAFL9ByZQELc7hhhTIht6DZzqarFIyfDXcGjbFEOOknQKztlwR1nMt+/YMqwLiE5GBh6 px4ptGICoC1uQ2Z52bSMl4bA4g8eQrHRnh8Bc9LRBr/tE1bnUKWYZqmci8zS8KaZ5PsN +Uj0p8248Gp6EqZUTb4b5rfSUav7FLPm6nQabkJR2U2dYUT3AYyPLT/R9XQt0l0TlGOl ML3mBKijted5efKxDRhibrBoN2PYshuAT6695J8pYHb1863l7LfRKIKlHHHi5RHP2DOC cGbw== X-Gm-Message-State: AGRZ1gK1+AMcAbtj04Y8BrfSsC8bMfjLI+eELghH9x6BrJqHb78UVOjK 2ue7AGwQ0Mh0yC/LZol7Z7Mk0g== X-Received: by 2002:a63:4246:: with SMTP id p67mr20902626pga.335.1542652785254; Mon, 19 Nov 2018 10:39:45 -0800 (PST) Received: from brauner.io ([2404:4404:133a:4500:9d11:de0b:446c:8485]) by smtp.gmail.com with ESMTPSA id m3sm66133111pgl.69.2018.11.19.10.39.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Nov 2018 10:39:44 -0800 (PST) Date: Mon, 19 Nov 2018 19:39:36 +0100 From: Christian Brauner To: Andy Lutomirski Cc: "Eric W. Biederman" , LKML , "Serge E. Hallyn" , Jann Horn , Andrew Morton , Oleg Nesterov , Aleksa Sarai , Al Viro , Linux FS Devel , Linux API , Daniel Colascione , Tim Murray , linux-man , Kees Cook Subject: Re: [PATCH v1 2/2] signal: add procfd_signal() syscall Message-ID: <20181119183931.tkz7hfruw2ekqh62@brauner.io> References: <20181119103241.5229-1-christian@brauner.io> <20181119103241.5229-3-christian@brauner.io> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 07:45:04AM -0800, Andy Lutomirski wrote: > 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? Yeah, so I thought about that. Your point being to combine: kill(), tgkill() aka rt_sigqueueinfo() and rt_tg_sigqueueinfo(). If I understand this correctly the implication is to also get file descriptors to /proc/PID/task/TID and pass them to procfd_signal()? Can we hold of on that one? Adding this in the future should be easily doable by simply getting /proc/PID/task/TID file descriptors but I would like this patchset to be as small as possible. > > > +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()? Yes, good idea! > > > + 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? I tried to strictly follow the sigqueue-based permission checks. I'm not comfortable removing this check without signal-experts telling me that it is safe to do.