• Alexei Starovoitov's avatar
    bpf: teach verifier to recognize imm += ptr pattern · 1b9b69ec
    Alexei Starovoitov authored
    Humans don't write C code like:
      u8 *ptr = skb->data;
      int imm = 4;
      imm += ptr;
    but from llvm backend point of view 'imm' and 'ptr' are registers and
    imm += ptr may be preferred vs ptr += imm depending which register value
    will be used further in the code, while verifier can only recognize ptr += imm.
    That caused small unrelated changes in the C code of the bpf program to
    trigger rejection by the verifier. Therefore teach the verifier to recognize
    both ptr += imm and imm += ptr.
    For example:
    when R6=pkt(id=0,off=0,r=62) R7=imm22
    after r7 += r6 instruction
    will be R6=pkt(id=0,off=0,r=62) R7=pkt(id=0,off=22,r=62)
    
    Fixes: 969bf05e ("bpf: direct packet access")
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    1b9b69ec
verifier.c 77.5 KB