Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp381978ybx; Wed, 6 Nov 2019 02:09:07 -0800 (PST) X-Google-Smtp-Source: APXvYqzDc9oBX3fliNZhhJqyyq7/TFY7uQDzOMzijfph9npTtSp26b7Ysuxr1eI/PO/dM/rA3tJS X-Received: by 2002:a17:906:1249:: with SMTP id u9mr119656eja.253.1573034947412; Wed, 06 Nov 2019 02:09:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573034947; cv=none; d=google.com; s=arc-20160816; b=azcZf/2qqdqDg7MBHBx8TmLuPnIN2Hs7jfPu94ZBpEKXXGfAKtzanvaTZ1bliq11mM XJIaDyi8Tim3D7hosZI0qjREdJiCaYBRwpvGuhxITHUjj7pneznjzHXEbLH5MN2CbABi fN9SOt+m7aJPY3iqJ8+q9/X14lPqwx+ZAbcLE+TxtrqW90dyzwY8v2srzVKIptSRqs/e 4JVH2bEQrAHfywVOus8lve8lk0WmQyqRlyb0Hf0yqlWfFaruzl70lamhbTMlCQmTgmEg Av2PmHaBpb9u9M5Ly73GxoAUdx0G2Ujsk67aGzGLbG8oie4S4tnplQgIf9P6vQCTqFvQ V9Hw== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=X05zBYkPaLX+0zINsXEFrTIGhG2lc88Xq9e+QvToQFs=; b=u+k2rac3WwWTZ6VipcIrSUmCtIey/DQPVvGnmUcqKkAMqW/xiGb9s6PnUismEiX3ku CdO8SVI8XAx4fuPmszE+zahPDqpBXZu3REhdkuejoi0X6YbqPQ8/n1Jeia1WUur39APD I0MW6N6jQ/zmLnCwjbnmLsZRPYM9jAN2UAleDATkMqYlOrS9TrIuBw7z7w6SEbxMksWZ V+dmpsz2zXjMiY5WKcUABmElqoQbjs5DetqoMG4ydw5hzDIOuHbWlgmz2kzuyZvhYTk1 +K9faBDtr/ygGK45mMRgEFJ4AijBVODY1M4Cbf8kqr2FibT+7e1VHqBCcftU/IdBHau1 WB3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OEt1lNHN; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l3si14781171ejc.213.2019.11.06.02.08.37; Wed, 06 Nov 2019 02:09:07 -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=@chromium.org header.s=google header.b=OEt1lNHN; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731096AbfKFKHU (ORCPT + 99 others); Wed, 6 Nov 2019 05:07:20 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34164 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729280AbfKFKHS (ORCPT ); Wed, 6 Nov 2019 05:07:18 -0500 Received: by mail-pg1-f195.google.com with SMTP id e4so16819878pgs.1 for ; Wed, 06 Nov 2019 02:07:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=X05zBYkPaLX+0zINsXEFrTIGhG2lc88Xq9e+QvToQFs=; b=OEt1lNHNq2Y25+Ru30BQlIgL1EGLF4SVCDHXPTBUUEH8XXrzP4rFCGQIIeA4HEfSu9 RWld6zC55fYxRNKD4idGhvwNxieHUE/RWLmQcF3jnD/Tx3jT04Q52E9fs2zOYKPzkA9g abeKK24Z/udzmQEdJYQ6ClRdjgr/ngNM2VwBg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=X05zBYkPaLX+0zINsXEFrTIGhG2lc88Xq9e+QvToQFs=; b=Rv78rFJQvEiBdjwPSiqU1tm/Kujhg+24JQo2He/+DF3WOm9P8xQsVEhzLjjkYkGEln 2H8/Cx6kBuxj9TZC83Bcqsl65+/7o8pxGQoSbo+ZAcxCP+wVDh7aa7iBQWjPhaYy3M9S NkcoJ/3XA5MmNEzom3f8IXkJqBAQ3PSD4GYz4fuFLuX2ajIzbUbQ9slXHEJbnFlFSf7h K2DvR9wA6Me3Hx0UvOYi15xD02OKMUVU7L1VdofO93df+lmA20Uk6XwbxzulCoye15Eu 3vo29x8FiPcxehbyRr8utoLC71VwIjtAvDTi0RN25F9zgtR1efNJ6pUVkVKp7cxFolUF Cedg== X-Gm-Message-State: APjAAAWd/tUG7vt8moXer+NashBHezBprdkDcIW4grNVsLV6mFJGsB68 +qWsruRtzUImAZOCWkYArnh+cQ== X-Received: by 2002:a63:5d04:: with SMTP id r4mr1924765pgb.22.1573034836267; Wed, 06 Nov 2019 02:07:16 -0800 (PST) Received: from chromium.org ([122.173.128.252]) by smtp.gmail.com with ESMTPSA id k9sm22977594pfk.72.2019.11.06.02.07.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2019 02:07:15 -0800 (PST) From: KP Singh X-Google-Original-From: KP Singh Date: Wed, 6 Nov 2019 15:36:55 +0530 To: Alexei Starovoitov Cc: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , linux-kernel@vger.kernel.org, Alexei Starovoitov , Andy Lutomirski , Casey Schaufler , Daniel Borkmann , David Drysdale , Florent Revest , James Morris , Jann Horn , John Johansen , Jonathan Corbet , Kees Cook , Michael Kerrisk , =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Paul Moore , Sargun Dhillon , "Serge E . Hallyn" , Shuah Khan , Stephen Smalley , Tejun Heo , Tetsuo Handa , Tycho Andersen , Will Drewry , bpf@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-security-module@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH bpf-next v13 4/7] landlock: Add ptrace LSM hooks Message-ID: <20191106100655.GA18815@chromium.org> References: <20191104172146.30797-1-mic@digikod.net> <20191104172146.30797-5-mic@digikod.net> <20191105171824.dfve44gjiftpnvy7@ast-mbp.dhcp.thefacebook.com> <23acf523-dbc4-855b-ca49-2bbfa5e7117e@digikod.net> <20191105193446.s4pswwwhrmgk6hcx@ast-mbp.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20191105193446.s4pswwwhrmgk6hcx@ast-mbp.dhcp.thefacebook.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05-Nov 11:34, Alexei Starovoitov wrote: > On Tue, Nov 05, 2019 at 07:01:41PM +0100, Micka?l Sala?n wrote: > > > > On 05/11/2019 18:18, Alexei Starovoitov wrote: > > > On Mon, Nov 04, 2019 at 06:21:43PM +0100, Micka?l Sala?n wrote: > > >> Add a first Landlock hook that can be used to enforce a security policy > > >> or to audit some process activities. For a sandboxing use-case, it is > > >> needed to inform the kernel if a task can legitimately debug another. > > >> ptrace(2) can also be used by an attacker to impersonate another task > > >> and remain undetected while performing malicious activities. > > >> > > >> Using ptrace(2) and related features on a target process can lead to a > > >> privilege escalation. A sandboxed task must then be able to tell the > > >> kernel if another task is more privileged, via ptrace_may_access(). > > >> > > >> Signed-off-by: Micka?l Sala?n > > > ... > > >> +static int check_ptrace(struct landlock_domain *domain, > > >> + struct task_struct *tracer, struct task_struct *tracee) > > >> +{ > > >> + struct landlock_hook_ctx_ptrace ctx_ptrace = { > > >> + .prog_ctx = { > > >> + .tracer = (uintptr_t)tracer, > > >> + .tracee = (uintptr_t)tracee, > > >> + }, > > >> + }; > > > > > > So you're passing two kernel pointers obfuscated as u64 into bpf program > > > yet claiming that the end goal is to make landlock unprivileged?! > > > The most basic security hole in the tool that is aiming to provide security. > > > > How could you used these pointers without dedicated BPF helpers? This > > context items are typed as PTR_TO_TASK and can't be used without a > > dedicated helper able to deal with ARG_PTR_TO_TASK. Moreover, pointer > > arithmetic is explicitly forbidden (and I added tests for that). Did I > > miss something? > > It's a pointer leak. > > > > > > > > > I think the only way bpf-based LSM can land is both landlock and KRSI > > > developers work together on a design that solves all use cases. > > > > As I said in a previous cover letter [1], that would be great. I think > > that the current Landlock bases (almost everything from this series > > except the seccomp interface) should meet both needs, but I would like > > to have the point of view of the KRSI developers. > > > > [1] https://lore.kernel.org/lkml/20191029171505.6650-1-mic@digikod.net/ > > > > > BPF is capable > > > to be a superset of all existing LSMs whereas landlock and KRSI propsals today > > > are custom solutions to specific security concerns. BPF subsystem was extended > > > with custom things in the past. In networking we have lwt, skb, tc, xdp, sk > > > program types with a lot of overlapping functionality. We couldn't figure out > > > how to generalize them into single 'networking' program. Now we can and we > > > should. Accepting two partially overlapping bpf-based LSMs would be repeating > > > the same mistake again. > > > > I'll let the LSM maintainers comment on whether BPF could be a superset > > of all LSM, but given the complexity of an access-control system, I have > > some doubts though. Anyway, we need to start somewhere and then iterate. > > This patch series is a first step. > > I would like KRSI folks to speak up. So far I don't see any sharing happening > between landlock and KRSI. You're claiming this set is a first step. They're > claiming the same about their patches. I'd like to set a patchset that was > jointly developed. We are willing to collaborate with the Landlock developers and come up with a common approach that would work for Landlock and KRSI. I want to mention that this collaboration and the current Landlock approach of using an eBPF based LSM for unprivileged sandboxing only makes sense if unprivileged usage of eBPF is going to be ever allowed. Purely from a technical standpoint, both the current designs for Landlock and KRSI target separate use cases and it would not be possible to build "one on top of the other". We've tried to identify the lowest denominator ("eBPF+LSM") requirements for both Landlock (unprivileged sandboxing / Discretionary Access Control) and KRSI (flexibility and unification of privileged MAC and Audit) and prototyped an implementation based on the newly added / upcoming features in BPF. We've been successfully able to prototype the use cases for KRSI (privileged MAC and Audit) using this "eBPF+LSM" and shared our approach at the Linux Security Summit [1]: * Use the new in-kernel BTF (CO-RE eBPF programs) [2] and the ability of the BPF verifier to use the BTF information for access validation to provide a more generic way to attach to the various LSM hooks. This potentially saves a lot of redundant work: - Creation of new program types. - Multiple types of contexts (or a single context with Unions). - Changes to the verifier and creation of new BPF argument types (eg. PTR_TO_TASK) * These new BPF features also alleviate the original concerns that we raised when initially proposing KRSI and designing for precise BPF helpers. We have some patches coming up which incorporate these new changes and will be sharing something on the mailing list after some cleanup. We can use the common "eBPF+LSM" for both privileged MAC and Audit and unprivileged sandboxing i.e. Discretionary Access Control. Here's what it could look like: * Common infrastructure allows attachment to all hooks which works well for privileged MAC and Audit. This could be extended to provide another attachment type for unprivileged DAC, which can restrict the hooks that can be attached to, and also the information that is exposed to the eBPF programs which is something that Landlock could build. * This attachment could use the proposed landlock domains and attach to the task_struct providing the discretionary access control semantics. [1] https://static.sched.com/hosted_files/lsseu2019/a2/Kernel%20Runtime%20Security%20Instrumentation.pdf [2] http://vger.kernel.org/bpfconf2019_talks/bpf-core.pdf - KP Singh >