[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211203191844.69709-3-mcroce@linux.microsoft.com>
Date: Fri, 3 Dec 2021 20:18:43 +0100
From: Matteo Croce <mcroce@...ux.microsoft.com>
To: bpf@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Jakub Kicinski <kuba@...nel.org>,
Jesper Dangaard Brouer <hawk@...nel.org>,
keyrings@...r.kernel.org, linux-crypto@...r.kernel.org,
Luca Boccassi <bluca@...ian.org>,
Lorenzo Bianconi <lorenzo@...nel.org>
Subject: [PATCH bpf-next 2/3] bpf: add option to require BPF signature
From: Matteo Croce <mcroce@...rosoft.com>
Add a compile time option which makes the BPF signature mandatory,
i.e. all programs without signature or with an invalid one are rejected.
CO-RE programs load a program of type BPF_PROG_TYPE_SYSCALL, which then
uses the bpf() syscall to load the final program. This one won't have any
signature, so never enforce signature for programs coming from the kernel.
This happens when loading a program with a missing signature:
# ip link set lo xdp object xdp.o
[ 8677.652546] Rejecting BPF '' with no signature
Signed-off-by: Matteo Croce <mcroce@...rosoft.com>
---
kernel/bpf/Kconfig | 6 ++++++
kernel/bpf/syscall.c | 4 ++++
2 files changed, 10 insertions(+)
diff --git a/kernel/bpf/Kconfig b/kernel/bpf/Kconfig
index 735979bb8672..fe6e84abe84c 100644
--- a/kernel/bpf/Kconfig
+++ b/kernel/bpf/Kconfig
@@ -87,6 +87,12 @@ config BPF_SIG
Check BPF programs for valid signatures upon load: the signature
is passed via the bpf() syscall together with the instructions.
+config BPF_SIG_FORCE
+ bool "Require BPF to be validly signed"
+ depends on BPF_SIG
+ help
+ Reject unsigned BPF or signed BPF for which we don't have a key.
+
source "kernel/bpf/preload/Kconfig"
config BPF_LSM
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 5aaa74a72b46..9e36614719fd 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -2340,6 +2340,10 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr)
prog->aux->name, ERR_PTR(err));
goto free_prog_sec;
}
+ } else if (IS_ENABLED(CONFIG_BPF_SIG_FORCE) && !uattr.is_kernel) {
+ pr_warn("Rejecting BPF '%s' with no signature\n", prog->aux->name);
+ err = -EKEYREJECTED;
+ goto free_prog_sec;
}
#endif
--
2.33.1
Powered by blists - more mailing lists