• Andrii Nakryiko's avatar
    bpf: generalize reg_set_min_max() to handle non-const register comparisons · 67420501
    Andrii Nakryiko authored
    Generalize bounds adjustment logic of reg_set_min_max() to handle not
    just register vs constant case, but in general any register vs any
    register cases. For most of the operations it's trivial extension based
    on range vs range comparison logic, we just need to properly pick
    min/max of a range to compare against min/max of the other range.
    
    For BPF_JSET we keep the original capabilities, just make sure JSET is
    integrated in the common framework. This is manifested in the
    internal-only BPF_JSET + BPF_X "opcode" to allow for simpler and more
    uniform rev_opcode() handling. See the code for details. This allows to
    reuse the same code exactly both for TRUE and FALSE branches without
    explicitly handling both conditions with custom code.
    
    Note also that now we don't need a special handling of BPF_JEQ/BPF_JNE
    case none of the registers are constants. This is now just a normal
    generic case handled by reg_set_min_max().
    
    To make tnum handling cleaner, tnum_with_subreg() helper is added, as
    that's a common operator when dealing with 32-bit subregister bounds.
    This keeps the overall logic much less noisy when it comes to tnums.
    Acked-by: default avatarEduard Zingerman <eddyz87@gmail.com>
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Acked-by: default avatarShung-Hsi Yu <shung-hsi.yu@suse.com>
    Link: https://lore.kernel.org/r/20231112010609.848406-2-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    67420501
verifier.c 618 KB