From: Kui-Feng Lee <thinker.li@gmail.com>
To: bpf@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev,
song@kernel.org, kernel-team@meta.com, andrii@kernel.org
Cc: sinquersw@gmail.com, kuifeng@meta.com,
Kui-Feng Lee <thinker.li@gmail.com>
Subject: [RFC bpf-next 2/5] bpf: Handle BPF_KPTR_USER in verifier.
Date: Wed, 7 Aug 2024 16:57:52 -0700 [thread overview]
Message-ID: <20240807235755.1435806-3-thinker.li@gmail.com> (raw)
In-Reply-To: <20240807235755.1435806-1-thinker.li@gmail.com>
Give PTR_MAYBE_NULL | PTR_UNTRUSTED | MEM_ALLOC | NON_OWN_REF to kptr_user
to the memory pointed by it readable and writable.
Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
---
kernel/bpf/verifier.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index df3be12096cf..84647e599595 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -5340,6 +5340,10 @@ static int map_kptr_match_type(struct bpf_verifier_env *env,
int perm_flags;
const char *reg_name = "";
+ if (kptr_field->type == BPF_KPTR_USER)
+ /* BPF programs should not change any user kptr */
+ return -EACCES;
+
if (btf_is_kernel(reg->btf)) {
perm_flags = PTR_MAYBE_NULL | PTR_TRUSTED | MEM_RCU;
@@ -5483,6 +5487,12 @@ static u32 btf_ld_kptr_type(struct bpf_verifier_env *env, struct btf_field *kptr
ret |= NON_OWN_REF;
} else {
ret |= PTR_UNTRUSTED;
+ if (kptr_field->type == BPF_KPTR_USER)
+ /* In oder to access directly from bpf
+ * programs. NON_OWN_REF make the memory
+ * writable. Check check_ptr_to_btf_access().
+ */
+ ret |= MEM_ALLOC | NON_OWN_REF;
}
return ret;
@@ -5576,6 +5586,7 @@ static int check_map_access(struct bpf_verifier_env *env, u32 regno,
case BPF_KPTR_UNREF:
case BPF_KPTR_REF:
case BPF_KPTR_PERCPU:
+ case BPF_KPTR_USER:
if (src != ACCESS_DIRECT) {
verbose(env, "kptr cannot be accessed indirectly by helper\n");
return -EACCES;
--
2.34.1
next prev parent reply other threads:[~2024-08-07 23:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-07 23:57 [RFC bpf-next 0/5] Share user memory to BPF program through task storage map Kui-Feng Lee
2024-08-07 23:57 ` [RFC bpf-next 1/5] bpf: Parse and support "kptr_user" tag Kui-Feng Lee
2024-08-07 23:57 ` Kui-Feng Lee [this message]
2024-08-12 16:48 ` [RFC bpf-next 2/5] bpf: Handle BPF_KPTR_USER in verifier Alexei Starovoitov
2024-08-13 16:52 ` Kui-Feng Lee
2024-08-13 19:35 ` Alexei Starovoitov
2024-08-13 23:13 ` Kui-Feng Lee
2024-08-07 23:57 ` [RFC bpf-next 3/5] bpf: pin, translate, and unpin __kptr_user from syscalls Kui-Feng Lee
2024-08-08 0:05 ` Kui-Feng Lee
2024-08-08 0:39 ` Kui-Feng Lee
2024-08-12 16:00 ` Kui-Feng Lee
2024-08-12 16:45 ` Alexei Starovoitov
2024-08-12 17:24 ` Kui-Feng Lee
2024-08-12 17:36 ` Alexei Starovoitov
2024-08-12 17:51 ` Kui-Feng Lee
2024-08-07 23:57 ` [RFC bpf-next 4/5] libbpf: define __kptr_user Kui-Feng Lee
2024-08-07 23:57 ` [RFC bpf-next 5/5] selftests/bpf: test __kptr_user on the value of a task storage map Kui-Feng Lee
2024-08-12 16:58 ` Alexei Starovoitov
2024-08-12 17:15 ` Kui-Feng Lee
2024-08-12 17:31 ` Alexei Starovoitov
2024-08-12 18:10 ` Kui-Feng Lee
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=20240807235755.1435806-3-thinker.li@gmail.com \
--to=thinker.li@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@meta.com \
--cc=kuifeng@meta.com \
--cc=martin.lau@linux.dev \
--cc=sinquersw@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