From: Daniel Borkmann <daniel@iogearbox.net>
To: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org, ast@kernel.org,
andrii.nakryiko@gmail.com, john.fastabend@gmail.com,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andriin@fb.com>
Subject: [PATCH bpf-next v3 3/8] bpf: Make use of probe_user_write in probe write helper
Date: Sat, 2 Nov 2019 00:17:58 +0100 [thread overview]
Message-ID: <841c461781874c07a0ee404a454c3bc0459eed30.1572649915.git.daniel@iogearbox.net> (raw)
In-Reply-To: <cover.1572649915.git.daniel@iogearbox.net>
Convert the bpf_probe_write_user() helper to probe_user_write() such that
writes are not attempted under KERNEL_DS anymore which is buggy as kernel
and user space pointers can have overlapping addresses. Also, given we have
the access_ok() check inside probe_user_write(), the helper doesn't need
to do it twice.
Fixes: 96ae52279594 ("bpf: Add bpf_probe_write_user BPF helper to be called in tracers")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andriin@fb.com>
---
kernel/trace/bpf_trace.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 571c25d60710..91eb17ac4bb6 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -163,7 +163,7 @@ static const struct bpf_func_proto bpf_probe_read_proto = {
.arg3_type = ARG_ANYTHING,
};
-BPF_CALL_3(bpf_probe_write_user, void *, unsafe_ptr, const void *, src,
+BPF_CALL_3(bpf_probe_write_user, void __user *, unsafe_ptr, const void *, src,
u32, size)
{
/*
@@ -186,10 +186,8 @@ BPF_CALL_3(bpf_probe_write_user, void *, unsafe_ptr, const void *, src,
return -EPERM;
if (unlikely(!nmi_uaccess_okay()))
return -EPERM;
- if (!access_ok(unsafe_ptr, size))
- return -EPERM;
- return probe_kernel_write(unsafe_ptr, src, size);
+ return probe_user_write(unsafe_ptr, src, size);
}
static const struct bpf_func_proto bpf_probe_write_user_proto = {
--
2.21.0
next prev parent reply other threads:[~2019-11-01 23:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-01 23:17 [PATCH bpf-next v3 0/8] Fix BPF probe memory helpers Daniel Borkmann
2019-11-01 23:17 ` [PATCH bpf-next v3 1/8] uaccess: Add non-pagefault user-space write function Daniel Borkmann
2019-11-01 23:17 ` [PATCH bpf-next v3 2/8] uaccess: Add strict non-pagefault kernel-space read function Daniel Borkmann
2019-11-01 23:17 ` Daniel Borkmann [this message]
2019-11-01 23:17 ` [PATCH bpf-next v3 4/8] bpf: Add probe_read_{user,kernel} and probe_read_{user,kernel}_str helpers Daniel Borkmann
2019-11-01 23:18 ` [PATCH bpf-next v3 5/8] bpf: Switch BPF probe insns to bpf_probe_read_kernel Daniel Borkmann
2019-11-01 23:18 ` [PATCH bpf-next v3 6/8] bpf, samples: Use bpf_probe_read_user where appropriate Daniel Borkmann
2019-11-01 23:18 ` [PATCH bpf-next v3 7/8] bpf, testing: Convert prog tests to probe_read_{user,kernel}{,_str} helper Daniel Borkmann
2019-11-01 23:18 ` [PATCH bpf-next v3 8/8] bpf, testing: Add selftest to read/write sockaddr from user space Daniel Borkmann
2019-11-02 20:08 ` [PATCH bpf-next v3 0/8] Fix BPF probe memory helpers Alexei Starovoitov
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=841c461781874c07a0ee404a454c3bc0459eed30.1572649915.git.daniel@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=andrii.nakryiko@gmail.com \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=john.fastabend@gmail.com \
--cc=netdev@vger.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).