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=-8.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham 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 96D24C10DCE for ; Tue, 24 Mar 2020 22:39:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 52F9420409 for ; Tue, 24 Mar 2020 22:39:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="eFbp7iaJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728289AbgCXWjP (ORCPT ); Tue, 24 Mar 2020 18:39:15 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:42397 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728227AbgCXWjP (ORCPT ); Tue, 24 Mar 2020 18:39:15 -0400 Received: by mail-wr1-f65.google.com with SMTP id h15so605351wrx.9 for ; Tue, 24 Mar 2020 15:39:14 -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=CsJTvGpVPmav8scr1f+8vGqJnRDlYhqVnGsY3dWNugM=; b=eFbp7iaJn1hT6hxrzF9p2+uV+G3iYIs+RbR8w+oGK0SWl0M4CdoFe9D5CI8MNBfLsT FhwxLc9CyARUimd4HUlZZOKRqVlcuOlFSP9Za+9D9NKccTdhiyawFfOKdUwa0n4aVQut bdVmJFSTEIUwO6Of5kw0HNRVyFy7EgOsn8Cy8= 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=CsJTvGpVPmav8scr1f+8vGqJnRDlYhqVnGsY3dWNugM=; b=Q6QRCGJfipqGRMQh859oVembBCAKPkZKKHTNRCn58S5kIKCZGW7b73Ojax/++GWwtv JDU+feBWZjaFylWJGh0Y/KtEIrhxqSm16rVa+zeFc0wzbYymM+Gs3+D6xDAh3pSnHRCm tUDN+hxJXupx0NFITApfiWxgtyixAapCCbYt2zR9TERjZLObKMFFNNsvuLVNrjkefpEv KoSDOSULO9LoUUggHeaFsq1A+5Yy/RNWIdGU+7hDdB9MlFj8w7RbLdLDCp+LXhL1hpX2 hyFsm9D843ynB7BOenv33PMiTXYUrc86QIj4rVXpUqPmnrtYZ1UX/DdIxeOZHDEFT/RB F8FQ== X-Gm-Message-State: ANhLgQ2W4WxDeEQAJDSpK9jFSsYXOO3cNZ7szyrbgwDc6SCY+SzxX1mw A+4/+2Db5AvlUodwhZYHbP4e8A== X-Google-Smtp-Source: ADFU+vvmq9phB+TJsSu5PlZjdZhx430KLaniYgGVncHAKBv0pYcKZqkSfT8jbwXzYfaMKem6odSqdQ== X-Received: by 2002:adf:9322:: with SMTP id 31mr39623063wro.297.1585089553456; Tue, 24 Mar 2020 15:39:13 -0700 (PDT) Received: from chromium.org (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id c21sm5509329wmb.13.2020.03.24.15.39.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 15:39:12 -0700 (PDT) From: KP Singh X-Google-Original-From: KP Singh Date: Tue, 24 Mar 2020 23:39:10 +0100 To: Andrii Nakryiko 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 Subject: Re: [PATCH bpf-next v5 3/7] bpf: lsm: provide attachment points for BPF LSM programs Message-ID: <20200324223910.GA5448@chromium.org> References: <20200323164415.12943-1-kpsingh@chromium.org> <20200323164415.12943-4-kpsingh@chromium.org> <20200324103910.GA7135@chromium.org> <20200324161211.GA11227@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: On 24-Mär 14:26, Andrii Nakryiko wrote: > On Tue, Mar 24, 2020 at 9:12 AM KP Singh wrote: > > > > On 24-Mär 11:39, KP Singh wrote: > > > On 23-Mär 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 hooks 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, declare a NOP > > > > > + * function where a BPF program can be attached as an fexit trampoline. > > > > > + */ > > > > > +#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 :) Yeah, you are right that does not work. so I added: LSM_HOOK(void, LSM_RET_VOID, bprm_committed_creds, struct linux_binprm *bprm) and as you suggested defined LSM_RET_VOID in lsm_hooks.h: /* LSM_RET_VOID is used as the default value in LSM_HOOK definitions for void * for void LSM hooks (in include/linux/lsm_hook_defs.h). */ #define LSM_RET_VOID ((void) 0) I also noticed a few other hooks that were passing an initial return value to call_int_hook which were missed in this revision. Have fixed these for the next one. - KP > > > > > 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 = { > > > > > }; > > > > > -- > > > > > 2.20.1 > > > > >