From: "Björn Töpel" <bjorn.topel@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org,
bpf@vger.kernel.org
Cc: "Björn Töpel" <bjorn.topel@gmail.com>,
linux-riscv@lists.infradead.org, xi.wang@gmail.com,
luke.r.nels@gmail.com
Subject: [PATCH bpf-next 2/3] selftests/bpf: Avoid running unprivileged tests with alignment requirements
Date: Tue, 17 Nov 2020 09:26:37 +0100 [thread overview]
Message-ID: <20201117082638.43675-3-bjorn.topel@gmail.com> (raw)
In-Reply-To: <20201117082638.43675-1-bjorn.topel@gmail.com>
Some architectures have strict alignment requirements. In that case,
the BPF verifier detects if a program has unaligned accesses and
rejects them. A user can pass BPF_F_ANY_ALIGNMENT to a program to
override this check. That, however, will only work when a privileged
user loads a program. A unprivileged user loading a program with this
flag will be rejected prior entering the verifier.
Hence, it does not make sense to load unprivileged programs without
strict alignment when testing the verifier. This patch avoids exactly
that.
Signed-off-by: Björn Töpel <bjorn.topel@gmail.com>
---
tools/testing/selftests/bpf/test_verifier.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 9be395d9dc64..2075f6a98813 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -1152,9 +1152,15 @@ static void get_unpriv_disabled()
static bool test_as_unpriv(struct bpf_test *test)
{
- return !test->prog_type ||
- test->prog_type == BPF_PROG_TYPE_SOCKET_FILTER ||
- test->prog_type == BPF_PROG_TYPE_CGROUP_SKB;
+ bool req_aligned = false;
+
+#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
+ req_aligned = test->flags & F_NEEDS_EFFICIENT_UNALIGNED_ACCESS;
+#endif
+ return (!test->prog_type ||
+ test->prog_type == BPF_PROG_TYPE_SOCKET_FILTER ||
+ test->prog_type == BPF_PROG_TYPE_CGROUP_SKB) &&
+ !req_aligned;
}
static int do_test(bool unpriv, unsigned int from, unsigned int to)
--
2.27.0
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2020-11-17 8:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-17 8:26 [PATCH bpf-next 0/3] RISC-V selftest/bpf fixes Björn Töpel
2020-11-17 8:26 ` [PATCH bpf-next 1/3] selftests/bpf: Fix broken riscv build Björn Töpel
2020-11-18 1:43 ` Andrii Nakryiko
2020-11-18 6:26 ` Björn Töpel
2020-11-17 8:26 ` Björn Töpel [this message]
2020-11-18 1:43 ` [PATCH bpf-next 2/3] selftests/bpf: Avoid running unprivileged tests with alignment requirements Andrii Nakryiko
2020-11-18 6:32 ` Björn Töpel
2020-11-17 8:26 ` [PATCH bpf-next 3/3] selftests/bpf: Mark tests that require unaligned memory access Björn Töpel
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=20201117082638.43675-3-bjorn.topel@gmail.com \
--to=bjorn.topel@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=linux-riscv@lists.infradead.org \
--cc=luke.r.nels@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=xi.wang@gmail.com \
/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