• Kui-Feng Lee's avatar
    bpf: hold module refcnt in bpf_struct_ops map creation and prog verification. · e3f87fdf
    Kui-Feng Lee authored
    To ensure that a module remains accessible whenever a struct_ops object of
    a struct_ops type provided by the module is still in use.
    
    struct bpf_struct_ops_map doesn't hold a refcnt to btf anymore since a
    module will hold a refcnt to it's btf already. But, struct_ops programs are
    different. They hold their associated btf, not the module since they need
    only btf to assure their types (signatures).
    
    However, verifier holds the refcnt of the associated module of a struct_ops
    type temporarily when verify a struct_ops prog. Verifier needs the help
    from the verifier operators (struct bpf_verifier_ops) provided by the owner
    module to verify data access of a prog, provide information, and generate
    code.
    
    This patch also add a count of links (links_cnt) to bpf_struct_ops_map. It
    avoids bpf_struct_ops_map_put_progs() from accessing btf after calling
    module_put() in bpf_struct_ops_map_free().
    Signed-off-by: default avatarKui-Feng Lee <thinker.li@gmail.com>
    Link: https://lore.kernel.org/r/20240119225005.668602-10-thinker.li@gmail.comSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
    e3f87fdf
verifier.c 626 KB