Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp5125103ybb; Tue, 24 Mar 2020 11:21:09 -0700 (PDT) X-Google-Smtp-Source: ADFU+vu2PzEdq9vm+9lr8doV2rmp8Oh/JrxeUj4uNpPg1rjf9rbdV+0sS/FOkpICovfOFKNHqDwM X-Received: by 2002:a4a:8e59:: with SMTP id z25mr2397700ook.86.1585074069024; Tue, 24 Mar 2020 11:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585074069; cv=none; d=google.com; s=arc-20160816; b=egYvoGexWFixNS3aT+8YDQkcLM7dOt24LXYax+OnyiuGvDniU+S2tp0u24eRlIQTl1 yg7pl7DpEh6uLLVBBnNE09tceFYKeOh9yPNjW1SBvMBBMeMeR+Utu0F+50mu2pP95jRw PmO9t4ql5yA7VJgeaDy39TPJRKPUexPkCvjXktJkEZOuRWbpb/TGICt1I2nSocAL03MW 8J6JssNSU/Ig+m4NATehEiZGlSrEgjV8Y+uhgUY0pt9XkEdL4mXehj4UNwTbNJLg8W7y MWgd+TdaM/qKcE16EIiYzj8MnUwOG8a4kqhMtbRRYMEZx6ABbEVbPc/o8vVTq3781vjo t9zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=QAsNqo91AZeBDE6F+SBZ53GrNbBmODwiTL6H1PjXDaY=; b=ThOzZnkzKHlA2tFf+SntOSeQugDdp9qcr+CAgx4Tw9tGVHH3bYpbAxDbmKa/JvTwOr NPwme9gwNH29UqE8vVvJ0QbaPuEdvA0VJnchTClC+MHFYjy72N3+GxL65JyGggokrsLo DZTE7l+7YAm2k+vy36YD9BySGRHiwcOQxeX9CvGmt37nDyX8eah2Bao6Vm0MKsBmOPSB CPtPLIXfUJg+ddOyPIu+lwcaxvXCbcDBJO2j7bZ+Jph3BExC6eitBQk4rS6DDqpYuiF4 tjWKoszQUW8K4BtCxKf8Pa7uBzjUVTH6ee4dnFZejuR6iRlF+4HVdpynVhLYsakCW7Lo 9wCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nDPahvsx; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h81si9308066oif.20.2020.03.24.11.20.54; Tue, 24 Mar 2020 11:21:09 -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=@gmail.com header.s=20161025 header.b=nDPahvsx; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727791AbgCXSUV (ORCPT + 99 others); Tue, 24 Mar 2020 14:20:21 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:37668 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727379AbgCXSUV (ORCPT ); Tue, 24 Mar 2020 14:20:21 -0400 Received: by mail-oi1-f196.google.com with SMTP id w13so19439983oih.4; Tue, 24 Mar 2020 11:20:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=QAsNqo91AZeBDE6F+SBZ53GrNbBmODwiTL6H1PjXDaY=; b=nDPahvsxANLN/fCqy3jJsk5S4SDwZAZh3QOv6ulH4PESbA0kR6J5qkTP7HWSy6BEW1 X/Q32jC3wNDPfa7iFm7XMtXwwBXIO39cxoJBgpREBxAZFrZ6g5vCBcOBRCtMaAQUjJIn PUeMNR1ubkrzX7LcAq7KtJ7OeU2GbHdTsckA2Q9MxLHxrF+gPePvSccJvifd2GA/EnZD jA5CEWRHRUsLjBB4VH7Rz+CDALpVQVgVHxg2y0xqqE38hmor/aPO5hxziFl54TucYtIA C0LAU/7IW+PF3nWO4ttq3MjfJgEUYxf5pOI+/2YzOTkuMg0fZu4YDGF2B8KTrX/hzepO qsUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=QAsNqo91AZeBDE6F+SBZ53GrNbBmODwiTL6H1PjXDaY=; b=VCNRplK3b88b7x2YP4if3u9/AnsBQ01QZfUWa5OpMVVnA0OwYuFVktaKfL4Ge7GqER fRFoQzVYzhrx6CWR1/aqGa6jTLO97qgJto/Y9ur//PqFJkipeF9h1f0D7dSAGZu1CuMD wb919KzkYLyiHnAhopNKjd3XUEfWgjHagWjwreZE/AUQ34vbUyyW7Rxh6NuVgvTaFcjH eIboDgoqA8jBLu7HNlnw08JAmGZsFlgJLgDhw7wzox3eX/EFzmsNhDCeLBQbVsgwJn6Y 5GC2un04U13NHHMOdbbuaGCH8CB44vUu61xPy5wceJRNV/6qYVSBv0Zk9DuSnsyTtYVm 17TQ== X-Gm-Message-State: ANhLgQ13o9RuLvVeTohxa6rfYbs0TYrVteox7MHjoZlRz3of9etyiI8a Vwqj7D6CAczwZOvmWfR/9euPUBekaGTBHklO1z4= X-Received: by 2002:aca:b803:: with SMTP id i3mr4303855oif.92.1585074020348; Tue, 24 Mar 2020 11:20:20 -0700 (PDT) MIME-Version: 1.0 References: <20200323164415.12943-1-kpsingh@chromium.org> <20200323164415.12943-5-kpsingh@chromium.org> <20200324145003.GA2685@chromium.org> <202003241100.279457EF@keescook> <20200324180652.GA11855@chromium.org> In-Reply-To: <20200324180652.GA11855@chromium.org> From: Stephen Smalley Date: Tue, 24 Mar 2020 14:21:30 -0400 Message-ID: Subject: Re: [PATCH bpf-next v5 4/7] bpf: lsm: Implement attach, detach and execution To: KP Singh 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 2:06 PM KP Singh wrote: > > On 24-M=C3=A4r 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=C3=A4r 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 t= rampoline. > > > > >>>> @@ -27,6 +30,32 @@ noinline __weak void bpf_lsm_##NAME(__VA_AR= GS__) {} > > > > >>>> #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 change= s to LSM hooks > > > > >>>> + */ > > > > >>>> + if (!capable(CAP_MAC_ADMIN)) > > > > >>>> + return -EPERM; > > > > >>> I had asked before, and will ask again: please provide an expli= cit LSM > > > > >>> hook for mediating whether one can make changes to the LSM hook= s. > > > > >>> 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 pe= ers. > > > > Just as Yama policy is independent of SELinux policy so KRSI policy= should > > > > be independent of SELinux policy. I understand the argument that BD= F programs > > > > ought to be constrained by SELinux, but I don't think it's right. F= urther, > > > > we've got unholy layering when security modules call security_ func= tions. > > > > 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?