Skip to content

Commit 4a9c7bb

Browse files
iamkafaiAlexei Starovoitov
authored andcommitted
bpf: Resolve to prog->aux->dst_prog->type only for BPF_PROG_TYPE_EXT
The commit 7e40781 ("bpf: verifier: Use target program's type for access verifications") fixes the verifier checking for BPF_PROG_TYPE_EXT (extension) prog such that the verifier looks for things based on the target prog type that it is extending instead of the BPF_PROG_TYPE_EXT itself. The current resolve_prog_type() returns the target prog type. It checks for nullness on prog->aux->dst_prog. However, when loading a BPF_PROG_TYPE_TRACING prog and it is tracing another bpf prog instead of a kernel function, prog->aux->dst_prog is not NULL also. In this case, the verifier should still verify as the BPF_PROG_TYPE_TRACING type instead of the traced prog type in prog->aux->dst_prog->type. An oops has been reported when tracing a struct_ops prog. A NULL dereference happened in check_return_code() when accessing the prog->aux->attach_func_proto->type and prog->aux->attach_func_proto is NULL here because the traced struct_ops prog has the "unreliable" set. This patch is to change the resolve_prog_type() to only return the target prog type if the prog being verified is BPF_PROG_TYPE_EXT. Fixes: 7e40781 ("bpf: verifier: Use target program's type for access verifications") Signed-off-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/bpf/20220330011456.2984509-1-kafai@fb.com
1 parent a2fb498 commit 4a9c7bb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

include/linux/bpf_verifier.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,11 @@ static inline u32 type_flag(u32 type)
570570
return type & ~BPF_BASE_TYPE_MASK;
571571
}
572572

573+
/* only use after check_attach_btf_id() */
573574
static inline enum bpf_prog_type resolve_prog_type(struct bpf_prog *prog)
574575
{
575-
return prog->aux->dst_prog ? prog->aux->dst_prog->type : prog->type;
576+
return prog->type == BPF_PROG_TYPE_EXT ?
577+
prog->aux->dst_prog->type : prog->type;
576578
}
577579

578580
#endif /* _LINUX_BPF_VERIFIER_H */

0 commit comments

Comments
 (0)