• Dave Marchevsky's avatar
    bpf: Add verifier check for BPF_PTR_POISON retval and arg · 47e34cb7
    Dave Marchevsky authored
    BPF_PTR_POISON was added in commit c0a5a21c ("bpf: Allow storing
    referenced kptr in map") to denote a bpf_func_proto btf_id which the
    verifier will replace with a dynamically-determined btf_id at verification
    time.
    
    This patch adds verifier 'poison' functionality to BPF_PTR_POISON in
    order to prepare for expanded use of the value to poison ret- and
    arg-btf_id in ongoing work, namely rbtree and linked list patchsets
    [0, 1]. Specifically, when the verifier checks helper calls, it assumes
    that BPF_PTR_POISON'ed ret type will be replaced with a valid type before
    - or in lieu of - the default ret_btf_id logic. Similarly for arg btf_id.
    
    If poisoned btf_id reaches default handling block for either, consider
    this a verifier internal error and fail verification. Otherwise a helper
    w/ poisoned btf_id but no verifier logic replacing the type will cause a
    crash as the invalid pointer is dereferenced.
    
    Also move BPF_PTR_POISON to existing include/linux/posion.h header and
    remove unnecessary shift.
    
      [0]: lore.kernel.org/bpf/20220830172759.4069786-1-davemarchevsky@fb.com
      [1]: lore.kernel.org/bpf/20220904204145.3089-1-memxor@gmail.com
    Signed-off-by: default avatarDave Marchevsky <davemarchevsky@fb.com>
    Acked-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
    Link: https://lore.kernel.org/r/20220912154544.1398199-1-davemarchevsky@fb.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    47e34cb7
verifier.c 436 KB