Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2784775ybb; Fri, 27 Mar 2020 12:01:11 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuQo1jOTl891CMWHz12Uq71bPSuiGlLKODOOOBL+HbglGyWnWp0yidLJUxBNfe8tyNcieBp X-Received: by 2002:aca:eb4e:: with SMTP id j75mr269851oih.18.1585335671587; Fri, 27 Mar 2020 12:01:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585335671; cv=none; d=google.com; s=arc-20160816; b=HX54+rho8KTdz1q4t5AOmzivJyk8WvVBhGt8LNwNCdwalu+rwCeSS+nCirXmLt9wBn v89J0FxB//XQkk7GlWW/qSW89Z3K8iVoOL3/VedzbkAfKYE33slakM2/vyUN66HzEpWu BYxh864FA7XhVqd7eLN9sSpfQHrEVFR9JUVzOkmebGYil7D7wVpi+jOGfXP2+o69jtVv EW2QjunbTWWeO6SitXI1Odgd23aj/mhZMCoXv+uXy8dEeKszqVEXjZBB80htceGJkOmj iTjdxY+xUFazFMdiop3lVDt+99hhhlzkY97jPkQ/2B0IfDXOwnAPr1X0UtT5OIC1msAO uPNQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=twjYcQrRYpiw9NudM5mQXAf1fpDRg8b0hwUBq6FdQjU=; b=pb0YmEoi8VaaTcjx4e4XhI8bqkdwkiBTLL9UfDcmqVUvfASupNSXedVfvDagh153ug nsWMhp50lnhIEoHJS2x0rL4tcU4griGLjBqlK7c/D6UUStEiPSKxxdn0vQ8HHJ7ABPk9 EUHyVlDdPxsJsKZMphCBp3CtyKIddD6avSRXE2IbDWPV98nRtV/+Mq/J2laKlPye8pcm MBB/A9zwdBJ/Bk8/NuLEqs1gyGUPvNQnc5NeOCjCGhvjyMm1tWVstn30mreOD3kd2DQf MdTiojMiFVjo+FWjhYoSMYxp5q7pbjJBmpN2Hxx/n0qfzuvZUeZtDRe4AvPDbydt8aBZ WGHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BvMDA3Fm; 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 m5si2701041ooq.79.2020.03.27.12.00.55; Fri, 27 Mar 2020 12:01:11 -0700 (PDT) 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=BvMDA3Fm; 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 S1727125AbgC0S7y (ORCPT + 99 others); Fri, 27 Mar 2020 14:59:54 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:42559 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726738AbgC0S7x (ORCPT ); Fri, 27 Mar 2020 14:59:53 -0400 Received: by mail-pf1-f193.google.com with SMTP id 22so4920372pfa.9 for ; Fri, 27 Mar 2020 11:59:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=twjYcQrRYpiw9NudM5mQXAf1fpDRg8b0hwUBq6FdQjU=; b=BvMDA3FmKQtoeTxdP15PTNARGM9gHf3Feep8W5rjyaXMr3aZzhTYvlY1A9qlAuufld im3+AVd7vDsI993CjrFNXXH3bYLxcmYeWbrURE8nGUcT0SoEKHX1wEkT1TX26MUDgfM8 1oR8E85XFrBCP7YHWhsudLUxOkUucgASTxyDM= 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:content-transfer-encoding :in-reply-to; bh=twjYcQrRYpiw9NudM5mQXAf1fpDRg8b0hwUBq6FdQjU=; b=TEUllD74CwBqEccQ2wzi+QZ89lkLYH+qmPRn/BR1Gsvp0wRVC2ayujOEyG7MUw6LjP DFNi/zA29NFQgGrEZjhrEV13OY0Z8W+6u80zt1KHJVsASzRSZTedZwCUyg8o2dwX7b7A FgU+efkzx7MurhlI7Ot2PcnqmdZ9RojL20odu5zPoRrTOUHC1PfU/mn7+ZkWd78QaopT MfKxuUJcLznvHa57jdE+OD798HbMd8xOHZ6DtxcDZfYFWIjDo3izemzPXnd6xhfvhfeT ZrIEingi8NDLT8Mq8Eckq0oW7ByLNrQBbX8LdItihwpKYbJUll2kCo9H2hZUbEvqsvTr F57Q== X-Gm-Message-State: ANhLgQ1porMWj6N+nLJXSW1fqCSu2S8mjcgdznXW9go0SOnqPq9MUzPy Z0b9LQOimQIgdHx6j5psECVCiQ== X-Received: by 2002:a63:c212:: with SMTP id b18mr722672pgd.92.1585335591118; Fri, 27 Mar 2020 11:59:51 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id e26sm4679920pfj.61.2020.03.27.11.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2020 11:59:50 -0700 (PDT) Date: Fri, 27 Mar 2020 11:59:48 -0700 From: Kees Cook To: Casey Schaufler Cc: Stephen Smalley , KP Singh , James Morris , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org, Brendan Jackman , Florent Revest , Alexei Starovoitov , Daniel Borkmann , Paul Turner , Jann Horn , Florent Revest , Brendan Jackman , Greg Kroah-Hartman , Paul Moore Subject: Re: [PATCH bpf-next v7 4/8] bpf: lsm: Implement attach, detach and execution Message-ID: <202003271143.71E0C591C1@keescook> References: <20200326142823.26277-1-kpsingh@chromium.org> <20200326142823.26277-5-kpsingh@chromium.org> <2241c806-65c9-68f5-f822-9a245ecf7ba0@tycho.nsa.gov> <20200327124115.GA8318@chromium.org> <14ff822f-3ca5-7ebb-3df6-dd02249169d2@tycho.nsa.gov> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 27, 2020 at 09:36:15AM -0700, Casey Schaufler wrote: > On 3/27/2020 6:43 AM, Stephen Smalley wrote: > > On 3/27/20 8:41 AM, KP Singh wrote: > >> On 27-M?r 08:27, Stephen Smalley wrote: > >>> On 3/26/20 8:24 PM, James Morris wrote: > >>>> On Thu, 26 Mar 2020, KP Singh wrote: > >>>> > >>>>> +int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog, > >>>>> +??????????? const struct bpf_prog *prog) > >>>>> +{ > >>>>> +??? /* Only CAP_MAC_ADMIN users are allowed to make changes to LSM hooks > >>>>> +???? */ > >>>>> +??? if (!capable(CAP_MAC_ADMIN)) > >>>>> +??????? return -EPERM; > >>>>> + > >>>> > >>>> Stephen, can you confirm that your concerns around this are resolved > >>>> (IIRC, by SELinux implementing a bpf_prog callback) ? > >>> > >>> I guess the only residual concern I have is that CAP_MAC_ADMIN means > >>> something different to SELinux (ability to get/set file security contexts > >>> unknown to the currently loaded policy), so leaving the CAP_MAC_ADMIN check > >>> here (versus calling a new security hook here and checking CAP_MAC_ADMIN in > >>> the implementation of that hook for the modules that want that) conflates > >>> two very different things.? Prior to this patch, there are no users of > >>> CAP_MAC_ADMIN outside of individual security modules; it is only checked in > >>> module-specific logic within apparmor, safesetid, selinux, and smack, so the > >>> meaning was module-specific. > >> > >> As we had discussed, We do have a security hook as well: > >> > >> https://lore.kernel.org/bpf/20200324180652.GA11855@chromium.org/ > >> > >> The bpf_prog hook which can check for BPF_PROG_TYPE_LSM and implement > >> module specific logic for LSM programs. I thougt that was okay? > >> > >> Kees was in favor of keeping the CAP_MAC_ADMIN check here: > >> > >> https://lore.kernel.org/bpf/202003241133.16C02BE5B@keescook > >> > >> If you feel strongly and Kees agrees, we can remove the CAP_MAC_ADMIN > >> check here, but given that we already have a security hook that meets > >> the requirements, we probably don't need another one. > > > > I would favor removing the CAP_MAC_ADMIN check here, and implementing it in a bpf_prog hook for Smack and AppArmor if they want that.? SELinux would implement its own check in its existing bpf_prog hook. > > > The whole notion of one security module calling into another for permission > to do something still gives me the heebee jeebees, but if more nimble minds > than mine think this is a good idea I won't nack it. Well, it's a hook into BPF prog creation, not the BPF LSM specifically, so that's why I think it's general enough control without it being directly weird. :) As far as dropping CAP_MAC_ADMIN, yeah, that should be fine. Creating LSM BPF programs already requires CAP_SYS_ADMIN, so for SELinux-less systems, that's likely fine. If we need to change the BPF program creation access control in the future we can revisit it then. -- Kees Cook