• Kumar Kartikeya Dwivedi's avatar
    bpf: Refactor check_btf_func and split into two phases · aaa619eb
    Kumar Kartikeya Dwivedi authored
    This patch splits the check_btf_info's check_btf_func check into two
    separate phases.  The first phase sets up the BTF and prepares
    func_info, but does not perform any validation of required invariants
    for subprogs just yet. This is left to the second phase, which happens
    where check_btf_info executes currently, and performs the line_info and
    CO-RE relocation.
    
    The reason to perform this split is to obtain the userspace supplied
    func_info information before we perform the add_subprog call, where we
    would now require finding and adding subprogs that may not have a
    bpf_pseudo_call or bpf_pseudo_func instruction in the program.
    
    We require this as we want to enable userspace to supply exception
    callbacks that can override the default hidden subprogram generated by
    the verifier (which performs a hardcoded action). In such a case, the
    exception callback may never be referenced in an instruction, but will
    still be suitably annotated (by way of BTF declaration tags). For
    finding this exception callback, we would require the program's BTF
    information, and the supplied func_info information which maps BTF type
    IDs to subprograms.
    
    Since the exception callback won't actually be referenced through
    instructions, later checks in check_cfg and do_check_subprogs will not
    verify the subprog. This means that add_subprog needs to add them in the
    add_subprog_and_kfunc phase before we move forward, which is why the BTF
    and func_info are required at that point.
    Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
    Link: https://lore.kernel.org/r/20230912233214.1518551-6-memxor@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    aaa619eb
verifier.c 591 KB