Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3272319imu; Mon, 19 Nov 2018 13:19:48 -0800 (PST) X-Google-Smtp-Source: AJdET5fhSjo0YzmVqwqXIN3GS41TASSVPBAHce0Jc9q4WeFLcmF1S9+74x4oR9ywZnQWi9CORAp7 X-Received: by 2002:a63:c10f:: with SMTP id w15mr21376087pgf.199.1542662388449; Mon, 19 Nov 2018 13:19:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542662388; cv=none; d=google.com; s=arc-20160816; b=Z2tZkPQPHBTEYQwKWwF1sDX3YfnznZTJ7wBXXaZlUnUbQBy9mXUQgA/Bc5n84ZjJMR R7RW3y3B+yW895IJuHtO7NXxftqGVaJE7Lhd87Db4KdsX/hmhD5WkbumSoXvAw2VmgF3 6ezpxDBxbbgcOaapBMA2PbNbB3aVE/jTYmwRQYbpkW0bRzqyc45JtDo8+jW4GvISqCYN Jhk8OXT+kRq5JqYzyFCpPBGgOOuVf+NeVmq/jzCutCBgqrFPHTj07hvuWsd7toTDSGwg KgL4MxClCpFLeMUv7ltHcTqD4uTAxzp5NLbcxOdVPCfboYCwjyeiZcFlGJylOM2cy2kM QUmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=b+FpPg127MdhYuTO57snwkEW3R5iN+g7+Lb7I2iPPaE=; b=JqxuTZTd4mZVTBm2dKTDFt5Ofa/3HvYN0Cv5x7I+dqtSfupOVZSebhG3zlvc3rQwKb AgjY3s+hWbCZweHGxhw3oQE4fKpJTO04NUoyGBGJizVHU3FSKC48tkEJ2o7Q/fY8BbiN YHkmUod28KoJbq2cVd2JlIYTTNwesVoVi1+XNhrcyREOaogrTcFTkHD5U5xfyPE9DwBG Cda0qKIjQhpJZQ1fLNMXEusC0xo/C0Ha+C7jkQMnKb7Mcd12mIdjuVpAtPC3exgCP8+K yo1HEcX/mvA8v4Jl3EhDLWZ/ElcVbe7L12/tS4GA3qIpv9RA0TuNQpF+pQJO3w16xmQS JWzQ== 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 p26si19211427pfj.244.2018.11.19.13.19.33; Mon, 19 Nov 2018 13:19:48 -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 S1730938AbeKTHny (ORCPT + 99 others); Tue, 20 Nov 2018 02:43:54 -0500 Received: from mx1.mailbox.org ([80.241.60.212]:44170 "EHLO mx1.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730091AbeKTHny (ORCPT ); Tue, 20 Nov 2018 02:43:54 -0500 Received: from smtp1.mailbox.org (unknown [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id 49AFE49042; Mon, 19 Nov 2018 22:18:22 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id iGMooPN9IemA; Mon, 19 Nov 2018 22:18:20 +0100 (CET) Date: Tue, 20 Nov 2018 08:18:10 +1100 From: Aleksa Sarai To: Christian Brauner 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: <20181119211810.73ptfhnwdmkngfi4@yavin> References: <20181119103241.5229-1-christian@brauner.io> <20181119103241.5229-3-christian@brauner.io> <20181119202857.k5zw742xjfrw677j@yavin> <20181119205518.btew3vxwgva4w3zh@brauner.io> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="3flxpxlg56fx5hka" Content-Disposition: inline In-Reply-To: <20181119205518.btew3vxwgva4w3zh@brauner.io> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --3flxpxlg56fx5hka Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 =3D __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 =3D -EPERM; > > > + if ((kinfo.si_code >=3D 0 || kinfo.si_code =3D=3D SI_TKILL) && > > > + (task_pid(current) !=3D pid)) > > > + goto err; > > > + } else { > > > + prepare_kill_siginfo(sig, &kinfo); > > > + } > >=20 > > 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. > >=20 > > 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 >=20 > 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: >=20 > if (proc_pid_ns() !=3D 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 =3D=3D ancestor) break; ns =3D 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.) --=20 Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH --3flxpxlg56fx5hka Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEb6Gz4/mhjNy+aiz1Snvnv3Dem58FAlvzKI8ACgkQSnvnv3De m58HKA//U69plvx4rY3bXQRVMmJc5vua9IDIuPdxTt30IqjvD3P2SRxKVSrajOdt I9kmAZBjKlTQ9ILra2ZQZjIpEfEiWyrepEepPP/FjQMW0rZ3bxwV2owfZGBTWDOF CSaYzPxBsGNz/CQS61dagWOlMyjrc/xREyzXaLNSPBva3fr/857Zc8lDUxDQvwHo PuabCxC3vO/xadvW1Lbx5d/lRvbq6/b72TQweQxdhQRYFXuKJHMJwuhYe3ErRrY3 IQzEy9978cIqPduC/+reHUEhzcuNba0IZHGOr6sGG6wsZ/k4mcMbofvzY7qFWOul aTWEhZbdKWKzz/1hhq5ohLCV/GA/XvarkTWazTqf9bJEhGWE7tfcwFAVSxDleTO1 QREoc6yEbMGncyPaadQeP8s16ctbyuxrY/SzG1q7ms8eKx1jivqYt2e0VXxFzIwx ZQdcS8ynyJIjIoZ+2Cbm9mXEiJQiKU8Z7soTa+sMoFXhsmgjymFrQfZ6kQrwSPtM 3XGFp5RDD/oRc14cidvbGu9cEADmzc5P50hVGUQTn9WRK40vZoj5aDEg9RY6irWd pdRrtaTfLt46Hw3caLxI7ilCB/j5wJSl8CklvJza4A93FTIVlPzwEssKCnmRBQ8c L8Vdp/zEfdukRn1IWSR/ngsb+IvSiW2iJyRMo7gXp94U3QXiQ84= =zDQm -----END PGP SIGNATURE----- --3flxpxlg56fx5hka--