• Daniel Borkmann's avatar
    bpf: Generally fix helper register offset check · 6788ab23
    Daniel Borkmann authored
    Right now the assertion on check_ptr_off_reg() is only enforced for register
    types PTR_TO_CTX (and open coded also for PTR_TO_BTF_ID), however, this is
    insufficient since many other PTR_TO_* register types such as PTR_TO_FUNC do
    not handle/expect register offsets when passed to helper functions.
    
    Given this can slip-through easily when adding new types, make this an explicit
    allow-list and reject all other current and future types by default if this is
    encountered.
    
    Also, extend check_ptr_off_reg() to handle PTR_TO_BTF_ID as well instead of
    duplicating it. For PTR_TO_BTF_ID, reg->off is used for BTF to match expected
    BTF ids if struct offset is used. This part still needs to be allowed, but the
    dynamic off from the tnum must be rejected.
    
    Fixes: 69c087ba ("bpf: Add bpf_for_each_map_elem() helper")
    Fixes: eaa6bcb7 ("bpf: Introduce bpf_per_cpu_ptr()")
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
    Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
    6788ab23
verifier.c 410 KB