Skip to content

Commit 6b17387

Browse files
Jakub Kicinskidavem330
authored andcommitted
bpf: recognize 64bit immediate loads as consts
When running as parser interpret BPF_LD | BPF_IMM | BPF_DW instructions as loading CONST_IMM with the value stored in imm. The verifier will continue not recognizing those due to concerns about search space/program complexity increase. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 13a27df commit 6b17387

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

kernel/bpf/verifier.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,9 +1769,19 @@ static int check_ld_imm(struct bpf_verifier_env *env, struct bpf_insn *insn)
17691769
if (err)
17701770
return err;
17711771

1772-
if (insn->src_reg == 0)
1773-
/* generic move 64-bit immediate into a register */
1772+
if (insn->src_reg == 0) {
1773+
/* generic move 64-bit immediate into a register,
1774+
* only analyzer needs to collect the ld_imm value.
1775+
*/
1776+
u64 imm = ((u64)(insn + 1)->imm << 32) | (u32)insn->imm;
1777+
1778+
if (!env->analyzer_ops)
1779+
return 0;
1780+
1781+
regs[insn->dst_reg].type = CONST_IMM;
1782+
regs[insn->dst_reg].imm = imm;
17741783
return 0;
1784+
}
17751785

17761786
/* replace_map_fd_with_map_ptr() should have caught bad ld_imm64 */
17771787
BUG_ON(insn->src_reg != BPF_PSEUDO_MAP_FD);

0 commit comments

Comments
 (0)