Skip to content

Commit 69a9cce

Browse files
bjotokernel-patches-bot
authored andcommitted
selftests/bpf: Avoid running unprivileged tests with alignment requirements
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>
1 parent ac5678a commit 69a9cce

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,9 +1152,15 @@ static void get_unpriv_disabled()
11521152

11531153
static bool test_as_unpriv(struct bpf_test *test)
11541154
{
1155-
return !test->prog_type ||
1156-
test->prog_type == BPF_PROG_TYPE_SOCKET_FILTER ||
1157-
test->prog_type == BPF_PROG_TYPE_CGROUP_SKB;
1155+
bool req_aligned = false;
1156+
1157+
#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1158+
req_aligned = test->flags & F_NEEDS_EFFICIENT_UNALIGNED_ACCESS;
1159+
#endif
1160+
return (!test->prog_type ||
1161+
test->prog_type == BPF_PROG_TYPE_SOCKET_FILTER ||
1162+
test->prog_type == BPF_PROG_TYPE_CGROUP_SKB) &&
1163+
!req_aligned;
11581164
}
11591165

11601166
static int do_test(bool unpriv, unsigned int from, unsigned int to)

0 commit comments

Comments
 (0)