• Andrii Nakryiko's avatar
    libbpf: Wire up BPF token support at BPF object level · 6b434b61
    Andrii Nakryiko authored
    Add BPF token support to BPF object-level functionality.
    
    BPF token is supported by BPF object logic either as an explicitly
    provided BPF token from outside (through BPF FS path), or implicitly
    (unless prevented through bpf_object_open_opts).
    
    Implicit mode is assumed to be the most common one for user namespaced
    unprivileged workloads. The assumption is that privileged container
    manager sets up default BPF FS mount point at /sys/fs/bpf with BPF token
    delegation options (delegate_{cmds,maps,progs,attachs} mount options).
    BPF object during loading will attempt to create BPF token from
    /sys/fs/bpf location, and pass it for all relevant operations
    (currently, map creation, BTF load, and program load).
    
    In this implicit mode, if BPF token creation fails due to whatever
    reason (BPF FS is not mounted, or kernel doesn't support BPF token,
    etc), this is not considered an error. BPF object loading sequence will
    proceed with no BPF token.
    
    In explicit BPF token mode, user provides explicitly custom BPF FS mount
    point path. In such case, BPF object will attempt to create BPF token
    from provided BPF FS location. If BPF token creation fails, that is
    considered a critical error and BPF object load fails with an error.
    
    Libbpf provides a way to disable implicit BPF token creation, if it
    causes any troubles (BPF token is designed to be completely optional and
    shouldn't cause any problems even if provided, but in the world of BPF
    LSM, custom security logic can be installed that might change outcome
    depending on the presence of BPF token). To disable libbpf's default BPF
    token creation behavior user should provide either invalid BPF token FD
    (negative), or empty bpf_token_path option.
    
    BPF token presence can influence libbpf's feature probing, so if BPF
    object has associated BPF token, feature probing is instructed to use
    BPF object-specific feature detection cache and token FD.
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Link: https://lore.kernel.org/bpf/20240124022127.2379740-26-andrii@kernel.org
    6b434b61
libbpf_internal.h 18.6 KB