Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1367224imu; Thu, 22 Nov 2018 15:07:46 -0800 (PST) X-Google-Smtp-Source: AJdET5dfDd351HDE0yvOuvx+zIFDUrYTy5zLzqszDpWQMN1FiVkTgVLLACSRUuFMs6QmsmwHOltk X-Received: by 2002:a62:6085:: with SMTP id u127-v6mr13982440pfb.147.1542928066721; Thu, 22 Nov 2018 15:07:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542928066; cv=none; d=google.com; s=arc-20160816; b=hxuZbtrYM2wK9cKlq5LeB9rMsd9G7488eihl5fBibuurGjuW0FuNDYiCY/oPQzACrw zGBAzv5yucKAOwMmjjYqQYSgG9EYMQMWqhNDh2MRuCVB3tD7xQXRntTqTkcA235tMR/D erR+Lp7DMhmIdywpvT+jIET4EGVezWrgzDx8kBOXiHFxhNQVIlBZ5zbroraYxrkbve70 fIiIQwCcmuJIq1ygjoOWjS7yj/mZLRBC4fOAsXGwwrjxTODz8ihMyQlhJ32eFKisTxr1 JxwsLj+XOlwNA6oMwI164LOgyC54jl4xrWh/unAMNe4t6yc2aP8RUdk3EzGhQG5qtTY3 RXDw== 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; bh=/qGMUiEMFDW3f7dw4iRXmRPfWqUKhvJqtWUsp4m9/Kg=; b=Vk2nU+Tb9VGtvih6uPPiPXGMICM0iXe89ruOjEcxft/CWgaBJpXR8Lw/dgDrD+bueU UfKyMkQhX1N20ykWFAjVHw2mHep6Pxatx3QGRxUSy9N4AAmgRFm2Fac79RrVZW4PTRhO rDPCFKgjZxgxVdDszDc6i29z7EvN13aUNi/xhMsLbWxqTyA0KFUH4eSUKRKh8aik/BlE E8CQgWBvhmJc7eZuL37UvhCGEhsSnt4XAVWwKKXR+hevVHO7DCLzCJhDQ88lzLKKy+gi JnHaG3LhgnOTPU1TJLCATjOa+fBSwVdp80ZBzeIeyrwU16p/yjxwKOvgDPIhStOo3+LR 4Fgg== ARC-Authentication-Results: i=1; mx.google.com; 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 n185-v6si53225035pfn.83.2018.11.22.15.07.31; Thu, 22 Nov 2018 15:07:46 -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; 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 S2392621AbeKVSTa (ORCPT + 99 others); Thu, 22 Nov 2018 13:19:30 -0500 Received: from mail.hallyn.com ([178.63.66.53]:57082 "EHLO mail.hallyn.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726200AbeKVSTa (ORCPT ); Thu, 22 Nov 2018 13:19:30 -0500 Received: by mail.hallyn.com (Postfix, from userid 1001) id C570F74E; Thu, 22 Nov 2018 01:41:14 -0600 (CST) Date: Thu, 22 Nov 2018 01:41:14 -0600 From: "Serge E. Hallyn" To: Aleksa Sarai Cc: Christian Brauner , ebiederm@xmission.com, linux-kernel@vger.kernel.org, serge@hallyn.com, jannh@google.com, luto@kernel.org, akpm@linux-foundation.org, oleg@redhat.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, dancol@google.com, timmurray@google.com, linux-man@vger.kernel.org, Kees Cook Subject: Re: [PATCH v1 2/2] signal: add procfd_signal() syscall Message-ID: <20181122074114.GA15484@mail.hallyn.com> References: <20181119103241.5229-1-christian@brauner.io> <20181119103241.5229-3-christian@brauner.io> <20181119202857.k5zw742xjfrw677j@yavin> <20181119205518.btew3vxwgva4w3zh@brauner.io> <20181119211810.73ptfhnwdmkngfi4@yavin> <20181119212343.yikfoxob7f4hio7h@yavin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181119212343.yikfoxob7f4hio7h@yavin> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 20, 2018 at 08:23:43AM +1100, Aleksa Sarai wrote: > On 2018-11-20, Aleksa Sarai wrote: > > On 2018-11-19, Christian Brauner wrote: > > > On Tue, Nov 20, 2018 at 07:28:57AM +1100, Aleksa Sarai wrote: > > > > On 2018-11-19, Christian Brauner wrote: > > > > > + 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; > > > > > + } else { > > > > > + prepare_kill_siginfo(sig, &kinfo); > > > > > + } > > > > > > > > I wonder whether we should also have a pidns restriction here, since > > > > currently it isn't possible for a container process using a pidns to > > > > signal processes outside its pidns. AFAICS, this isn't done through an > > > > explicit check -- it's a side-effect of processes in a pidns not being > > > > able to address non-descendant-pidns processes. > > > > > > > > But maybe it's reasonable to allow sending a procfd to a different pidns > > > > and the same operations working on it? If we extend the procfd API to > > > > > > No, I don't think so. I really don't want any fancy semantics in here. > > > Fancy doesn't get merged and fancy is hard to maintain. So we should do > > > something like: > > > > > > if (proc_pid_ns() != current_pid_ns) > > > return EINVAL > > > > This isn't quite sufficient. The key thing is that you have to be in an > > *ancestor* (or same) pidns, not the *same* pidns. Ideally you can re-use > > the check already in pidns_get_parent, and expose it. It would be > > something as trivial as: > > > > bool pidns_is_descendant(struct pid_namespace *ns, > > struct pid_namespace *ancestor) > > { > > for (;;) { > > if (!ns) > > return false; > > if (ns == ancestor) > > break; > > ns = ns->parent; > > } > > return true; > > } > > > > And you can rewrite pidns_get_parent to use it. So you would instead be > > doing: > > > > if (pidns_is_descendant(proc_pid_ns, task_active_pid_ns(current))) > > return -EPERM; > > Scratch the last bit, -EPERM is wrong here. I would argue that -EINVAL > is *somewhat* wrong because arguable the more semantically consistent > error (with kill(2)) would be -ESRCH -- but then you're mixing the "pid > is dead" and "pid is not visible to you" cases. I'm not sure what the > right errno would be here (I'm sure some of the LKML greybeards will > have a better clue.) :P Actually I like EXDEV for this. ERMOTE also works.