From: "Maciej Żenczykowski" <zenczykowski@gmail.com>
To: "Maciej Żenczykowski" <maze@google.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>
Cc: Linux Network Development Mailing List <netdev@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
BPF Mailing List <bpf@vger.kernel.org>,
"David S . Miller" <davem@davemloft.net>
Subject: [PATCH bpf-next] bpf: allow readonly direct path access for skfilter
Date: Tue, 23 Nov 2021 12:56:07 -0800 [thread overview]
Message-ID: <20211123205607.452497-1-zenczykowski@gmail.com> (raw)
From: Maciej Żenczykowski <maze@google.com>
skfilter bpf programs can read the packet directly via llvm.bpf.load.byte/
/half/word which are 8/16/32-bit primitive bpf instructions and thus
behave basically as well as DPA reads. But there is no 64-bit equivalent,
due to the support for the equivalent 64-bit bpf opcode never having been
added (unclear why, there was a patch posted).
DPA uses a slightly different mechanism, so doesn't suffer this limitation.
Using 64-bit reads, 128-bit ipv6 address comparisons can be done in just
2 steps, instead of the 4 steps needed with llvm.bpf.word.
This should hopefully allow simpler (less instructions, and possibly less
logic and maybe even less jumps) programs. Less jumps may also mean vastly
faster bpf verifier times (it can be exponential in the number of jumps...).
This can be particularly important when trying to do something like scan
a netlink message for a pattern (2000 iteration loop) to decide whether
a message should be dropped, or delivered to userspace (thus waking it up).
I'm requiring CAP_NET_ADMIN because I'm not sure of the security
implications...
Tested: only build tested
Signed-off-by: Maciej Żenczykowski <maze@google.com>
---
kernel/bpf/verifier.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 331b170d9fcc..0c2e25fb9844 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -3258,6 +3258,11 @@ static bool may_access_direct_pkt_data(struct bpf_verifier_env *env,
enum bpf_prog_type prog_type = resolve_prog_type(env->prog);
switch (prog_type) {
+ case BPF_PROG_TYPE_SOCKET_FILTER:
+ if (meta || !capable(CAP_NET_ADMIN))
+ return false;
+ fallthrough;
+
/* Program types only with direct read access go here! */
case BPF_PROG_TYPE_LWT_IN:
case BPF_PROG_TYPE_LWT_OUT:
--
2.34.0.rc2.393.gf8c9666880-goog
next reply other threads:[~2021-11-23 20:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-23 20:56 Maciej Żenczykowski [this message]
2021-11-23 23:02 ` Maciej Żenczykowski
2021-11-27 2:13 ` Song Liu
2021-11-30 1:42 ` 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=20211123205607.452497-1-zenczykowski@gmail.com \
--to=zenczykowski@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=maze@google.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
all inboxes | Powered by JetHome®