Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp5103945ybb; Tue, 24 Mar 2020 11:02:12 -0700 (PDT) X-Google-Smtp-Source: ADFU+vshckNir1BTZ0mVJ/dQQWot3VH+plqADT0D00R0SkUTZDWMcnFLNeu9TPn082yiNEuzIrUp X-Received: by 2002:aca:c390:: with SMTP id t138mr4166575oif.117.1585072932295; Tue, 24 Mar 2020 11:02:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585072932; cv=none; d=google.com; s=arc-20160816; b=Db5FkTU+PbPpVtTgzU3xZTzYQkR1PBelFfGf6rz1nK6Luw3fANC2gLGCCCF+Rn+Ba5 QswWerE66OCNNHFO4VQf55PwhNa+AISi4g1v2xIMbE3bWtHn7jCDO/c4SUQb6BRGEsKp 7Nl7gf0+Hs/G5Fr78Z3QtgJsjMOIoHDdYPrj7IjvMgMtyN1RaGD1Z3rHLCgXmL/lIlTr CBu0s1qj7Vernr+Nj6Vx316LE/ybiXcAVJyAKdv4ZCDb2UvrVxsQdP6yOaTCmzjtZS9E 3TdH++vpAMaY4omMeKQPyPt7QoL8Vyg4BzuGy3w8KSAR/vzacB0DRGzos9+DxG5hb532 XQYA== 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=p/25+VohAOX3oBgJFFKkPBRMfW/ssz0RSjZO0iulozc=; b=e4GdRMARfI1xl7wtyBNTJ592A+3FGwyoJ0tWQ8JuMHdIR5oLL2fdc/VZxK+GNky90i 0xSUCUWi2rVNWBZ68ORfWEGN3o8L8927IdJS5HTl+a4Fa+WNNeb0/eUaUNglXEHkfUV/ u7hF0ByGqpa9aPdgzvHNIdEyKcxtHNhfIAwEoIOcb08SclBgs7cG3Uy2TKvngp4hV3h2 gw6BK0INSKFgeS/f2Ilyg+eBP0cD7Ty7rLZzemHVqba9M9Xnbz78ituTU9+98lc0l/8k gG2k6BiInrnADyguYXylvhJCQJd/qKya1EDghdOpMbf55LFAnVviJMIPrhjp2lFp3CYd R2Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Q9VMbXjn; 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 e4si10108698otj.242.2020.03.24.11.01.55; Tue, 24 Mar 2020 11:02:12 -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=Q9VMbXjn; 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 S1727509AbgCXSBS (ORCPT + 99 others); Tue, 24 Mar 2020 14:01:18 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:34808 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727318AbgCXSBS (ORCPT ); Tue, 24 Mar 2020 14:01:18 -0400 Received: by mail-pj1-f66.google.com with SMTP id q16so1416335pje.1 for ; Tue, 24 Mar 2020 11:01:17 -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=p/25+VohAOX3oBgJFFKkPBRMfW/ssz0RSjZO0iulozc=; b=Q9VMbXjnSM/D/DUHkyvF+6SqZf1W+Duhih6q1dsNV3HaC4RlaR0DWVaf7YsYP9/mOv 2cL4SU+7oFPyDM04T0cTFfZ7eIw9mjJPnOCHS2N2FWE5/dbxzIQQUlSBRlbXkn+yxl4x EU39xlrlA3DrdPy7fmHBdhXNlbglNI47yR4ok= 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=p/25+VohAOX3oBgJFFKkPBRMfW/ssz0RSjZO0iulozc=; b=sEAF4JAvUt74K1T47iLDrjdosgE+Z8Xujfxw/Cw9R7Y9f+NX2ky4g31PTTkPTzw5ys ayrTd07saI2m9qWjWYyo6OGBREsBPby/oBMcggPSiiiwRWaReRgz//JAe10eEPkubcir BTcHLZQyFtqXoxCzaJzDtYfXmbrkrjjKowCsuVfhRIP+SPHWf8wA8gjFueYbMoEjTWni 2DHfgt14CuaxryCW/oFJgwZsVATT5nOwX+QJuSHcLZLIzwO+1newxuY4rx7fcWJCRskc x3+C/+u4f4Q+lU2DGxQsEGwM67Hl340c+RFtEqJ5KgTi9JNuImDMt4pRL67e51ea/gY2 qZww== X-Gm-Message-State: ANhLgQ2BlzRUnEtx3R99OXtKmc77eT+Zf3lt4ayKjF+nBZgAld4IYWsb cQdZJYtdlJ9QEu7gxkpy+U0Kaw== X-Received: by 2002:a17:902:7c0c:: with SMTP id x12mr24983110pll.196.1585072876326; Tue, 24 Mar 2020 11:01:16 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id f127sm16731008pfa.9.2020.03.24.11.01.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 11:01:15 -0700 (PDT) Date: Tue, 24 Mar 2020 11:01:14 -0700 From: Kees Cook To: Stephen Smalley Cc: Casey Schaufler , KP Singh , 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: <202003241100.279457EF@keescook> References: <20200323164415.12943-1-kpsingh@chromium.org> <20200323164415.12943-5-kpsingh@chromium.org> <20200324145003.GA2685@chromium.org> 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 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)? -- Kees Cook