From: Daniel Borkmann <daniel@iogearbox.net>
To: ast@kernel.org
Cc: netdev@vger.kernel.org, Daniel Borkmann <daniel@iogearbox.net>
Subject: [PATCH bpf 7/7] bpf: make direct packet write unclone more robust
Date: Wed, 24 Oct 2018 22:05:49 +0200 [thread overview]
Message-ID: <20181024200549.8516-8-daniel@iogearbox.net> (raw)
In-Reply-To: <20181024200549.8516-1-daniel@iogearbox.net>
Given this seems to be quite fragile and can easily slip through the
cracks, lets make direct packet write more robust by requiring that
future program types which allow for such write must provide a prologue
callback. In case of XDP and sk_msg it's noop, thus add a generic noop
handler there. The latter starts out with NULL data/data_end unconditionally
when sg pages are shared.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
---
kernel/bpf/verifier.c | 6 +++++-
net/core/filter.c | 11 +++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 5fc9a65..171a2c8 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -5709,7 +5709,11 @@ static int convert_ctx_accesses(struct bpf_verifier_env *env)
bool is_narrower_load;
u32 target_size;
- if (ops->gen_prologue) {
+ if (ops->gen_prologue || env->seen_direct_write) {
+ if (!ops->gen_prologue) {
+ verbose(env, "bpf verifier is misconfigured\n");
+ return -EINVAL;
+ }
cnt = ops->gen_prologue(insn_buf, env->seen_direct_write,
env->prog);
if (cnt >= ARRAY_SIZE(insn_buf)) {
diff --git a/net/core/filter.c b/net/core/filter.c
index 3fdddfa..cd648d0 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -5644,6 +5644,15 @@ static bool sock_filter_is_valid_access(int off, int size,
prog->expected_attach_type);
}
+static int bpf_noop_prologue(struct bpf_insn *insn_buf, bool direct_write,
+ const struct bpf_prog *prog)
+{
+ /* Neither direct read nor direct write requires any preliminary
+ * action.
+ */
+ return 0;
+}
+
static int bpf_unclone_prologue(struct bpf_insn *insn_buf, bool direct_write,
const struct bpf_prog *prog, int drop_verdict)
{
@@ -7210,6 +7219,7 @@ const struct bpf_verifier_ops xdp_verifier_ops = {
.get_func_proto = xdp_func_proto,
.is_valid_access = xdp_is_valid_access,
.convert_ctx_access = xdp_convert_ctx_access,
+ .gen_prologue = bpf_noop_prologue,
};
const struct bpf_prog_ops xdp_prog_ops = {
@@ -7308,6 +7318,7 @@ const struct bpf_verifier_ops sk_msg_verifier_ops = {
.get_func_proto = sk_msg_func_proto,
.is_valid_access = sk_msg_is_valid_access,
.convert_ctx_access = sk_msg_convert_ctx_access,
+ .gen_prologue = bpf_noop_prologue,
};
const struct bpf_prog_ops sk_msg_prog_ops = {
--
2.9.5
next prev parent reply other threads:[~2018-10-25 4:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-24 20:05 [PATCH bpf 0/7] Batch of direct packet access fixes for BPF Daniel Borkmann
2018-10-24 20:05 ` [PATCH bpf 1/7] bpf: fix test suite to enable all unpriv program types Daniel Borkmann
2018-10-24 20:05 ` [PATCH bpf 2/7] bpf: disallow direct packet access for unpriv in cg_skb Daniel Borkmann
2018-10-24 20:05 ` [PATCH bpf 3/7] bpf: fix direct packet access for flow dissector progs Daniel Borkmann
2018-10-24 20:05 ` [PATCH bpf 4/7] bpf: fix cg_skb types to hint access type in may_access_direct_pkt_data Daniel Borkmann
2018-10-24 20:05 ` [PATCH bpf 5/7] bpf: fix direct packet write into pop/peek helpers Daniel Borkmann
2018-10-24 22:30 ` Mauricio Vasquez
2018-10-24 20:05 ` [PATCH bpf 6/7] bpf: fix leaking uninitialized memory on " Daniel Borkmann
2018-10-24 22:08 ` Mauricio Vasquez
2018-10-24 20:05 ` Daniel Borkmann [this message]
2018-10-24 21:42 ` [PATCH bpf 7/7] bpf: make direct packet write unclone more robust Song Liu
2018-10-24 22:08 ` Daniel Borkmann
2018-10-24 23:36 ` Song Liu
2018-10-24 21:43 ` [PATCH bpf 0/7] Batch of direct packet access fixes for BPF Song Liu
2018-10-26 0:11 ` 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=20181024200549.8516-8-daniel@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=ast@kernel.org \
--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).