Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp5109786ybb; Tue, 24 Mar 2020 11:07:56 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv5IzflPN+9ka5xWCf/55TBjvclH4CJL0CR43EH9r5e+ZTzLbt8zg6K35wVQekpDwcV0YqT X-Received: by 2002:a05:6830:1313:: with SMTP id p19mr5439200otq.179.1585073275812; Tue, 24 Mar 2020 11:07:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585073275; cv=none; d=google.com; s=arc-20160816; b=rrjNoCc7HFygY1X7oB2V4nFjHJoiJ27iqCTI76xoo403C5/qHhAjxGDLIWobjlr7ZB d7JuY2Af+g/uZOloX2ejZk5RL5cQ6xsJtmgT80b/7AsjxuW2olVzdKlwtakyR6GnYFIv kcAUADn1WNAMlAxnELl3KIzyrpTuqKAR4GwqIAlL18hTLRBpCW1db8Ru449swoDMl4ly gEdkA6456034lZf+thfdysTXBsDLlbKCGynaNGur0gH/Nv6Fh1838mE7tSQrj504LdqG wZDQ53Yu/5dSScSGvd/R3pMAkUAYo2I8Ih/gD0KTmSOC6B0UX+72jaMHry22YWbSr/Yk q5hg== 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=xhSNhInfbkhw9Tyrol6FCl+av3/YsbNLmKw2OeAtFgo=; b=YPuO1aleP8j/3qm0OPeKBK+04DN657hH7YEclS57tg8NRO3bpp15c+O4H9fb/n+BvT gLFpBl2ksAsdDM9xcpAEppy+YaDT2jXCea6UfYKhzccIYvLKxS69sREoqPCP8tgH9/7q KtD78kVRqc4h8VcJ+MbJLax/JBZL6ZBIdmai3slvj1+n4CiOtw0ZWdDteK7TS/Y1KFuZ kAXCUnbcBZaE66BJBBsfdxGS7SF3AuGIcWiZ9OhurWBFs11qziLANgAjIDCQOBhxFGE2 wWePxxTWePKciGLUuVrYUCiwYR2ASBe2lFn8pujipDslbJ157aooqq5mUoN4yPeumzvr W79w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=c6BWSWwJ; 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 x33si9254455otb.48.2020.03.24.11.07.41; Tue, 24 Mar 2020 11:07:55 -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=c6BWSWwJ; 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 S1727393AbgCXSG5 (ORCPT + 99 others); Tue, 24 Mar 2020 14:06:57 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:33412 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727257AbgCXSG5 (ORCPT ); Tue, 24 Mar 2020 14:06:57 -0400 Received: by mail-wm1-f68.google.com with SMTP id w25so306151wmi.0 for ; Tue, 24 Mar 2020 11:06:55 -0700 (PDT) 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=xhSNhInfbkhw9Tyrol6FCl+av3/YsbNLmKw2OeAtFgo=; b=c6BWSWwJu2NoDWhT1p3b28hnOXVHz4XHF8NEU/7/D+2zuTMXNee6qXECxllDNYLtk4 OJXXUZjl26Ax+c2wx7B/W/Q92kUZY1FQP5WT7nRATW02tPGaOwFr3xZ5PInMbCYUiCp/ SBYjIQ8SSx/jwyXYLIMKsBr6gLhNBJjyEO5pU= 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=xhSNhInfbkhw9Tyrol6FCl+av3/YsbNLmKw2OeAtFgo=; b=T629D7/fx4kErR/A/+cMvWyi0cFRc/0qhN4oZTzzt3aAhEwGIsOrIqR6b+i35OJ0OX touyVSDI6CJbL/+gUaCVAN0jL5Z4Ifx7PFkl4i58CART+yeKbdLw0izID9KpwIDqMfxH O2lOjF2a2hqe0nBNUXu7UJhaFZ3CexxbzjotFLUKnYwAzgv1ctSpPiSQ3V/Bk9prJzjj maJEsyF3FJngb1RDLO7JveWowLYwsrCBpdE7wwt8BL1QpN1YOfz/DLVo9/Bauq4JcyHm 5cM/sFo6U+Tz2nVU71BG7kAh9LfgJxOYh7r5LQG5pyG4zYfq5x/vH72AIwmZYFfx4Gyb dFwA== X-Gm-Message-State: ANhLgQ1AOzmyU595RhCqWjFk3b8BAizOBycTM801xUk0OaeFLQmI4uJx B4fDTW/lG1CjN/yWV5gD//lHjQ== X-Received: by 2002:a1c:a552:: with SMTP id o79mr7018394wme.87.1585073214731; Tue, 24 Mar 2020 11:06:54 -0700 (PDT) Received: from chromium.org (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id l12sm29098026wrt.73.2020.03.24.11.06.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 11:06:54 -0700 (PDT) From: KP Singh X-Google-Original-From: KP Singh Date: Tue, 24 Mar 2020 19:06:52 +0100 To: Kees Cook Cc: Stephen Smalley , Casey Schaufler , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, LSM List , Brendan Jackman , Florent Revest , Alexei Starovoitov , Daniel Borkmann , James Morris , Paul Turner , Jann Horn , Florent Revest , Brendan Jackman , Greg Kroah-Hartman , Paul Moore Subject: Re: [PATCH bpf-next v5 4/7] bpf: lsm: Implement attach, detach and execution Message-ID: <20200324180652.GA11855@chromium.org> References: <20200323164415.12943-1-kpsingh@chromium.org> <20200323164415.12943-5-kpsingh@chromium.org> <20200324145003.GA2685@chromium.org> <202003241100.279457EF@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202003241100.279457EF@keescook> 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 24-M?r 11:01, Kees Cook wrote: > On Tue, Mar 24, 2020 at 01:49:34PM -0400, Stephen Smalley wrote: > > On Tue, Mar 24, 2020 at 12:25 PM Casey Schaufler wrote: > > > > > > On 3/24/2020 7:58 AM, Stephen Smalley wrote: > > > > On Tue, Mar 24, 2020 at 10:50 AM KP Singh wrote: > > > >> On 24-M?r 10:35, Stephen Smalley wrote: > > > >>> On Mon, Mar 23, 2020 at 12:46 PM KP Singh wrote: > > > >>>> From: KP Singh > > > >>>> diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c > > > >>>> index 530d137f7a84..2a8131b640b8 100644 > > > >>>> --- a/kernel/bpf/bpf_lsm.c > > > >>>> +++ b/kernel/bpf/bpf_lsm.c > > > >>>> @@ -9,6 +9,9 @@ > > > >>>> #include > > > >>>> #include > > > >>>> #include > > > >>>> +#include > > > >>>> +#include > > > >>>> +#include > > > >>>> > > > >>>> /* For every LSM hook that allows attachment of BPF programs, declare a NOP > > > >>>> * function where a BPF program can be attached as an fexit trampoline. > > > >>>> @@ -27,6 +30,32 @@ noinline __weak void bpf_lsm_##NAME(__VA_ARGS__) {} > > > >>>> #include > > > >>>> #undef LSM_HOOK > > > >>>> > > > >>>> +#define BPF_LSM_SYM_PREFX "bpf_lsm_" > > > >>>> + > > > >>>> +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; > > > >>> I had asked before, and will ask again: please provide an explicit LSM > > > >>> hook for mediating whether one can make changes to the LSM hooks. > > > >>> Neither CAP_MAC_ADMIN nor CAP_SYS_ADMIN suffices to check this for SELinux. > > > >> What do you think about: > > > >> > > > >> int security_check_mutable_hooks(void) > > > >> > > > >> Do you have any suggestions on the signature of this hook? Does this > > > >> hook need to be BPF specific? > > > > I'd do something like int security_bpf_prog_attach_security(const > > > > struct bpf_prog *prog) or similar. > > > > Then the security module can do a check based on the current task > > > > and/or the prog. We already have some bpf-specific hooks. > > > > > > I *strongly* disagree with Stephen on this. KRSI and SELinux are peers. > > > Just as Yama policy is independent of SELinux policy so KRSI policy should > > > be independent of SELinux policy. I understand the argument that BDF programs > > > ought to be constrained by SELinux, but I don't think it's right. Further, > > > we've got unholy layering when security modules call security_ functions. > > > I'm not saying there is no case where it would be appropriate, but this is not > > > one of them. > > > > I explained this previously. The difference is that the BPF programs > > are loaded from a userspace > > process, not a kernel-resident module. They already recognize there > > is a difference here or > > they wouldn't have the CAP_MAC_ADMIN check above in their patch. The > > problem with that > > check is just that CAP_MAC_ADMIN doesn't necessarily mean fully > > privileged with respect to > > SELinux, which is why I want an explicit hook. This gets a NAK from > > me until there is such a hook. > > Doesn't the existing int (*bpf_prog)(struct bpf_prog *prog); cover > SELinux's need here? I.e. it can already examine that a hook is being > created for the LSM (since it has a distinct type, etc)? I was about to say the same, specifically for the BPF use-case, we do have the "bpf_prog" i.e. : "Do a check when the kernel generate and return a file descriptor for eBPF programs." SELinux can implement its policy logic for BPF_PROG_TYPE_LSM by providing a callback for this hook. - KP > > -- > Kees Cook