Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3901251ybb; Mon, 23 Mar 2020 09:46:06 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtRtzxySHcQeQnKnGFPGG3lTDY5wi3x3oO9CumhgUDlKGGho/PI4/XyYdVwDfb4unvJ9+og X-Received: by 2002:a05:6830:1d7:: with SMTP id r23mr19558918ota.153.1584981966447; Mon, 23 Mar 2020 09:46:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584981966; cv=none; d=google.com; s=arc-20160816; b=ei//lEikx8uvoIhbT+bnt3FJ66Il1snWcLTipQ9nikIncxxotMO+31789vqQs+7qE/ DlwZDOyzjtIsQrT26cY7zlytJJ0Ap4kba6a6G9Sv2wn6Kjtx2TxOaWuDR/nzuHlS4z7Z QREnkMeLDvip8E33DBeRseFUR991rZ24PYK1MGEhBihyDFn6BXdqNs0MgPs0NppqRPVm 9klLOJqqOr+0Bs6r91BsnOem14iigjGAzN7/z4g1yWkaurixjuEdSbc7ZQRp2sXqB1Pc Y6/JQKPrur9xvs6bSDpnhXuWN869m44cU/TQwHHK5yJGed2Pva3bnjlV9PDcETiOdBIH 2mKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GlA7urqMw8mKHvI9rDt37xMzrwfcfL0wKrtQ00PyQpc=; b=t4bB0fwzbUlNasG5hrLnGXD8i7dtnM5u+q5x9ey5P6lQUOOCyuaL84kxJDuWYJZitW viZZk0rcFVUV0SWwUUvmOpWTnMUWONvRX5tZaDejhY+cZ2L/bBJ8F2IjwbDonmx6nulg yLZvKmMjk+bwQErwl5muWb4D79jbnPkaoLjOpRl/WT9NIf0opFhvEDh/0WAz9uuSDmQn 7/CxfAF29iLuB5XCw7DGbCGU1fKH53NT6CdiXY/2ntRpqNynjhkRhjt2xLBO85QZ8iU3 JuQIkqu5RAoSuqIzB+vxoh54Wiza//dyhsd9eXnqE7UEPEngo8VqdrzECk+G33iLfHdo 3xCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Is/fLBhX"; 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 f26si8152953otc.182.2020.03.23.09.45.52; Mon, 23 Mar 2020 09:46:06 -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="Is/fLBhX"; 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 S1727857AbgCWQpA (ORCPT + 99 others); Mon, 23 Mar 2020 12:45:00 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44510 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727644AbgCWQod (ORCPT ); Mon, 23 Mar 2020 12:44:33 -0400 Received: by mail-wr1-f65.google.com with SMTP id m17so8974563wrw.11 for ; Mon, 23 Mar 2020 09:44:32 -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=GlA7urqMw8mKHvI9rDt37xMzrwfcfL0wKrtQ00PyQpc=; b=Is/fLBhXkfsoYTWL+rb7nbgKjQZDSHeREiaENX/ryr1Klw/wT/paImg2ZmlmRU0LM+ ye/muNgE3Jxcw0uJbW0K2yyK5O8Xv+MkovtpqtVyRzdBCIVq49/Rd6tRgP1cSIBIpK3h G0DKJOPlqTSzhRvHt99l0hw3zeL0nmEbFCjMc= 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=GlA7urqMw8mKHvI9rDt37xMzrwfcfL0wKrtQ00PyQpc=; b=f1uVpEOhS/yDcOy66CPrpT1W5qR1Z/OjcCzhnFWg6ZC9C7eZ+5Pqjoc79Vex1dqtw2 C9lsQE94NYm42zo2zmRw5WaGfSjZrU74YEqAkSvkXehcgT1X+PFmuPuKAB5G7v25AKpL TBPZhyhXiPIYLz0wKZeqmX1v3Yr6JMT/+DAXPUqirN4fcCe+NVJDaN3CpG+O7gJ2sClR HshoQ4T2qGtF5ckHVuO2S6SnrONuwbUlypScIzGkznRSD+6ykie+GkctjQefrOxaPczK d0MT0V2URnh1z/x+3tF+DF4fuMMQ1XYmK9dTBtqpqJ2+mpmnUo40Ufa2qloHafBDqoyk Jv0w== X-Gm-Message-State: ANhLgQ3YBm01qJkvTiO+CtjGp7hoDQ2/DMbsDOsL9tELMZjwEMExUs1e XVBOQK+KQsouRT10Is8DLso6PGCwMoQ= X-Received: by 2002:a5d:54cb:: with SMTP id x11mr20563706wrv.179.1584981871985; Mon, 23 Mar 2020 09:44:31 -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 l8sm199874wmj.2.2020.03.23.09.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 09:44:31 -0700 (PDT) From: KP Singh To: 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 Subject: [PATCH bpf-next v5 3/7] bpf: lsm: provide attachment points for BPF LSM programs Date: Mon, 23 Mar 2020 17:44:11 +0100 Message-Id: <20200323164415.12943-4-kpsingh@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200323164415.12943-1-kpsingh@chromium.org> References: <20200323164415.12943-1-kpsingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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__) {} + +#include +#undef LSM_HOOK const struct bpf_prog_ops lsm_prog_ops = { }; -- 2.20.1