Commit 6007b23c authored by Björn Töpel's avatar Björn Töpel Committed by Andrii Nakryiko

selftests/bpf: Mark tests that require unaligned memory access

A lot of tests require unaligned memory access to work. Mark the tests
as such, so that they can be avoided on unsupported architectures such
as RISC-V.
Signed-off-by: default avatarBjörn Töpel <bjorn.topel@gmail.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Acked-by: default avatarLuke Nelson <luke.r.nels@gmail.com>
Link: https://lore.kernel.org/bpf/20201118071640.83773-4-bjorn.topel@gmail.com
parent c77b0589
...@@ -266,6 +266,7 @@ ...@@ -266,6 +266,7 @@
.result = REJECT, .result = REJECT,
.prog_type = BPF_PROG_TYPE_SK_LOOKUP, .prog_type = BPF_PROG_TYPE_SK_LOOKUP,
.expected_attach_type = BPF_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", "invalid 8-byte read from bpf_sk_lookup remote_ip4 field",
...@@ -292,6 +293,7 @@ ...@@ -292,6 +293,7 @@
.result = REJECT, .result = REJECT,
.prog_type = BPF_PROG_TYPE_SK_LOOKUP, .prog_type = BPF_PROG_TYPE_SK_LOOKUP,
.expected_attach_type = BPF_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", "invalid 8-byte read from bpf_sk_lookup remote_port field",
...@@ -305,6 +307,7 @@ ...@@ -305,6 +307,7 @@
.result = REJECT, .result = REJECT,
.prog_type = BPF_PROG_TYPE_SK_LOOKUP, .prog_type = BPF_PROG_TYPE_SK_LOOKUP,
.expected_attach_type = BPF_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", "invalid 8-byte read from bpf_sk_lookup local_ip4 field",
...@@ -331,6 +334,7 @@ ...@@ -331,6 +334,7 @@
.result = REJECT, .result = REJECT,
.prog_type = BPF_PROG_TYPE_SK_LOOKUP, .prog_type = BPF_PROG_TYPE_SK_LOOKUP,
.expected_attach_type = BPF_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", "invalid 8-byte read from bpf_sk_lookup local_port field",
...@@ -344,6 +348,7 @@ ...@@ -344,6 +348,7 @@
.result = REJECT, .result = REJECT,
.prog_type = BPF_PROG_TYPE_SK_LOOKUP, .prog_type = BPF_PROG_TYPE_SK_LOOKUP,
.expected_attach_type = BPF_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 */ /* invalid 1,2,4-byte reads from 8-byte fields in bpf_sk_lookup */
{ {
...@@ -410,6 +415,7 @@ ...@@ -410,6 +415,7 @@
.result = REJECT, .result = REJECT,
.prog_type = BPF_PROG_TYPE_SK_LOOKUP, .prog_type = BPF_PROG_TYPE_SK_LOOKUP,
.expected_attach_type = BPF_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", "invalid 4-byte unaligned read from bpf_sk_lookup at even offset",
...@@ -422,6 +428,7 @@ ...@@ -422,6 +428,7 @@
.result = REJECT, .result = REJECT,
.prog_type = BPF_PROG_TYPE_SK_LOOKUP, .prog_type = BPF_PROG_TYPE_SK_LOOKUP,
.expected_attach_type = BPF_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 */ /* in-bound and out-of-bound writes to bpf_sk_lookup */
{ {
......
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
.fixup_map_array_48b = { 1 }, .fixup_map_array_48b = { 1 },
.result = REJECT, .result = REJECT,
.errstr = "R1 min value is outside of the allowed memory range", .errstr = "R1 min value is outside of the allowed memory range",
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
}, },
{ {
"direct map access, write test 7", "direct map access, write test 7",
...@@ -195,6 +196,7 @@ ...@@ -195,6 +196,7 @@
.fixup_map_array_48b = { 1, 3 }, .fixup_map_array_48b = { 1, 3 },
.result = REJECT, .result = REJECT,
.errstr = "invalid access to map value, value_size=48 off=47 size=2", .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", "direct map access, write test 17",
...@@ -209,6 +211,7 @@ ...@@ -209,6 +211,7 @@
.fixup_map_array_48b = { 1, 3 }, .fixup_map_array_48b = { 1, 3 },
.result = REJECT, .result = REJECT,
.errstr = "invalid access to map value, value_size=48 off=47 size=2", .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", "direct map access, write test 18",
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
.errstr_unpriv = "bpf_array access is allowed only to CAP_PERFMON and CAP_SYS_ADMIN", .errstr_unpriv = "bpf_array access is allowed only to CAP_PERFMON and CAP_SYS_ADMIN",
.result = REJECT, .result = REJECT,
.errstr = "cannot access ptr member ops with moff 0 in struct bpf_map with off 1 size 4", .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", "bpf_map_ptr: read ops field accepted",
......
...@@ -31,4 +31,5 @@ ...@@ -31,4 +31,5 @@
.fixup_map_hash_8b = { 1, }, .fixup_map_hash_8b = { 1, },
.prog_type = BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE, .prog_type = BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
.errstr = "R6 invalid variable buffer offset: off=0, var_off=(0x0; 0xffffffff)", .errstr = "R6 invalid variable buffer offset: off=0, var_off=(0x0; 0xffffffff)",
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
}, },
...@@ -675,6 +675,7 @@ ...@@ -675,6 +675,7 @@
.prog_type = BPF_PROG_TYPE_SCHED_CLS, .prog_type = BPF_PROG_TYPE_SCHED_CLS,
.result = REJECT, .result = REJECT,
.errstr = "invalid mem access", .errstr = "invalid mem access",
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
}, },
{ {
"reference tracking: use ptr from bpf_sk_fullsock() after release", "reference tracking: use ptr from bpf_sk_fullsock() after release",
...@@ -698,6 +699,7 @@ ...@@ -698,6 +699,7 @@
.prog_type = BPF_PROG_TYPE_SCHED_CLS, .prog_type = BPF_PROG_TYPE_SCHED_CLS,
.result = REJECT, .result = REJECT,
.errstr = "invalid mem access", .errstr = "invalid mem access",
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
}, },
{ {
"reference tracking: use ptr from bpf_sk_fullsock(tp) after release", "reference tracking: use ptr from bpf_sk_fullsock(tp) after release",
...@@ -725,6 +727,7 @@ ...@@ -725,6 +727,7 @@
.prog_type = BPF_PROG_TYPE_SCHED_CLS, .prog_type = BPF_PROG_TYPE_SCHED_CLS,
.result = REJECT, .result = REJECT,
.errstr = "invalid mem access", .errstr = "invalid mem access",
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
}, },
{ {
"reference tracking: use sk after bpf_sk_release(tp)", "reference tracking: use sk after bpf_sk_release(tp)",
...@@ -747,6 +750,7 @@ ...@@ -747,6 +750,7 @@
.prog_type = BPF_PROG_TYPE_SCHED_CLS, .prog_type = BPF_PROG_TYPE_SCHED_CLS,
.result = REJECT, .result = REJECT,
.errstr = "invalid mem access", .errstr = "invalid mem access",
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
}, },
{ {
"reference tracking: use ptr from bpf_get_listener_sock() after bpf_sk_release(sk)", "reference tracking: use ptr from bpf_get_listener_sock() after bpf_sk_release(sk)",
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
.fixup_map_hash_48b = { 4 }, .fixup_map_hash_48b = { 4 },
.result = ACCEPT, .result = ACCEPT,
.prog_type = BPF_PROG_TYPE_TRACEPOINT, .prog_type = BPF_PROG_TYPE_TRACEPOINT,
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
}, },
{ {
"regalloc negative", "regalloc negative",
...@@ -71,6 +72,7 @@ ...@@ -71,6 +72,7 @@
.fixup_map_hash_48b = { 4 }, .fixup_map_hash_48b = { 4 },
.result = ACCEPT, .result = ACCEPT,
.prog_type = BPF_PROG_TYPE_TRACEPOINT, .prog_type = BPF_PROG_TYPE_TRACEPOINT,
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
}, },
{ {
"regalloc src_reg negative", "regalloc src_reg negative",
...@@ -97,6 +99,7 @@ ...@@ -97,6 +99,7 @@
.result = REJECT, .result = REJECT,
.errstr = "invalid access to map value, value_size=48 off=44 size=8", .errstr = "invalid access to map value, value_size=48 off=44 size=8",
.prog_type = BPF_PROG_TYPE_TRACEPOINT, .prog_type = BPF_PROG_TYPE_TRACEPOINT,
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
}, },
{ {
"regalloc and spill", "regalloc and spill",
...@@ -126,6 +129,7 @@ ...@@ -126,6 +129,7 @@
.fixup_map_hash_48b = { 4 }, .fixup_map_hash_48b = { 4 },
.result = ACCEPT, .result = ACCEPT,
.prog_type = BPF_PROG_TYPE_TRACEPOINT, .prog_type = BPF_PROG_TYPE_TRACEPOINT,
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
}, },
{ {
"regalloc and spill negative", "regalloc and spill negative",
...@@ -156,6 +160,7 @@ ...@@ -156,6 +160,7 @@
.result = REJECT, .result = REJECT,
.errstr = "invalid access to map value, value_size=48 off=48 size=8", .errstr = "invalid access to map value, value_size=48 off=48 size=8",
.prog_type = BPF_PROG_TYPE_TRACEPOINT, .prog_type = BPF_PROG_TYPE_TRACEPOINT,
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
}, },
{ {
"regalloc three regs", "regalloc three regs",
...@@ -182,6 +187,7 @@ ...@@ -182,6 +187,7 @@
.fixup_map_hash_48b = { 4 }, .fixup_map_hash_48b = { 4 },
.result = ACCEPT, .result = ACCEPT,
.prog_type = BPF_PROG_TYPE_TRACEPOINT, .prog_type = BPF_PROG_TYPE_TRACEPOINT,
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
}, },
{ {
"regalloc after call", "regalloc after call",
...@@ -210,6 +216,7 @@ ...@@ -210,6 +216,7 @@
.fixup_map_hash_48b = { 4 }, .fixup_map_hash_48b = { 4 },
.result = ACCEPT, .result = ACCEPT,
.prog_type = BPF_PROG_TYPE_TRACEPOINT, .prog_type = BPF_PROG_TYPE_TRACEPOINT,
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
}, },
{ {
"regalloc in callee", "regalloc in callee",
...@@ -240,6 +247,7 @@ ...@@ -240,6 +247,7 @@
.fixup_map_hash_48b = { 4 }, .fixup_map_hash_48b = { 4 },
.result = ACCEPT, .result = ACCEPT,
.prog_type = BPF_PROG_TYPE_TRACEPOINT, .prog_type = BPF_PROG_TYPE_TRACEPOINT,
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
}, },
{ {
"regalloc, spill, JEQ", "regalloc, spill, JEQ",
......
#define BPF_SOCK_ADDR_STORE(field, off, res, err) \ #define BPF_SOCK_ADDR_STORE(field, off, res, err, flgs) \
{ \ { \
"wide store to bpf_sock_addr." #field "[" #off "]", \ "wide store to bpf_sock_addr." #field "[" #off "]", \
.insns = { \ .insns = { \
...@@ -11,31 +11,36 @@ ...@@ -11,31 +11,36 @@
.prog_type = BPF_PROG_TYPE_CGROUP_SOCK_ADDR, \ .prog_type = BPF_PROG_TYPE_CGROUP_SOCK_ADDR, \
.expected_attach_type = BPF_CGROUP_UDP6_SENDMSG, \ .expected_attach_type = BPF_CGROUP_UDP6_SENDMSG, \
.errstr = err, \ .errstr = err, \
.flags = flgs, \
} }
/* user_ip6[0] is u64 aligned */ /* user_ip6[0] is u64 aligned */
BPF_SOCK_ADDR_STORE(user_ip6, 0, ACCEPT, BPF_SOCK_ADDR_STORE(user_ip6, 0, ACCEPT,
NULL), NULL, 0),
BPF_SOCK_ADDR_STORE(user_ip6, 1, REJECT, BPF_SOCK_ADDR_STORE(user_ip6, 1, REJECT,
"invalid bpf_context access off=12 size=8"), "invalid bpf_context access off=12 size=8",
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
BPF_SOCK_ADDR_STORE(user_ip6, 2, ACCEPT, BPF_SOCK_ADDR_STORE(user_ip6, 2, ACCEPT,
NULL), NULL, 0),
BPF_SOCK_ADDR_STORE(user_ip6, 3, REJECT, BPF_SOCK_ADDR_STORE(user_ip6, 3, REJECT,
"invalid bpf_context access off=20 size=8"), "invalid bpf_context access off=20 size=8",
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
/* msg_src_ip6[0] is _not_ u64 aligned */ /* msg_src_ip6[0] is _not_ u64 aligned */
BPF_SOCK_ADDR_STORE(msg_src_ip6, 0, REJECT, BPF_SOCK_ADDR_STORE(msg_src_ip6, 0, REJECT,
"invalid bpf_context access off=44 size=8"), "invalid bpf_context access off=44 size=8",
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
BPF_SOCK_ADDR_STORE(msg_src_ip6, 1, ACCEPT, BPF_SOCK_ADDR_STORE(msg_src_ip6, 1, ACCEPT,
NULL), NULL, 0),
BPF_SOCK_ADDR_STORE(msg_src_ip6, 2, REJECT, BPF_SOCK_ADDR_STORE(msg_src_ip6, 2, REJECT,
"invalid bpf_context access off=52 size=8"), "invalid bpf_context access off=52 size=8",
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
BPF_SOCK_ADDR_STORE(msg_src_ip6, 3, REJECT, BPF_SOCK_ADDR_STORE(msg_src_ip6, 3, REJECT,
"invalid bpf_context access off=56 size=8"), "invalid bpf_context access off=56 size=8", 0),
#undef BPF_SOCK_ADDR_STORE #undef BPF_SOCK_ADDR_STORE
#define BPF_SOCK_ADDR_LOAD(field, off, res, err) \ #define BPF_SOCK_ADDR_LOAD(field, off, res, err, flgs) \
{ \ { \
"wide load from bpf_sock_addr." #field "[" #off "]", \ "wide load from bpf_sock_addr." #field "[" #off "]", \
.insns = { \ .insns = { \
...@@ -48,26 +53,31 @@ BPF_SOCK_ADDR_STORE(msg_src_ip6, 3, REJECT, ...@@ -48,26 +53,31 @@ BPF_SOCK_ADDR_STORE(msg_src_ip6, 3, REJECT,
.prog_type = BPF_PROG_TYPE_CGROUP_SOCK_ADDR, \ .prog_type = BPF_PROG_TYPE_CGROUP_SOCK_ADDR, \
.expected_attach_type = BPF_CGROUP_UDP6_SENDMSG, \ .expected_attach_type = BPF_CGROUP_UDP6_SENDMSG, \
.errstr = err, \ .errstr = err, \
.flags = flgs, \
} }
/* user_ip6[0] is u64 aligned */ /* user_ip6[0] is u64 aligned */
BPF_SOCK_ADDR_LOAD(user_ip6, 0, ACCEPT, BPF_SOCK_ADDR_LOAD(user_ip6, 0, ACCEPT,
NULL), NULL, 0),
BPF_SOCK_ADDR_LOAD(user_ip6, 1, REJECT, BPF_SOCK_ADDR_LOAD(user_ip6, 1, REJECT,
"invalid bpf_context access off=12 size=8"), "invalid bpf_context access off=12 size=8",
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
BPF_SOCK_ADDR_LOAD(user_ip6, 2, ACCEPT, BPF_SOCK_ADDR_LOAD(user_ip6, 2, ACCEPT,
NULL), NULL, 0),
BPF_SOCK_ADDR_LOAD(user_ip6, 3, REJECT, BPF_SOCK_ADDR_LOAD(user_ip6, 3, REJECT,
"invalid bpf_context access off=20 size=8"), "invalid bpf_context access off=20 size=8",
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
/* msg_src_ip6[0] is _not_ u64 aligned */ /* msg_src_ip6[0] is _not_ u64 aligned */
BPF_SOCK_ADDR_LOAD(msg_src_ip6, 0, REJECT, BPF_SOCK_ADDR_LOAD(msg_src_ip6, 0, REJECT,
"invalid bpf_context access off=44 size=8"), "invalid bpf_context access off=44 size=8",
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
BPF_SOCK_ADDR_LOAD(msg_src_ip6, 1, ACCEPT, BPF_SOCK_ADDR_LOAD(msg_src_ip6, 1, ACCEPT,
NULL), NULL, 0),
BPF_SOCK_ADDR_LOAD(msg_src_ip6, 2, REJECT, BPF_SOCK_ADDR_LOAD(msg_src_ip6, 2, REJECT,
"invalid bpf_context access off=52 size=8"), "invalid bpf_context access off=52 size=8",
F_NEEDS_EFFICIENT_UNALIGNED_ACCESS),
BPF_SOCK_ADDR_LOAD(msg_src_ip6, 3, REJECT, BPF_SOCK_ADDR_LOAD(msg_src_ip6, 3, REJECT,
"invalid bpf_context access off=56 size=8"), "invalid bpf_context access off=56 size=8", 0),
#undef BPF_SOCK_ADDR_LOAD #undef BPF_SOCK_ADDR_LOAD
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment