Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4695526ybb; Tue, 24 Mar 2020 03:39:58 -0700 (PDT) X-Google-Smtp-Source: ADFU+vukKQCXnywmVqqzjsBcK+ou4I7RulhcQnzrKePw0pTR313F6kNrzTJ/cjk7L+alifsJSbzF X-Received: by 2002:aca:3008:: with SMTP id w8mr2762692oiw.96.1585046398299; Tue, 24 Mar 2020 03:39:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585046398; cv=none; d=google.com; s=arc-20160816; b=qEiKhy7xf5Kz47qXMFpAsxwBpHyLSFKwoxlIf1solfja8KiOdkWeem2GwO7pao801n sTf7h3qpaE83zvmeQxeT3UVMHYWcRJ5yfOU5ICYhrtujL6l71CjjvSpjMZRZK722cjn2 2x5FWaOIZ9xsikJop8/o9SDZjecpes8/PK9z90BChXG8fM2as1deSDhWyTj0YdLzud5/ n45UjO0ThXjxio1gBUIaip/d2CtOFSEhLmge0ZoDt4UehgVh+t5n2N+JGtjy42Pkh8GL U09cVxBQZupcDfwGI+n5Hp/Tn4dsXunmY0MaxkS2O45QFzZMbNCX0fmBw4z0mCvQvSxc AOlg== 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=WNURfYwUOPAnuz+U3UbPZyrljqXKCvMA7vRxyxXRqHM=; b=ehT+Db1FxLkw07z1ja5/QzZBCmPqxZ24haGe57KGW/Ne1HntMfnQMjES7Cs8Ymh8DT vrh65p7ICWw2F8uLmVr/Dtio/40DUGBEqgZjjB0zV/ODd1qRW4G93x5q8z8ClpD+ekkb v5AVqkdS7lkhWY6hGWjLm4Nh9i+wBOlrhAgcRQmuC2MZQR1GxxBESAHEUbV8uQrX4qAr 4oDJE0CDnRZwSgcsedGz38qoRf723v4gvmrkPfeI6YpT8j0KVY1DgPGEwUXXvviGFbSF aLTMeCGbufO4BpAjgj1+vUDoC4jwdSYjzGOoPxJwij/g4LuIQtkVtZQX/6yS/itF1V+v GhGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=h5BvdxgS; 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 a8si8531113oto.299.2020.03.24.03.39.45; Tue, 24 Mar 2020 03:39:58 -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=h5BvdxgS; 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 S1727297AbgCXKjP (ORCPT + 99 others); Tue, 24 Mar 2020 06:39:15 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:45040 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727066AbgCXKjP (ORCPT ); Tue, 24 Mar 2020 06:39:15 -0400 Received: by mail-wr1-f65.google.com with SMTP id m17so11775698wrw.11 for ; Tue, 24 Mar 2020 03: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=WNURfYwUOPAnuz+U3UbPZyrljqXKCvMA7vRxyxXRqHM=; b=h5BvdxgSXNE2/jma/jYDLUTdGPiB158yhJaCdf6uihjZuDF6ED9XbYBj9gs+33cFnL BR1q8lLb2zZjJ4RN+Z9haG820tRE9+3+kaOsQwpzzfqSE2Up3YZf6krsbiTbZGf9WN4m xsvkfvQuQ/lQQBEIFooS67t8NoZu9oZvSpcBE= 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=WNURfYwUOPAnuz+U3UbPZyrljqXKCvMA7vRxyxXRqHM=; b=VB5TBgfjbMfVmcEeLusG7rtL7ud9EZ+j54YRUsh/3Ad8Pw0fZl9G56sTvarfruJMsY V7QXlpAc5BiYfre2wUmZf3Ge1W81YZz/i4dsadbrxKvCMDaXIDZhyWaoAWgvzVkVyfsE mkk1CC5qLTLWTVc8xC8O+rcPmVm9DVJRZWPJntYPkSC/+o3jB1prkkYO6IM9XowR2c0w QqK1FGs34+4LmexnGz1+zZ3PlcIbyzIzxet4g3ik50Am0BvYyu3PKNtNb61K7/OuCZf5 RITop+c4oH2C5cOEb8NdJS/ZOWXawpg3l/SqXeNWDvgGYNwCAYJ9e9atUKwzkLuCWXxP vMkQ== X-Gm-Message-State: ANhLgQ1bhnXbEgZgY2k7EXaTZcuW2V2PoNlwY4AQHVrXJrr1/Dj02EFq qxRZHTCvpE514Fm43D6+qqVxLg== X-Received: by 2002:a5d:6187:: with SMTP id j7mr12220191wru.419.1585046353498; Tue, 24 Mar 2020 03: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 b187sm3828624wmb.42.2020.03.24.03.39.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 03:39:12 -0700 (PDT) From: KP Singh X-Google-Original-From: KP Singh Date: Tue, 24 Mar 2020 11: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: <20200324103910.GA7135@chromium.org> References: <20200323164415.12943-1-kpsingh@chromium.org> <20200323164415.12943-4-kpsingh@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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > > +#include > > +#undef LSM_HOOK > > > > const struct bpf_prog_ops lsm_prog_ops = { > > }; > > -- > > 2.20.1 > >