From patchwork Fri Mar 27 19:28:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: KP Singh X-Patchwork-Id: 11463017 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 11F1E1667 for ; Fri, 27 Mar 2020 19:29:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB17520838 for ; Fri, 27 Mar 2020 19:29:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Z7zva+1H" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727800AbgC0T3D (ORCPT ); Fri, 27 Mar 2020 15:29:03 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:54771 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727575AbgC0T3C (ORCPT ); Fri, 27 Mar 2020 15:29:02 -0400 Received: by mail-wm1-f66.google.com with SMTP id c81so12639387wmd.4 for ; Fri, 27 Mar 2020 12:29:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R06x0mive4StEspSChp8nXo8gNb0lFU1htQmKzctqw8=; b=Z7zva+1H9Ng1imInyY27caOwyw10M/swWEMpQ8Mt/HV3BUB/lM080e5kqPFcP/eaHG QYVhrR6LeZ3TSB9Ndst735+/YfMRd7ZHauPWZHM14E6UDuQIcCh2+zP2d87Y0vh0xexN IUXiTfsOMwkFhwexpe/Nxa8FuGodE/f95Vd34= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R06x0mive4StEspSChp8nXo8gNb0lFU1htQmKzctqw8=; b=uRa01lWLtbqhmTB8v86iFVcC4g/KXEBGOdYjG5O+tURq2xf3ONdCeK82AQSh6viab4 dg9bk3hs9INrRGKC+122VkmlKegpW4/N4PwMmQYjRHGDZUtbrgkcQoxWEjfrS0YL7x0U AG8FMoEngwB2xIHLlh3u+1KQHsZmvDV7RjNN6j2xxfr1EjK5lFV//GOeCqafxFlGUTHs cGfitR93xjO5b9a7P29k8Sfjpe0jdmSmAXxIj2qzgl4kepOz5AXcXS2Xe3VvqOqjikAd PSDtA9ourguhTeDJkUPpdj/AuxHfbLlp/a/CbuU5envHQaxNixPEie/Aid17XY5NaaJu 5U9g== X-Gm-Message-State: ANhLgQ10Xg3niXkJhoRQLl3EZIK8EV675rmYub1Kfp55+m5+jbDmG6HG tRteywYzzJlcpiRkw/0HyYhAlw== X-Google-Smtp-Source: ADFU+vsURyzyLHsYKVKSarKoYYkz4RkDde+olmwWaEXzivFrIaIwr/kh4Yuwm/+7Oys2J37oKItZtw== X-Received: by 2002:a1c:1dcf:: with SMTP id d198mr255524wmd.121.1585337341148; Fri, 27 Mar 2020 12:29:01 -0700 (PDT) Received: from kpsingh-kernel.localdomain (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id h132sm9828537wmf.18.2020.03.27.12.28.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2020 12:29:00 -0700 (PDT) From: KP Singh To: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org Cc: Yonghong Song , James Morris , Brendan Jackman , Florent Revest , Kees Cook , Alexei Starovoitov , Daniel Borkmann , James Morris , Paul Turner , Jann Horn , Florent Revest , Brendan Jackman , Greg Kroah-Hartman Subject: [PATCH bpf-next v8 3/8] bpf: lsm: provide attachment points for BPF LSM programs Date: Fri, 27 Mar 2020 20:28:49 +0100 Message-Id: <20200327192854.31150-4-kpsingh@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200327192854.31150-1-kpsingh@chromium.org> References: <20200327192854.31150-1-kpsingh@chromium.org> MIME-Version: 1.0 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: From: KP Singh When CONFIG_BPF_LSM is enabled, nop functions, bpf_lsm_, are generated for each LSM hook. These functions are initialized as LSM hooks in a subsequent patch. Signed-off-by: KP Singh Acked-by: Yonghong Song Acked-by: James Morris Reviewed-by: Brendan Jackman Reviewed-by: Florent Revest Reviewed-by: Kees Cook --- include/linux/bpf_lsm.h | 22 ++++++++++++++++++++++ kernel/bpf/bpf_lsm.c | 14 ++++++++++++++ 2 files changed, 36 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..83b96895829f --- /dev/null +++ b/include/linux/bpf_lsm.h @@ -0,0 +1,22 @@ +/* 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, DEFAULT, 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..3b3bbb28603e 100644 --- a/kernel/bpf/bpf_lsm.c +++ b/kernel/bpf/bpf_lsm.c @@ -7,6 +7,20 @@ #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. + */ +#define LSM_HOOK(RET, DEFAULT, NAME, ...) \ +noinline RET bpf_lsm_##NAME(__VA_ARGS__) \ +{ \ + return DEFAULT; \ +} + +#include +#undef LSM_HOOK const struct bpf_prog_ops lsm_prog_ops = { };