bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf 1/2] bpf: Restrict bpf_sys_bpf to CAP_PERFMON
@ 2022-08-16 20:55 YiFei Zhu
  2022-08-16 20:55 ` [PATCH bpf 2/2] bpf: Add WARN_ON for recursive prog_run invocation YiFei Zhu
  2022-08-17 22:30 ` [PATCH bpf 1/2] bpf: Restrict bpf_sys_bpf to CAP_PERFMON patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: YiFei Zhu @ 2022-08-16 20:55 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Jinghao Jia, Daniel Borkmann,
	Alexei Starovoitov, Andrii Nakryiko, Song Liu,
	Stanislav Fomichev, Jason Zhang, Jann Horn, mvle, zohar,
	tyxu.uiuc, security

The verifier cannot perform sufficient validation of any pointers
passed into bpf_attr and treats them as integers rather than pointers.
The helper will then read from arbitrary pointers passed into it.
Restrict the helper to CAP_PERFMON since the security model in
BPF of arbitrary kernel read is CAP_BPF + CAP_PERFMON.

Fixes: af2ac3e13e45 ("bpf: Prepare bpf syscall to be used from kernel and user space.")
Signed-off-by: YiFei Zhu <zhuyifei@google.com>
---
 kernel/bpf/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index a4d40d98428a..27760627370d 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -5197,7 +5197,7 @@ syscall_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 {
 	switch (func_id) {
 	case BPF_FUNC_sys_bpf:
-		return &bpf_sys_bpf_proto;
+		return !perfmon_capable() ? NULL : &bpf_sys_bpf_proto;
 	case BPF_FUNC_btf_find_by_name_kind:
 		return &bpf_btf_find_by_name_kind_proto;
 	case BPF_FUNC_sys_close:
-- 
2.37.1.595.g718a3a8f04-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-08-17 23:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-16 20:55 [PATCH bpf 1/2] bpf: Restrict bpf_sys_bpf to CAP_PERFMON YiFei Zhu
2022-08-16 20:55 ` [PATCH bpf 2/2] bpf: Add WARN_ON for recursive prog_run invocation YiFei Zhu
2022-08-17 22:30   ` Daniel Borkmann
2022-08-17 23:20     ` YiFei Zhu
2022-08-17 22:30 ` [PATCH bpf 1/2] bpf: Restrict bpf_sys_bpf to CAP_PERFMON patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).