Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4054838ybb; Mon, 23 Mar 2020 12:35:25 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvqkmImM1kBlRYmX2W80QkfWpeT3kjyjRkcY5XDn7Wnfnrdqd0i8YHl8dLazUejn650nYKE X-Received: by 2002:aca:b245:: with SMTP id b66mr764969oif.170.1584992125815; Mon, 23 Mar 2020 12:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584992125; cv=none; d=google.com; s=arc-20160816; b=lg0Ex8JEzFBLLUOKubSkeuAysl8lEMKzavjPD1+P8/cg2JgMH/4rqJSnjRx4Y09PWl 9Djb8G20wLrCWPkpclNWM8sctQ/REo9stQRyQV5k18qmfErekLCqyqNQct6toLuVBORj bcXplnWyhDUrPHhUGKwPnC5iDf6NDAMjhb18XBbuJ8LBWZUOBsl/izDNXzZhy3ajPjN/ 3CTxeT7i9xWIzkwYfde9M/8/WukMJdFfLReN6DB2qTNvUUgGrnmHvrLdG9NdC/Gvs1rx Xop78/z7gHrvD1eS6dBkXbTPMzNCTGQGLrNcvUxm9WIMux52WKl9B9j+c5bFZkWgu5Ly riMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=QK1jZXR8lSHrMmCV4BaYuYh+4tyJTB+kyT8mffooOtA=; b=oygorgk5wFo1nc3VbbGQQhjkLOF8Pt29G97mjuIlDQcWer7yqZKLQSpYkdUWn4Fpi9 q7b9aNk96Ww09n2YmCmM7ION70GNQ1PLwpc0t0ZRxozBM7dYuDbXOdvBAfow8u7dWCYi UNY+MZNS9WeSt7Wv88a0aeJPhH2amYSTPY9ESvf9cWqVMZkYW2dQDM3eTIqAseE2cc1c LJC5TH8YebepC84nAcO48wJjDCdK+Panb4DhjA7iDzMLWttuJs8oLXPdI+JKvumdV6Yu W5Fr2+YOyhm/ZyLwqzuGEuPMX3j/urz1AwEN6w68He1QfxBTKB55clKPjncbjzGQ5Vx0 JVQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HY0cWUyi; 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 a11si8262635otp.55.2020.03.23.12.35.11; Mon, 23 Mar 2020 12:35:25 -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=HY0cWUyi; 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 S1727903AbgCWTds (ORCPT + 99 others); Mon, 23 Mar 2020 15:33:48 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:35720 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727838AbgCWTds (ORCPT ); Mon, 23 Mar 2020 15:33:48 -0400 Received: by mail-pj1-f68.google.com with SMTP id g9so310596pjp.0 for ; Mon, 23 Mar 2020 12:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=QK1jZXR8lSHrMmCV4BaYuYh+4tyJTB+kyT8mffooOtA=; b=HY0cWUyiO+tlb7hC5bbViSYOfF0QR6yS/1XYhTW2nFMIXjADrDzAxBWqUWl09jzXYi 3tQQblO3u2Xd6Lslklk+9nGAGLXb0BWsi83Uc5JrUD4ztiVDckfTvwJqUaPWGCMGQvQo wMTNDwOJIF8n6FNk1wvZaHcl9wbszdMe71fUY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QK1jZXR8lSHrMmCV4BaYuYh+4tyJTB+kyT8mffooOtA=; b=tg5YKg0xDdjT1CX9jS267eFawgXKDSGKaaTHB+8j9o2azWgjP3HfHYc8O1UpZXKnxR Xe0ptZtZUMCDtthiCo+LvQpA666Ivy8lGu88j8gWVRJYaGl14Xkvje37cMlwIPLfUGTA svss2X5xFdSJBgfOEnlYEgtdCtwKWJpLzzpv0F/vFoLfUk+00xoexORpB4EeTw6oQu3p lYIYgVD/vsFR51E8S1GH2iwCn1NfGOzSzRFQ5dozeNvK0w0ZY0uEOymGKaVl4fNX40qH MUSpAm2PUoMGjLqF8CH9OKI2bjnPAfZ+ZUiTSv4jmU4xCgDj21/lT/x383LgkELeFrUk Xrtw== X-Gm-Message-State: ANhLgQ0J+THz46BqcZWTlfeGu5KP0/NDhzvK95B54PyG9j17/FCI8IBj xzIi9WoYRreXWmKic4RBtM/BKw== X-Received: by 2002:a17:90a:1a43:: with SMTP id 3mr993827pjl.35.1584992026093; Mon, 23 Mar 2020 12:33:46 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id f6sm14827161pfk.99.2020.03.23.12.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 12:33:45 -0700 (PDT) Date: Mon, 23 Mar 2020 12:33:44 -0700 From: Kees Cook To: KP Singh Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org, Brendan Jackman , Florent Revest , Alexei Starovoitov , Daniel Borkmann , James Morris , 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: <202003231233.9C1E0B830@keescook> References: <20200323164415.12943-1-kpsingh@chromium.org> <20200323164415.12943-4-kpsingh@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200323164415.12943-4-kpsingh@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 23, 2020 at 05:44:11PM +0100, 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: Kees Cook -Kees > 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__) {} > + > +#include > +#undef LSM_HOOK > > const struct bpf_prog_ops lsm_prog_ops = { > }; > -- > 2.20.1 > -- Kees Cook