Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp5136246ybb; Tue, 24 Mar 2020 11:32:31 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs9xXom4Q//z/4Ns4CDDCH+l5vsDbwi2+IS1Y999VUd+BhjETa/SWOL3MbPd9G9d7liAXB9 X-Received: by 2002:a9d:1d07:: with SMTP id m7mr21921197otm.167.1585074751811; Tue, 24 Mar 2020 11:32:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585074751; cv=none; d=google.com; s=arc-20160816; b=J77BAFXgAQVD2hjG3xKqe+MreMLjl++Gy/wgc+xdt8w5gcFxIEuXZV8H1PR055hbWV rEOFKZjSfD6Tbtj90d2cv2ZbouXnY2WIJJItO82iNx6W/djHRVPffkdVQ/GPODQzOVo5 a8y619wbBSv7EjhXLMw0tXqDPJ3p6kC7F5rlmJIl0Ewqzy9oDl2OjfYmVJxyfcf+XFcx KJBGT63Mcf1VI2KqGPDXFoeDDLUjRjiC+ZywHhV8vbXlVHKn2mAy6WJEvf2AhwBKY+bU v44AdPmr3NAe22caqCZ7oZcldWSs5I8DoozOlNTtIL63yg7TjVjVwhirCYKjIe1IDsQp Hx5Q== 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=TRKPAduhRgzDYFGxEjhwPq1m22owdMRTC7dAMnXK8+o=; b=kVBYYiCcxknu3sQ37t5tW0WPbvw/2r4BhtfPXezH//G0WwbREG4JGcu+SWxD++88TK yuwv1JRZSyWQYFsRvLJD9KNG0BhfEgrxxHCyqkGocGWrMYFTbHDrrZXWdjnrhG+wiGRD LLQZPKum9mRBeYpligiXojRSJr+siP6JUqGIjI4qGPwhjBZOgJumZ/xgg0ecXgZ3gZQh vxURHgFrh6cXy1BWx1MhvoOX/OQSmxigs7HPTGWp2y9zYvNmK6FJwql7/fXeS7vMkJPE TDr+WSqsV3QenqLpo7ocpwfxiFzyP0H8Op3lDI17lNSOPJnNkGAGWcUN0Kdf6uCtXYsc mhQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KP8bPH6f; 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 m67si9459610oib.215.2020.03.24.11.32.14; Tue, 24 Mar 2020 11:32:31 -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=KP8bPH6f; 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 S1727662AbgCXSbh (ORCPT + 99 others); Tue, 24 Mar 2020 14:31:37 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33861 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727509AbgCXSbg (ORCPT ); Tue, 24 Mar 2020 14:31:36 -0400 Received: by mail-wr1-f68.google.com with SMTP id 65so6097627wrl.1 for ; Tue, 24 Mar 2020 11:31:33 -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=TRKPAduhRgzDYFGxEjhwPq1m22owdMRTC7dAMnXK8+o=; b=KP8bPH6f3jWjqSWoYd0o9+lv1OOSKO7pfp/BIzm+cXQWQbRWyXDB6S2KJWjLGdnKIl 5ea+BPNAStIimPJoBw8ecKXfZicIgjyjyL8kEyzlt20kRNpat2FLekmzx7KMzVi+vYV9 xnyc/6mnkuGv03QWVH50lmoKbLgoC6F7Y7pno= 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=TRKPAduhRgzDYFGxEjhwPq1m22owdMRTC7dAMnXK8+o=; b=bbAHl00a3DIRO2kIuizsCCxexQccwphSGbn9Z5pATkua41qkEulgB0+shJo1CHlBvU Jo3iUXlqJ6V+9PLoha9cCYcIPvi5ZIUjpHEgYBxlPVcPwGyugFXmRNcSd6U/jlAKKUR2 EdFLypfR0QyMSnOx/9Pq594mm2KvGDNmLiFq9+3p3itFWt399zeP6TwiMGJifC9PTNt1 +Ha/crfBXmB7wrnKjSgwdDk/B56ZIVnmNo16z8/dwjsXR7x8bsMeQ5wiwJH8U8YjQL9u DEq7fSFEq91ym1YMplwomvEtclZvhsSLhJVB6F2klJOsAD+G+AzA0AliGW4yH1q7HKZz 5LBw== X-Gm-Message-State: ANhLgQ1N15BBKZoJP01mffCOOIyeZTaLubN+6Fk0hiQ9gKKNEht7amDx /ggESA9g/Fowuq9BUb23ej6OaQ== X-Received: by 2002:a5d:4290:: with SMTP id k16mr16437054wrq.406.1585074692983; Tue, 24 Mar 2020 11:31:32 -0700 (PDT) Received: from chromium.org (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id v26sm29817820wra.7.2020.03.24.11.31.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 11:31:32 -0700 (PDT) From: KP Singh X-Google-Original-From: KP Singh Date: Tue, 24 Mar 2020 19:31:30 +0100 To: Stephen Smalley Cc: Kees Cook , 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: <20200324183130.GA6784@chromium.org> References: <20200323164415.12943-5-kpsingh@chromium.org> <20200324145003.GA2685@chromium.org> <202003241100.279457EF@keescook> <20200324180652.GA11855@chromium.org> <20200324182759.GA5557@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200324182759.GA5557@chromium.org> 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 19:27, KP Singh wrote: > On 24-M?r 14:21, Stephen Smalley wrote: > > On Tue, Mar 24, 2020 at 2:06 PM KP Singh wrote: > > > > > > 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. > > > > Ok. In that case do we really need the capable() check here at all? > > We do not have a specific capable check for BPF_PROG_TYPE_LSM programs > now. There is a general check which requires CAP_SYS_ADMIN when > unprivileged BPF is disabled: > > in kernel/bpf/sycall.c: > > if (sysctl_unprivileged_bpf_disabled && !capable(CAP_SYS_ADMIN)) > return -EPERM; > > AFAIK, Most distros disable unprivileged eBPF. > > Now that I look at this, I think we might need a CAP_MAC_ADMIN check > though as unprivileged BPF being enabled will result in an > unprivileged user being able to load MAC policies. Actually we do have an extra check for loading BPF programs: in kernel/bpf/syscall.c:bpf_prog_load if (type != BPF_PROG_TYPE_SOCKET_FILTER && type != BPF_PROG_TYPE_CGROUP_SKB && !capable(CAP_SYS_ADMIN)) return -EPERM; Do you think we still need a CAP_MAC_ADMIN check for LSM programs? - KP > > - KP