Skip to content

Commit 12a1fe6

Browse files
etsalanakryiko
authored andcommitted
bpf/verifier: Do not limit maximum direct offset into arena map
The verifier currently limits direct offsets into a map to 512MiB to avoid overflow during pointer arithmetic. However, this prevents arena maps from using direct addressing instructions to access data at the end of > 512MiB arena maps. This is necessary when moving arena globals to the end of the arena instead of the front. Refactor the verifier code to remove the offset calculation during direct value access calculations. This is possible because the only two map types that implement .map_direct_value_addr() are arrays and arenas, and they both do their own internal checks to ensure the offset is within bounds. Adjust selftests that expect the old error. These tests still fail because the verifier identifies the access as out of bounds for the map, so change them to expect an "invalid access to map value pointer" error instead. Signed-off-by: Emil Tsalapatis <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 0355911 commit 12a1fe6

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

kernel/bpf/verifier.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21132,11 +21132,6 @@ static int resolve_pseudo_ldimm64(struct bpf_verifier_env *env)
2113221132
} else {
2113321133
u32 off = insn[1].imm;
2113421134

21135-
if (off >= BPF_MAX_VAR_OFF) {
21136-
verbose(env, "direct value offset of %u is not allowed\n", off);
21137-
return -EINVAL;
21138-
}
21139-
2114021135
if (!map->ops->map_direct_value_addr) {
2114121136
verbose(env, "no direct value access support for this map type\n");
2114221137
return -EINVAL;

tools/testing/selftests/bpf/verifier/direct_value_access.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
},
8282
.fixup_map_array_48b = { 1 },
8383
.result = REJECT,
84-
.errstr = "direct value offset of 4294967295 is not allowed",
84+
.errstr = "invalid access to map value pointer, value_size=48 off=4294967295",
8585
},
8686
{
8787
"direct map access, write test 8",
@@ -141,7 +141,7 @@
141141
},
142142
.fixup_map_array_48b = { 1 },
143143
.result = REJECT,
144-
.errstr = "direct value offset of 536870912 is not allowed",
144+
.errstr = "invalid access to map value pointer, value_size=48 off=536870912",
145145
},
146146
{
147147
"direct map access, write test 13",

0 commit comments

Comments
 (0)