Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4305321ybb; Mon, 23 Mar 2020 18:13:51 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuddFpwwPvAiXpyhiaXwikrgAgfvcUASQqQhRiJ0MtpVZBIQKKQ/uMgz2sGzUMcp19Xft3R X-Received: by 2002:aca:a98a:: with SMTP id s132mr1694085oie.75.1585012431185; Mon, 23 Mar 2020 18:13:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585012431; cv=none; d=google.com; s=arc-20160816; b=F1tZMvpfDqjQb0pCok5egYnrPBtbNT1LgFZPIDazPFAXegsh3pF11XuwtOqWHCFaWE Fo+Kk0GhZmn+YB0bzx+7v6FFc8CUpzIVONrVoVy7Y3rJCRTUtP5hkq+mjwc8a54ZHcli ZqPWI3B11u0D2p435LDEJEk7bPzoWz9XDEU9jzW+MatzWgcRX+SqZ3E9MM8OC7bfK9nM uCJ9EQrqxITrHW7eSHFFYal0I7D+dH4BM0ttKJuh9d1QXies3Nu8HekhHz+atvCTKto0 yi70PxkSj+Nc4FmITkGT2C6Ijs7mUVEOkr0zTIRVubc87LFmfGghygzqRS5nPQePBNMP gPog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:from:references:cc:to:subject:dkim-signature; bh=E8pHerNHsgqWl5NSFOxfCUBbRlZ0aBL2d+8GXaQowo0=; b=ld1E30hABTTp59OsIXD8zXsMqJXETMqFFLVbIGNMD8aU9zkBXPUW7/VNhxZ2D1ceIW rL6woUKSU6GYWQ/P61saH+l1W351xAYNLD7Gg4gWqq9bNa6Hi2sZIB7Y/kUXZJtdT1z5 AzQgX3qtn6cWolpUUzLi+TSkRZ2y7haY7NrofDcdJ4JCmBSFyvhxxLMmx38j/tGbufTi E+QugmIl7JxT1T6byQ3gxJsjL+2pmV/phsY3hVmqMxMfgdtFmXaYVQ84s2jVvoBDfHpo R+4REmt0DRyeqmlaqs7KjGJEIO/kE2LUG5QsnZjYBiHmhYtC+FwCQM0SanJuvNhi2u8G d4/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=CHjGmQne; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j192si7919817oih.233.2020.03.23.18.13.37; Mon, 23 Mar 2020 18:13:51 -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=@yahoo.com header.s=s2048 header.b=CHjGmQne; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727161AbgCXBNN (ORCPT + 99 others); Mon, 23 Mar 2020 21:13:13 -0400 Received: from sonic309-28.consmr.mail.ne1.yahoo.com ([66.163.184.154]:41410 "EHLO sonic309-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727101AbgCXBNM (ORCPT ); Mon, 23 Mar 2020 21:13:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1585012391; bh=E8pHerNHsgqWl5NSFOxfCUBbRlZ0aBL2d+8GXaQowo0=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=CHjGmQneFxo3HOlwUQ1F5pIpkGWLUBzDtSackwOb9nsluo6LL6czIxrpLVVxZRYCDVr3JF2DqqiFyBav8yr1z8S+KYWBZLWv0ivOx+SpwXsCpVOo2ej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JNMGuDA1qUHzPYp79nBbOJBA1MTxVz2VxMtgO0_e9Sp72YZzP2Kgct.Vj1laevrf0ilwx F3heg.V3o9ewwqH1.M0tmEAjiE6R1Jv.AG6yfYg7W.LfoY0w8lbJebb3juASPD1RkH4k6p9_J8Hk SitsgX3gj_uCFBI0isfJrbCQldzN8Cf8eaYU3gMBCGtbtJ5K9MGfnEmNJTtFhVRbM7LO6cA04Aqe WlDZomSTAkNu84UxkFE66yHscaIgcCT9bIwiMlhqdvcBnAdiZSCNo.LMZcWgbGBQg6Pkow89tvyk dYslQMVga0RKJ2oZumfkwj3GeRnlM7xCpGTugErGTZd7_ElKxBLkn7ZBHl003MrNJoEr4bRsziKm Cx3JhFRPjnXT7jCB4N7DSee.OxMKVMRi3gA51_vw5Fvn9uc.PP3fVG4_8x60svuMDW5EPJZLn7BR vUCZdY0QmG9woTdBeaF2luwctPRwqDVkmvSoihzfPBLV885ANwahjgT1dobOFXBMid.oOgdpGHg2 EUXlMONl7AKXq5yNxvw1IDMg6OiIR_R9DI937iFOUNEdgWb7pupnIJXnrv6HJrDDoClDhfWi894M x6jkGr49rr.L56zR7YZBey9OFnUeNBCzJCqSMv3BO0E2nWoI- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ne1.yahoo.com with HTTP; Tue, 24 Mar 2020 01:13:11 +0000 Received: by smtp416.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID eaf3f90a99241b90d501d246ab4bcf2e; Tue, 24 Mar 2020 01:13:08 +0000 (UTC) Subject: Re: [PATCH bpf-next v5 5/7] bpf: lsm: Initialize the BPF LSM hooks To: KP Singh , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org Cc: Brendan Jackman , Florent Revest , Alexei Starovoitov , Daniel Borkmann , James Morris , Kees Cook , Paul Turner , Jann Horn , Florent Revest , Brendan Jackman , Greg Kroah-Hartman , Casey Schaufler References: <20200323164415.12943-1-kpsingh@chromium.org> <20200323164415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68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200323164415.12943-6-kpsingh@chromium.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Mailer: WebService/1.1.15518 hermes Apache-HttpAsyncClient/4.1.4 (Java/1.8.0_242) Content-Length: 5062 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/23/2020 9:44 AM, KP Singh wrote: > From: KP Singh > > The bpf_lsm_ nops are initialized into the LSM framework like any other > LSM. Some LSM hooks do not have 0 as their default return value. The > __weak symbol for these hooks is overridden by a corresponding > definition in security/bpf/hooks.c > > The LSM can be enabled / disabled with CONFIG_LSM. > > Signed-off-by: KP Singh > Reviewed-by: Brendan Jackman > Reviewed-by: Florent Revest > --- > security/Kconfig | 10 ++++---- > security/Makefile | 2 ++ > security/bpf/Makefile | 5 ++++ > security/bpf/hooks.c | 55 +++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 67 insertions(+), 5 deletions(-) > create mode 100644 security/bpf/Makefile > create mode 100644 security/bpf/hooks.c > > diff --git a/security/Kconfig b/security/Kconfig > index 2a1a2d396228..cd3cc7da3a55 100644 > --- a/security/Kconfig > +++ b/security/Kconfig > @@ -277,11 +277,11 @@ endchoice > > config LSM > string "Ordered list of enabled LSMs" > - default "lockdown,yama,loadpin,safesetid,integrity,smack,selinux,tomoyo,apparmor" if DEFAULT_SECURITY_SMACK > - default "lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo" if DEFAULT_SECURITY_APPARMOR > - default "lockdown,yama,loadpin,safesetid,integrity,tomoyo" if DEFAULT_SECURITY_TOMOYO > - default "lockdown,yama,loadpin,safesetid,integrity" if DEFAULT_SECURITY_DAC > - default "lockdown,yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor" > + default "lockdown,yama,loadpin,safesetid,integrity,smack,selinux,tomoyo,apparmor,bpf" if DEFAULT_SECURITY_SMACK > + default "lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf" if DEFAULT_SECURITY_APPARMOR > + default "lockdown,yama,loadpin,safesetid,integrity,tomoyo,bpf" if DEFAULT_SECURITY_TOMOYO > + default "lockdown,yama,loadpin,safesetid,integrity,bpf" if DEFAULT_SECURITY_DAC > + default "lockdown,yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor,bpf" > help > A comma-separated list of LSMs, in initialization order. > Any LSMs left off this list will be ignored. This can be > diff --git a/security/Makefile b/security/Makefile > index 746438499029..22e73a3482bd 100644 > --- a/security/Makefile > +++ b/security/Makefile > @@ -12,6 +12,7 @@ subdir-$(CONFIG_SECURITY_YAMA) += yama > subdir-$(CONFIG_SECURITY_LOADPIN) += loadpin > subdir-$(CONFIG_SECURITY_SAFESETID) += safesetid > subdir-$(CONFIG_SECURITY_LOCKDOWN_LSM) += lockdown > +subdir-$(CONFIG_BPF_LSM) += bpf > > # always enable default capabilities > obj-y += commoncap.o > @@ -30,6 +31,7 @@ obj-$(CONFIG_SECURITY_LOADPIN) += loadpin/ > obj-$(CONFIG_SECURITY_SAFESETID) += safesetid/ > obj-$(CONFIG_SECURITY_LOCKDOWN_LSM) += lockdown/ > obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o > +obj-$(CONFIG_BPF_LSM) += bpf/ > > # Object integrity file lists > subdir-$(CONFIG_INTEGRITY) += integrity > diff --git a/security/bpf/Makefile b/security/bpf/Makefile > new file mode 100644 > index 000000000000..c7a89a962084 > --- /dev/null > +++ b/security/bpf/Makefile > @@ -0,0 +1,5 @@ > +# SPDX-License-Identifier: GPL-2.0 > +# > +# Copyright (C) 2020 Google LLC. > + > +obj-$(CONFIG_BPF_LSM) := hooks.o > diff --git a/security/bpf/hooks.c b/security/bpf/hooks.c > new file mode 100644 > index 000000000000..68e5824868f9 > --- /dev/null > +++ b/security/bpf/hooks.c > @@ -0,0 +1,55 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +/* > + * Copyright (C) 2020 Google LLC. > + */ > +#include > +#include > + > +/* Some LSM hooks do not have 0 as their default return values. Override the > + * __weak definitons generated by default for these hooks > + */ > +noinline int bpf_lsm_inode_getsecurity(struct inode *inode, const char *name, > + void **buffer, bool alloc) > +{ > + return -EOPNOTSUPP; > +} > + > +noinline int bpf_lsm_inode_setsecurity(struct inode *inode, const char *name, > + const void *value, size_t size, > + int flags) > +{ > + return -EOPNOTSUPP; > +} > + > +noinline int bpf_lsm_task_prctl(int option, unsigned long arg2, > + unsigned long arg3, unsigned long arg4, > + unsigned long arg5) > +{ > + return -ENOSYS; > +} > + > +noinline int bpf_lsm_xfrm_state_pol_flow_match(struct xfrm_state *x, > + struct xfrm_policy *xp, > + const struct flowi *fl) > +{ > + return 1; > +} > + > +static struct security_hook_list bpf_lsm_hooks[] __lsm_ro_after_init = { > + #define LSM_HOOK(RET, NAME, ...) LSM_HOOK_INIT(NAME, bpf_lsm_##NAME), > + #include > + #undef LSM_HOOK > +}; > + > +static int __init bpf_lsm_init(void) > +{ > + security_add_hooks(bpf_lsm_hooks, ARRAY_SIZE(bpf_lsm_hooks), "bpf"); > + pr_info("LSM support for eBPF active\n"); > + return 0; > +} > + > +DEFINE_LSM(bpf) = { > + .name = "bpf", > + .init = bpf_lsm_init, Have you given up on the "BPF must be last" requirement? > +};