OSDN Git Service

bpf: Account for BPF_FETCH in insn_has_def32()
authorIlya Leoshkevich <iii@linux.ibm.com>
Mon, 1 Mar 2021 15:40:19 +0000 (16:40 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 4 Mar 2021 15:02:31 +0000 (16:02 +0100)
commit83a2881903f3d5bc08ded4fb04f6e3bedb1fba65
tree7cb2b678083cf4c0d1539e66ba6cd6c6ed5e75b8
parent2b2aedabc44e9660f90ccf7ba1ca2706d75f411f
bpf: Account for BPF_FETCH in insn_has_def32()

insn_has_def32() returns false for 32-bit BPF_FETCH insns. This makes
adjust_insn_aux_data() incorrectly set zext_dst, as can be seen in [1].
This happens because insn_no_def() does not know about the BPF_FETCH
variants of BPF_STX.

Fix in two steps.

First, replace insn_no_def() with insn_def_regno(), which returns the
register an insn defines. Normally insn_no_def() calls are followed by
insn->dst_reg uses; replace those with the insn_def_regno() return
value.

Second, adjust the BPF_STX special case in is_reg64() to deal with
queries made from opt_subreg_zext_lo32_rnd_hi32(), where the state
information is no longer available. Add a comment, since the purpose
of this special case is not clear at first glance.

  [1] https://lore.kernel.org/bpf/20210223150845.1857620-1-jackmanb@google.com/

Fixes: 5ffa25502b5a ("bpf: Add instructions for atomic_[cmp]xchg")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Brendan Jackman <jackmanb@google.com>
Link: https://lore.kernel.org/bpf/20210301154019.129110-1-iii@linux.ibm.com
kernel/bpf/verifier.c