From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74408C10DCE for ; Tue, 24 Mar 2020 21:27:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3AE192076F for ; Tue, 24 Mar 2020 21:27:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oFV80YsD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727937AbgCXV1J (ORCPT ); Tue, 24 Mar 2020 17:27:09 -0400 Received: from mail-qv1-f67.google.com ([209.85.219.67]:42070 "EHLO mail-qv1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726673AbgCXV1I (ORCPT ); Tue, 24 Mar 2020 17:27:08 -0400 Received: by mail-qv1-f67.google.com with SMTP id ca9so10048958qvb.9; Tue, 24 Mar 2020 14:27:07 -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=VEJoT2ftN3/J+JzBUUMUSAFQV5uekS8p6QQqfLbkw4A=; b=oFV80YsDBCCQS0H4uydp2GAraoKy7ypaOl2OlD8XbZYroGuz5VpxBZxfoVMgGBvuQc TAiLpIF5hcEfbtGLKjdqpM7ILoJvZ77DINUgNK+ljR2xi72jnvWddbKxIvlaEAkzGQz0 jfbHfUrL7KAIm2RBEoyYfRUy6GRc4G6BwQbOgsHunw7c4GDpx1tXhGWJ2efEdhX1JEve PXSCvO38IkqekjcBSShUg+QPHwEeWr8xAO1AejfTANdqvPGSRfWKYyGa9mR98hazvVGe asS4dfkNHeWJgd8fNvwgSRQQNONdT8/31nSsRRJVI8wvjD8QwQmKmJltOXDL6R8+WyQA AwfQ== 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=VEJoT2ftN3/J+JzBUUMUSAFQV5uekS8p6QQqfLbkw4A=; b=RUf/ivsbbPqhMBIMgV3NBq72E8Lt0ykepGzQPT11t0Njbi+OkgF8IuLYGKrxQn7tF+ cLMCEMo8txjKQxoOBV8JAkHj+uDEgrK5uzN1L4JTijtmQRFZRgLeJo6T5QtGEBf62bxi xUQReLHqbvn6KoXdqB2+RlWksKsGIyVWvZq0NYWiXpffchLX/GzAr7p3I5pUdIo+2oSU kwrMSvmcrnovd1xX/Z8+FojJ/ziWESKhLFifDg60E/ezMx9Sl43/eNxYVAPqpIU8PAIX RtskwiR4A6yV1ODAmhURTvSVwTHWU6FM58QjtkCVYM//6iwxXxLiE9VMpFE12WKVoWhM Qb8w== X-Gm-Message-State: ANhLgQ3BvvZiOXX2bu7AnJyFcVpqMkZj83qIygsIFUv6itlUI5LktzSz J9fPTiQahaQRvNzCZ87vYx5VegRRNEH5KkTon10= X-Google-Smtp-Source: ADFU+vvnlC2tuBiX08DOSzyNzyZRiEDqPSX5ECF8NjcPaR1qvgPpgcPX+NbxgqdXH4UO5KxsSJRb91QXeEmgiswfoFM= X-Received: by 2002:a0c:ee28:: with SMTP id l8mr178148qvs.196.1585085226618; Tue, 24 Mar 2020 14:27:06 -0700 (PDT) MIME-Version: 1.0 References: <20200323164415.12943-1-kpsingh@chromium.org> <20200323164415.12943-4-kpsingh@chromium.org> <20200324103910.GA7135@chromium.org> <20200324161211.GA11227@chromium.org> In-Reply-To: <20200324161211.GA11227@chromium.org> From: Andrii Nakryiko Date: Tue, 24 Mar 2020 14:26:55 -0700 Message-ID: Subject: Re: [PATCH bpf-next v5 3/7] bpf: lsm: provide attachment points for BPF LSM programs To: KP Singh Cc: open list , bpf , linux-security-module@vger.kernel.org, Brendan Jackman , Florent Revest , Alexei Starovoitov , Daniel Borkmann , James Morris , Kees Cook , Paul Turner , Jann Horn , Florent Revest , Brendan Jackman , Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: On Tue, Mar 24, 2020 at 9:12 AM KP Singh wrote: > > On 24-M=C3=A4r 11:39, KP Singh wrote: > > On 23-M=C3=A4r 12:59, Andrii Nakryiko wrote: > > > On Mon, Mar 23, 2020 at 9:45 AM KP Singh wrote= : > > > > > > > > From: KP Singh > > > > > > > > When CONFIG_BPF_LSM is enabled, nops functions, bpf_lsm_= , are > > > > generated for each LSM hook. These nops are initialized as LSM hook= s in > > > > a subsequent patch. > > > > > > > > Signed-off-by: KP Singh > > > > Reviewed-by: Brendan Jackman > > > > Reviewed-by: Florent Revest > > > > --- > > > > include/linux/bpf_lsm.h | 21 +++++++++++++++++++++ > > > > kernel/bpf/bpf_lsm.c | 19 +++++++++++++++++++ > > > > 2 files changed, 40 insertions(+) > > > > create mode 100644 include/linux/bpf_lsm.h > > > > > > > > diff --git a/include/linux/bpf_lsm.h b/include/linux/bpf_lsm.h > > > > new file mode 100644 > > > > index 000000000000..c6423a140220 > > > > --- /dev/null > > > > +++ b/include/linux/bpf_lsm.h > > > > @@ -0,0 +1,21 @@ > > > > +/* SPDX-License-Identifier: GPL-2.0 */ > > > > + > > > > +/* > > > > + * Copyright (C) 2020 Google LLC. > > > > + */ > > > > + > > > > +#ifndef _LINUX_BPF_LSM_H > > > > +#define _LINUX_BPF_LSM_H > > > > + > > > > +#include > > > > +#include > > > > + > > > > +#ifdef CONFIG_BPF_LSM > > > > + > > > > +#define LSM_HOOK(RET, NAME, ...) RET bpf_lsm_##NAME(__VA_ARGS__); > > > > +#include > > > > +#undef LSM_HOOK > > > > + > > > > +#endif /* CONFIG_BPF_LSM */ > > > > + > > > > +#endif /* _LINUX_BPF_LSM_H */ > > > > diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c > > > > index 82875039ca90..530d137f7a84 100644 > > > > --- a/kernel/bpf/bpf_lsm.c > > > > +++ b/kernel/bpf/bpf_lsm.c > > > > @@ -7,6 +7,25 @@ > > > > #include > > > > #include > > > > #include > > > > +#include > > > > +#include > > > > + > > > > +/* For every LSM hook that allows attachment of BPF programs, dec= lare a NOP > > > > + * function where a BPF program can be attached as an fexit trampo= line. > > > > + */ > > > > +#define LSM_HOOK(RET, NAME, ...) LSM_HOOK_##RET(NAME, __VA_ARGS__) > > > > + > > > > +#define LSM_HOOK_int(NAME, ...) \ > > > > +noinline __weak int bpf_lsm_##NAME(__VA_ARGS__) \ > > > > +{ \ > > > > + return 0; \ > > > > +} > > > > + > > > > +#define LSM_HOOK_void(NAME, ...) \ > > > > +noinline __weak void bpf_lsm_##NAME(__VA_ARGS__) {} > > > > + > > > > > > Could unify with: > > > > > > #define LSM_HOOK(RET, NAME, ...) noinline __weak RET bpf_lsm_##NAME(_= _VA_ARGS__) > > > { > > > return (RET)0; > > > } > > > > > > then you don't need LSM_HOOK_int and LSM_HOOK_void. > > > > Nice. > > > > But, given that we are adding default values and that > > they are only needed for int hooks, we will need to keep the macros > > separate for int and void. Or, Am I missing a trick here? > > > > - KP > > Actually, was able to get it work. not setting a default for void > hooks makes the macros messier. So i just set it void. For example: > > LSM_HOOK(void, void, bprm_committing_creds, struct linux_binprm *bprm) surprised this works, was going to propose to specify `(void)0` as default value :) > > This also allows me to use the cleanup you suggested and not having > to split every usage into int and void. > Nice, one of the reasons for proposing this. > - KP > > > > > > > > > > +#include > > > > +#undef LSM_HOOK > > > > > > > > const struct bpf_prog_ops lsm_prog_ops =3D { > > > > }; > > > > -- > > > > 2.20.1 > > > >