From: Artem Savkov <asavkov@redhat.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Andrea Arcangeli <aarcange@redhat.com>,
Daniel Vacek <dvacek@redhat.com>, Jiri Olsa <olsajiri@gmail.com>,
Song Liu <song@kernel.org>, Artem Savkov <asavkov@redhat.com>
Subject: [PATCH bpf-next 2/4] bpf: add destructive kfunc set
Date: Wed, 20 Jul 2022 13:46:50 +0200 [thread overview]
Message-ID: <20220720114652.3020467-3-asavkov@redhat.com> (raw)
In-Reply-To: <20220720114652.3020467-1-asavkov@redhat.com>
Add BTF_KFUNC_TYPE_DESTRUCTIVE and a new destructive_set in struct
btf_kfunc_id_set. Functions in this set will require CAP_SYS_BOOT
capabilities and BPF_F_DESTRUCTIVE flag.
Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
include/linux/btf.h | 2 ++
kernel/bpf/verifier.c | 12 ++++++++++++
2 files changed, 14 insertions(+)
diff --git a/include/linux/btf.h b/include/linux/btf.h
index 1bfed7fa04287..6c58aa70e8125 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -18,6 +18,7 @@ enum btf_kfunc_type {
BTF_KFUNC_TYPE_RELEASE,
BTF_KFUNC_TYPE_RET_NULL,
BTF_KFUNC_TYPE_KPTR_ACQUIRE,
+ BTF_KFUNC_TYPE_DESTRUCTIVE,
BTF_KFUNC_TYPE_MAX,
};
@@ -37,6 +38,7 @@ struct btf_kfunc_id_set {
struct btf_id_set *release_set;
struct btf_id_set *ret_null_set;
struct btf_id_set *kptr_acquire_set;
+ struct btf_id_set *destructive_set;
};
struct btf_id_set *sets[BTF_KFUNC_TYPE_MAX];
};
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index c59c3df0fea61..064035e70deac 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -7582,6 +7582,18 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
return -EACCES;
}
+ if (btf_kfunc_id_set_contains(desc_btf, resolve_prog_type(env->prog),
+ BTF_KFUNC_TYPE_DESTRUCTIVE, func_id)) {
+ if (!env->prog->aux->destructive) {
+ verbose(env, "destructive kfunc calls require BPF_F_DESTRUCTIVE flag\n");
+ return -EACCES;
+ }
+ if (!capable(CAP_SYS_BOOT)) {
+ verbose(env, "destructive kfunc calls require CAP_SYS_BOOT capabilities\n");
+ return -EACCES;
+ }
+ }
+
acq = btf_kfunc_id_set_contains(desc_btf, resolve_prog_type(env->prog),
BTF_KFUNC_TYPE_ACQUIRE, func_id);
--
2.35.3
next prev parent reply other threads:[~2022-07-20 11:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-20 11:46 [PATCH bpf-next 0/4] destructive bpf kfuncs (was: bpf_panic) Artem Savkov
2022-07-20 11:46 ` [PATCH bpf-next 1/4] bpf: add BPF_F_DESTRUCTIVE flag for BPF_PROG_LOAD Artem Savkov
2022-07-21 14:02 ` Alexei Starovoitov
2022-07-22 4:18 ` Artem Savkov
2022-07-22 4:32 ` Alexei Starovoitov
2022-07-25 9:27 ` Artem Savkov
2022-07-25 19:23 ` Daniel Xu
2022-07-20 11:46 ` Artem Savkov [this message]
2022-07-20 11:46 ` [PATCH bpf-next 3/4] selftests/bpf: add destructive kfunc tests Artem Savkov
2022-07-20 11:46 ` [PATCH bpf-next 4/4] bpf: export crash_kexec() as destructive kfunc Artem Savkov
2022-07-21 13:00 ` [PATCH bpf-next 0/4] destructive bpf kfuncs (was: bpf_panic) Daniel Borkmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220720114652.3020467-3-asavkov@redhat.com \
--to=asavkov@redhat.com \
--cc=aarcange@redhat.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dvacek@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olsajiri@gmail.com \
--cc=song@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).