• Andrii Nakryiko's avatar
    bpf: generalize MAYBE_NULL vs non-MAYBE_NULL rule · 7f4ce97c
    Andrii Nakryiko authored
    Make generic check to prevent XXX_OR_NULL and XXX register types to be
    intermixed. While technically in some situations it could be safe, it's
    impossible to enforce due to the loss of an ID when converting
    XXX_OR_NULL to its non-NULL variant. So prevent this in general, not
    just for PTR_TO_MAP_KEY and PTR_TO_MAP_VALUE.
    
    PTR_TO_MAP_KEY_OR_NULL and PTR_TO_MAP_VALUE_OR_NULL checks, which were
    previously special-cased, are simplified to generic check that takes
    into account range_within() and tnum_in(). This is correct as BPF
    verifier doesn't allow arithmetic on XXX_OR_NULL register types, so
    var_off and ranges should stay zero. But even if in the future this
    restriction is lifted, it's even more important to enforce that var_off
    and ranges are compatible, otherwise it's possible to construct case
    where this can be exploited to bypass verifier's memory range safety
    checks.
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/r/20221223054921.958283-4-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    7f4ce97c
verifier.c 494 KB