Skip to content

Commit d3178e8

Browse files
SunHao-0borkmann
authored andcommitted
bpf: Skip invalid kfunc call in backtrack_insn
The verifier skips invalid kfunc call in check_kfunc_call(), which would be captured in fixup_kfunc_call() if such insn is not eliminated by dead code elimination. However, this can lead to the following warning in backtrack_insn(), also see [1]: ------------[ cut here ]------------ verifier backtracking bug WARNING: CPU: 6 PID: 8646 at kernel/bpf/verifier.c:2756 backtrack_insn kernel/bpf/verifier.c:2756 __mark_chain_precision kernel/bpf/verifier.c:3065 mark_chain_precision kernel/bpf/verifier.c:3165 adjust_reg_min_max_vals kernel/bpf/verifier.c:10715 check_alu_op kernel/bpf/verifier.c:10928 do_check kernel/bpf/verifier.c:13821 [inline] do_check_common kernel/bpf/verifier.c:16289 [...] So make backtracking conservative with this by returning ENOTSUPP. [1] https://lore.kernel.org/bpf/CACkBjsaXNceR8ZjkLG=dT3P=4A8SBsg0Z5h5PWLryF5=ghKq=g@mail.gmail.com/ Reported-by: [email protected] Signed-off-by: Hao Sun <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent c244c09 commit d3178e8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

kernel/bpf/verifier.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,6 +2748,12 @@ static int backtrack_insn(struct bpf_verifier_env *env, int idx,
27482748
*/
27492749
if (insn->src_reg == 0 && is_callback_calling_function(insn->imm))
27502750
return -ENOTSUPP;
2751+
/* kfunc with imm==0 is invalid and fixup_kfunc_call will
2752+
* catch this error later. Make backtracking conservative
2753+
* with ENOTSUPP.
2754+
*/
2755+
if (insn->src_reg == BPF_PSEUDO_KFUNC_CALL && insn->imm == 0)
2756+
return -ENOTSUPP;
27512757
/* regular helper call sets R0 */
27522758
*reg_mask &= ~1;
27532759
if (*reg_mask & 0x3f) {

0 commit comments

Comments
 (0)