Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3274050imu; Mon, 19 Nov 2018 13:21:45 -0800 (PST) X-Google-Smtp-Source: AJdET5cgBOCwaI1Eu7XejJPkgQFxI5RL+dJthXq4aKd0dbbgBmz5iqlYV4XGoHuJCW2YdwEKYW2H X-Received: by 2002:a17:902:6b87:: with SMTP id p7-v6mr24360950plk.282.1542662505301; Mon, 19 Nov 2018 13:21:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542662505; cv=none; d=google.com; s=arc-20160816; b=X2SFwHeXewvcN9865PvLwagrhzs3jA8L3UtjgzVdv5LtIM1VXz5rN1u4JmdIA9Yg8B vtAGI/Hd+yV34RmIoaYqIwUbgR1ZCA7vdLQ+6YzDdFp29jDhz8FXvcYPtB8lyn+d8IuU /KJ3WN59hjx9t25Ei29myqdUxAJvpcVb0pV0WYROT1+GLsqMod53P6Q+rJ0TQgKzhuau 5YKN74bp+Vy1yJC/mXGxT5WVvSyPBO53E/xzQMQ5EHsT+8FQNwEIa46vnpUvjQSnKmVB /Vczv9MSpQq4/IjIRs10hT7WojTizULd24eTjTrvhpX0e7L/e3FCcji4Fb9O6zXA6jAn 07cA== 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=Jt+Pnm3pFpw6REz21HA5THfjrEnVfEm5dqNKjiLRLzI=; b=jFNn14UY4YBkjqze0yLnRcPYabwYvRZeFyFyAS9OHHXd71oAfNFtMY34vwDzDR4W/4 Vt9STSquDlh1X/i4dYII0RPTVtkPvBqwbgRe7dDabgJCAfs4Z3xytu22wVIJHVzYy/Ni s/L2vGw6qkmzVuXYXE0S/Okph3LNZeFdrDvFoMC4RxgHwO6y/7g+UBuD83EHo+tQXbtp UzK79B53Us/ZlmTMYwwK33YBGM9fbDNUifyndyYaZDqqDYm55Xo+me0mOx6hupYSnP8k PxiDa/Fwa/kVB3Th5Gz5HZHx7PzpeeZPwgDYsPrLeXbwIrGnLGQXdwb9berbxHdxdYHU cuFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=O9vpF7wD; 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 o3si38887167pgi.388.2018.11.19.13.21.30; Mon, 19 Nov 2018 13:21: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=@brauner.io header.s=google header.b=O9vpF7wD; 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 S1731030AbeKTHqJ (ORCPT + 99 others); Tue, 20 Nov 2018 02:46:09 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:46715 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730798AbeKTHqJ (ORCPT ); Tue, 20 Nov 2018 02:46:09 -0500 Received: by mail-pl1-f193.google.com with SMTP id t13so12196037ply.13 for ; Mon, 19 Nov 2018 13:20:39 -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=Jt+Pnm3pFpw6REz21HA5THfjrEnVfEm5dqNKjiLRLzI=; b=O9vpF7wDjafpSx0sIoHKJGo3/jxsHGLCTyDDqDKVmWH5RXH3AUiocT3H0JUdzBOjkY AO5/SuhGxlo0aBZ5FQSABltd4DPReTUHrTXdSS8X9LWRWqMrz6lOKe2t2jwJFkabRIgZ JrHwhsxRYeoAAHdgX81hkhdkJVVr6kxQKUWL1Ebit5vXq6hlA+Be4zdxu00lpzCEmRbx IGNUhFSFXDrpsY7jB1xVh6Uqedetn1ZhUmDYazg7FbwVPPKw6ShkY5xTg/8UWDgiSdIL 2f5S68sTyJg2/f2Muax3TMZACB0VjxwlzTkAOvDQXpJfApvd48AQQP760i8ExvpdFzHP N5Pg== 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=Jt+Pnm3pFpw6REz21HA5THfjrEnVfEm5dqNKjiLRLzI=; b=kz+qjSoirVtgGcFQGrHvGuc5L47k0R2kGRLNfObxmYQ6Ldw5mvsaL3rgr8UgoFvEPy BpKAU+jxSrRarPzPmyen2bel0rJNKAwaekc4xClGjsZXZEPa9LpJzlNzt8kOFfOJ5Mqw YABgAyL2MnU0imGmbkpG9QcA/WLdZXpt5sQwKJlYm+opTlHYZ8okyqIbxSjKyVikD+bq +2rX+7SvSEh2XTJQvT+QYCxFNk2F/OPCXifRaCtYHv7N4AaOuzBApm1nRQJlald3DLfS m9G6i/vV8O7FVY6ys54B42r5n3fn/2xOtIViXyOXjtEoLB31A0RoAGNj0uIa7ri1WTMO 9wiQ== X-Gm-Message-State: AGRZ1gIdfFpj5kMgpTtafOuxeKT27o0HK/CtEum2mCp8RDZOdUz+M5oe fUB2oSYI/hcc5gp46AU0ecVQKw== X-Received: by 2002:a17:902:a988:: with SMTP id bh8-v6mr24128933plb.163.1542662438811; Mon, 19 Nov 2018 13:20:38 -0800 (PST) Received: from brauner.io ([2404:4404:133a:4500:9d11:de0b:446c:8485]) by smtp.gmail.com with ESMTPSA id s144sm40736816pgs.87.2018.11.19.13.20.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Nov 2018 13:20:38 -0800 (PST) Date: Mon, 19 Nov 2018 22:20:29 +0100 From: Christian Brauner To: Aleksa Sarai Cc: 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: <20181119212027.vtkp7r7srf5ocnr4@brauner.io> References: <20181119103241.5229-1-christian@brauner.io> <20181119103241.5229-3-christian@brauner.io> <20181119202857.k5zw742xjfrw677j@yavin> <20181119205518.btew3vxwgva4w3zh@brauner.io> <20181119211810.73ptfhnwdmkngfi4@yavin> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20181119211810.73ptfhnwdmkngfi4@yavin> User-Agent: NeoMutt/20180716 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:18:10AM +1100, 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 See my next mail. > 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; > > (Or you can just copy the 5-line loop into procfd_signal -- though I > imagine we'll need this for all of the procfd_* APIs.) > > -- > Aleksa Sarai > Senior Software Engineer (Containers) > SUSE Linux GmbH >