Skip to content

Commit 3e6a4b3

Browse files
rgushchinborkmann
authored andcommitted
bpf/verifier: introduce BPF_PTR_TO_MAP_VALUE
BPF_MAP_TYPE_CGROUP_STORAGE maps are special in a way that the access from the bpf program side is lookup-free. That means the result is guaranteed to be a valid pointer to the cgroup storage; no NULL-check is required. This patch introduces BPF_PTR_TO_MAP_VALUE return type, which is required to cause the verifier accept programs, which are not checking the map value pointer for being NULL. Signed-off-by: Roman Gushchin <guro@fb.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 394e40a commit 3e6a4b3

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

include/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ enum bpf_arg_type {
155155
enum bpf_return_type {
156156
RET_INTEGER, /* function returns integer */
157157
RET_VOID, /* function doesn't return anything */
158+
RET_PTR_TO_MAP_VALUE, /* returns a pointer to map elem value */
158159
RET_PTR_TO_MAP_VALUE_OR_NULL, /* returns a pointer to map elem value or NULL */
159160
};
160161

kernel/bpf/verifier.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,8 +2545,12 @@ static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn
25452545
mark_reg_unknown(env, regs, BPF_REG_0);
25462546
} else if (fn->ret_type == RET_VOID) {
25472547
regs[BPF_REG_0].type = NOT_INIT;
2548-
} else if (fn->ret_type == RET_PTR_TO_MAP_VALUE_OR_NULL) {
2549-
regs[BPF_REG_0].type = PTR_TO_MAP_VALUE_OR_NULL;
2548+
} else if (fn->ret_type == RET_PTR_TO_MAP_VALUE_OR_NULL ||
2549+
fn->ret_type == RET_PTR_TO_MAP_VALUE) {
2550+
if (fn->ret_type == RET_PTR_TO_MAP_VALUE)
2551+
regs[BPF_REG_0].type = PTR_TO_MAP_VALUE;
2552+
else
2553+
regs[BPF_REG_0].type = PTR_TO_MAP_VALUE_OR_NULL;
25502554
/* There is no offset yet applied, variable or fixed */
25512555
mark_reg_known_zero(env, regs, BPF_REG_0);
25522556
regs[BPF_REG_0].off = 0;

0 commit comments

Comments
 (0)