Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3339149ybl; Fri, 20 Dec 2019 07:43:02 -0800 (PST) X-Google-Smtp-Source: APXvYqyxeNLwKKAlvJelkuty1ul9kk0p5LdfuAXhBPCnoPI42HMz29hEwxrIVnonuTfW5MkI65S1 X-Received: by 2002:a05:6830:1251:: with SMTP id s17mr15439175otp.108.1576856582512; Fri, 20 Dec 2019 07:43:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576856582; cv=none; d=google.com; s=arc-20160816; b=zWe1K5e1eCAPv3E8d8U2cS6CxVungD46/JcdqWQP6OlifIuuh7BfdKCrZ5VOlsuT8N hxPJ085RqG0hozfi5cHMQWZYEdsne+edu6Bqgn04TXJuaal6DtJcB1Yw6OU7pE8oBtKx 2mDKctsmmAIdfKgWaamtYaWcBoGzIWiHjOWq7Mc1Os0JlbO8LSEVok/SJwmH9AjkYVbr et2GsHopOZdhpa9ZxE0+arbGCGD2158qakf5ebdTQgphATQCbyr6pDI+h+WLohuG8jI4 3UhomSiuZ6+4kQozSGD5IB9uwxwpnb8p+MDYXfif+m+oUc5n+PWtLc8badg1F7nxrnIj ouIA== 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=6t1SoqwVuPN5RZrWbZ/JmprOHgDz/qxqketSjNkDxYQ=; b=XIV8Insr3MB7TsVk935i53JbRrQ7nfE0jmRTt1vUo05NwikmVhEOwnoV0YILr1Butm d/+7RqrXKrHwQ1n8cA6aQSOtPkiOwIrJoy6aR5OTZLSVSbGhWmjGWI3/c8xr8M0V9CBF gf5UxCp2CRJDLmE5lna3pGL9TH4OcrYA3cazII5pDwSG1cilrZhftAPgf+4iqIwOOsaJ 8GP0rEMsnOVuS/Qk2EUOEFXGTiPBSexOoDhjhcGlJeLll4ZqHK/93884Ly82ymovQ/6c CiSRrfrtcqF20TXzA3Or+ce/3tgdJbUmjASLTgExLS1v974qrJqcmabIjaZdA2DOhxlq 5XFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Za0Ik+yT; 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 r1si3992116otk.251.2019.12.20.07.42.49; Fri, 20 Dec 2019 07:43:02 -0800 (PST) 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=Za0Ik+yT; 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 S1727517AbfLTPmL (ORCPT + 99 others); Fri, 20 Dec 2019 10:42:11 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38761 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727428AbfLTPmJ (ORCPT ); Fri, 20 Dec 2019 10:42:09 -0500 Received: by mail-wr1-f66.google.com with SMTP id y17so9867556wrh.5 for ; Fri, 20 Dec 2019 07:42:06 -0800 (PST) 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=6t1SoqwVuPN5RZrWbZ/JmprOHgDz/qxqketSjNkDxYQ=; b=Za0Ik+yT8Naldmi7JYTHp0+WuOF/mI5o4+6wTWn6WVqreRl0BuH5kZGrkAT65FqOhL ik4xff8Y0GYoREJjknBeExBw0poezt9BfP29XsTroIiGfvbmr3lTTPQvSc4q7cV48WMa JD9UHz8JdBAmhXmajPinQmLxnyjUaYDP/S4UE= 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=6t1SoqwVuPN5RZrWbZ/JmprOHgDz/qxqketSjNkDxYQ=; b=IJ438ZJ7M29jdFzcCrCku9K46Ci/urJzmmo/eVxAH51vMTpt8zKd8dVSGc/t60OWuL IFb9+iOCYjWIXcCbDowzcC93koAyZ1suKXRpOUmqS95kbED4xazJNPHkDdIh5xGiEq1h y9vbv8CYH8otofun2WXUh84Ljik1Cfd37zWw022AVSuS3AnwHQ6UUipl06VLlqcFT4Oe bHrhh74NS28jFngVLJ1R9PYiPwIhNNaiX0tkTW92XSwNBpKa2vNEyS1IhshOv1U5GtjN d04Ov7cv8ne2T9MLJqaBHbfnn0R1OgZNlMFzNUuaPwmZJUFI+WnSqhDgzwe6HtF72Asy Fbwg== X-Gm-Message-State: APjAAAUqv9Wrz82hbUPpKRF+tXdo1JGla9HcA+51sZCEnARza1xJ55Bs uoDP3i+pYC2FmxB5JRTTfbSE3Sh7J1g= X-Received: by 2002:a5d:6349:: with SMTP id b9mr16641794wrw.346.1576856525938; Fri, 20 Dec 2019 07:42:05 -0800 (PST) Received: from kpsingh-kernel.localdomain ([2a00:79e1:abc:308:c46b:b838:66cf:6204]) by smtp.gmail.com with ESMTPSA id x11sm10118062wmg.46.2019.12.20.07.42.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 07:42:05 -0800 (PST) From: KP Singh To: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , James Morris , Kees Cook , Thomas Garnier , Michael Halcrow , Paul Turner , Brendan Gregg , Jann Horn , Matthew Garrett , Christian Brauner , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Florent Revest , Brendan Jackman , Martin KaFai Lau , Song Liu , Yonghong Song , "Serge E. Hallyn" , Mauro Carvalho Chehab , "David S. Miller" , Greg Kroah-Hartman , Nicolas Ferre , Stanislav Fomichev , Quentin Monnet , Andrey Ignatov , Joe Stringer Subject: [PATCH bpf-next v1 02/13] bpf: lsm: Add a skeleton and config options Date: Fri, 20 Dec 2019 16:41:57 +0100 Message-Id: <20191220154208.15895-3-kpsingh@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191220154208.15895-1-kpsingh@chromium.org> References: <20191220154208.15895-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 The LSM can be enabled by CONFIG_SECURITY_BPF. Without CONFIG_SECURITY_BPF_ENFORCE, the LSM will run the attached eBPF programs but not enforce MAC policy based on the return value of the attached programs. Signed-off-by: KP Singh --- MAINTAINERS | 7 +++++++ security/Kconfig | 11 ++++++----- security/Makefile | 2 ++ security/bpf/Kconfig | 25 +++++++++++++++++++++++++ security/bpf/Makefile | 5 +++++ security/bpf/lsm.c | 28 ++++++++++++++++++++++++++++ 6 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 security/bpf/Kconfig create mode 100644 security/bpf/Makefile create mode 100644 security/bpf/lsm.c diff --git a/MAINTAINERS b/MAINTAINERS index 8f075b866aaf..3b82d8ff21fb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3175,6 +3175,13 @@ S: Supported F: arch/x86/net/ X: arch/x86/net/bpf_jit_comp32.c +BPF SECURITY MODULE +M: KP Singh +L: linux-security-module@vger.kernel.org +L: bpf@vger.kernel.org +S: Maintained +F: security/bpf/ + BROADCOM B44 10/100 ETHERNET DRIVER M: Michael Chan L: netdev@vger.kernel.org diff --git a/security/Kconfig b/security/Kconfig index 2a1a2d396228..6f1aab195e7d 100644 --- a/security/Kconfig +++ b/security/Kconfig @@ -236,6 +236,7 @@ source "security/tomoyo/Kconfig" source "security/apparmor/Kconfig" source "security/loadpin/Kconfig" source "security/yama/Kconfig" +source "security/bpf/Kconfig" source "security/safesetid/Kconfig" source "security/lockdown/Kconfig" @@ -277,11 +278,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 be1dd9d2cb2f..50e6821dd7b7 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_SECURITY_BPF) += bpf # always enable default capabilities obj-y += commoncap.o @@ -29,6 +30,7 @@ obj-$(CONFIG_SECURITY_YAMA) += yama/ obj-$(CONFIG_SECURITY_LOADPIN) += loadpin/ obj-$(CONFIG_SECURITY_SAFESETID) += safesetid/ obj-$(CONFIG_SECURITY_LOCKDOWN_LSM) += lockdown/ +obj-$(CONFIG_SECURITY_BPF) += bpf/ obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o # Object integrity file lists diff --git a/security/bpf/Kconfig b/security/bpf/Kconfig new file mode 100644 index 000000000000..1aaa1340e795 --- /dev/null +++ b/security/bpf/Kconfig @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright 2019 Google LLC. + +config SECURITY_BPF + bool "BPF-based MAC and audit policy" + depends on SECURITY + depends on SECURITYFS + depends on BPF + depends on BPF_SYSCALL + help + This enables instrumentation of the security hooks with + eBPF programs. The LSM creates per-hook files in securityfs to which + eBPF programs can be attached. + + If you are unsure how to answer this question, answer N. + +config SECURITY_BPF_ENFORCE + bool "Deny operations based on the evaluation of the attached programs" + depends on SECURITY_BPF + help + eBPF programs attached to hooks can be used for both auditing and + enforcement. Enabling enforcement implies that the evaluation result + from the attached eBPF programs will allow or deny the operation + guarded by the security hook. diff --git a/security/bpf/Makefile b/security/bpf/Makefile new file mode 100644 index 000000000000..26a0ab6f99b7 --- /dev/null +++ b/security/bpf/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright 2019 Google LLC. + +obj-$(CONFIG_SECURITY_BPF) := lsm.o diff --git a/security/bpf/lsm.c b/security/bpf/lsm.c new file mode 100644 index 000000000000..fe5c65bbdd45 --- /dev/null +++ b/security/bpf/lsm.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright 2019 Google LLC. + */ + +#include + +static int process_execution(struct linux_binprm *bprm) +{ + return 0; +} + +static struct security_hook_list lsm_hooks[] __lsm_ro_after_init = { + LSM_HOOK_INIT(bprm_check_security, process_execution), +}; + +static int __init lsm_init(void) +{ + security_add_hooks(lsm_hooks, ARRAY_SIZE(lsm_hooks), "bpf"); + pr_info("eBPF and LSM are friends now.\n"); + return 0; +} + +DEFINE_LSM(bpf) = { + .name = "bpf", + .init = lsm_init, +}; -- 2.20.1