Commit 4e99d115 authored by Andrii Nakryiko's avatar Andrii Nakryiko
Browse files

Merge branch 'RISC-V selftest/bpf fixes'



Björn Töpel says:

====================

This series contain some fixes for selftests/bpf when building/running
on a RISC-V host. Details can be found in each individual commit.

v2:
  Makefile cosmetics. (Andrii)
  Simplified unpriv check and added comment. (Andrii)
====================

Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
parents d0551261 6007b23c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -219,7 +219,8 @@ $(RESOLVE_BTFIDS): $(BPFOBJ) | $(BUILD_DIR)/resolve_btfids \
# build would have failed anyways.
define get_sys_includes
$(shell $(1) -v -E - </dev/null 2>&1 \
	| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')
	| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
$(shell $(1) -dM -E - </dev/null | grep '#define __riscv_xlen ' | sed 's/#define /-D/' | sed 's/ /=/')
endef

# Determine target endianness.
+13 −0
Original line number Diff line number Diff line
@@ -1152,6 +1152,19 @@ static void get_unpriv_disabled()

static bool test_as_unpriv(struct bpf_test *test)
{
#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
	/* 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. An unprivileged user loading a program
	 * with this flag will be rejected prior entering the
	 * verifier.
	 */
	if (test->flags & F_NEEDS_EFFICIENT_UNALIGNED_ACCESS)
		return false;
#endif
	return !test->prog_type ||
	       test->prog_type == BPF_PROG_TYPE_SOCKET_FILTER ||
	       test->prog_type == BPF_PROG_TYPE_CGROUP_SKB;
+7 −0
Original line number Diff line number Diff line
@@ -266,6 +266,7 @@
	.result = REJECT,
	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
	.expected_attach_type = BPF_SK_LOOKUP,
	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
},
{
	"invalid 8-byte read from bpf_sk_lookup remote_ip4 field",
@@ -292,6 +293,7 @@
	.result = REJECT,
	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
	.expected_attach_type = BPF_SK_LOOKUP,
	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
},
{
	"invalid 8-byte read from bpf_sk_lookup remote_port field",
@@ -305,6 +307,7 @@
	.result = REJECT,
	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
	.expected_attach_type = BPF_SK_LOOKUP,
	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
},
{
	"invalid 8-byte read from bpf_sk_lookup local_ip4 field",
@@ -331,6 +334,7 @@
	.result = REJECT,
	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
	.expected_attach_type = BPF_SK_LOOKUP,
	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
},
{
	"invalid 8-byte read from bpf_sk_lookup local_port field",
@@ -344,6 +348,7 @@
	.result = REJECT,
	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
	.expected_attach_type = BPF_SK_LOOKUP,
	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
},
/* invalid 1,2,4-byte reads from 8-byte fields in bpf_sk_lookup */
{
@@ -410,6 +415,7 @@
	.result = REJECT,
	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
	.expected_attach_type = BPF_SK_LOOKUP,
	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
},
{
	"invalid 4-byte unaligned read from bpf_sk_lookup at even offset",
@@ -422,6 +428,7 @@
	.result = REJECT,
	.prog_type = BPF_PROG_TYPE_SK_LOOKUP,
	.expected_attach_type = BPF_SK_LOOKUP,
	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
},
/* in-bound and out-of-bound writes to bpf_sk_lookup */
{
+3 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@
	.fixup_map_array_48b = { 1 },
	.result = REJECT,
	.errstr = "R1 min value is outside of the allowed memory range",
	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
},
{
	"direct map access, write test 7",
@@ -195,6 +196,7 @@
	.fixup_map_array_48b = { 1, 3 },
	.result = REJECT,
	.errstr = "invalid access to map value, value_size=48 off=47 size=2",
	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
},
{
	"direct map access, write test 17",
@@ -209,6 +211,7 @@
	.fixup_map_array_48b = { 1, 3 },
	.result = REJECT,
	.errstr = "invalid access to map value, value_size=48 off=47 size=2",
	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
},
{
	"direct map access, write test 18",
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@
	.errstr_unpriv = "bpf_array access is allowed only to CAP_PERFMON and CAP_SYS_ADMIN",
	.result = REJECT,
	.errstr = "cannot access ptr member ops with moff 0 in struct bpf_map with off 1 size 4",
	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
},
{
	"bpf_map_ptr: read ops field accepted",
Loading