Skip to content

Commit a5bebc4

Browse files
kvanheesAlexei Starovoitov
authored andcommitted
bpf: Fix verifier support for validation of async callbacks
Commit bfc6bb7 ("bpf: Implement verifier support for validation of async callbacks.") added support for BPF_FUNC_timer_set_callback to the __check_func_call() function. The test in __check_func_call() is flaweed because it can mis-interpret a regular BPF-to-BPF pseudo-call as a BPF_FUNC_timer_set_callback callback call. Consider the conditional in the code: if (insn->code == (BPF_JMP | BPF_CALL) && insn->imm == BPF_FUNC_timer_set_callback) { The BPF_FUNC_timer_set_callback has value 170. This means that if you have a BPF program that contains a pseudo-call with an instruction delta of 170, this conditional will be found to be true by the verifier, and it will interpret the pseudo-call as a callback. This leads to a mess with the verification of the program because it makes the wrong assumptions about the nature of this call. Solution: include an explicit check to ensure that insn->src_reg == 0. This ensures that calls cannot be mis-interpreted as an async callback call. Fixes: bfc6bb7 ("bpf: Implement verifier support for validation of async callbacks.") Signed-off-by: Kris Van Hees <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 58d8a3f commit a5bebc4

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

kernel/bpf/verifier.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6031,6 +6031,7 @@ static int __check_func_call(struct bpf_verifier_env *env, struct bpf_insn *insn
60316031
}
60326032

60336033
if (insn->code == (BPF_JMP | BPF_CALL) &&
6034+
insn->src_reg == 0 &&
60346035
insn->imm == BPF_FUNC_timer_set_callback) {
60356036
struct bpf_verifier_state *async_cb;
60366037

0 commit comments

Comments
 (0)