• Anquan Wu's avatar
    libbpf: Fix the name of a reused map · bf3f0037
    Anquan Wu authored
    BPF map name is limited to BPF_OBJ_NAME_LEN.
    A map name is defined as being longer than BPF_OBJ_NAME_LEN,
    it will be truncated to BPF_OBJ_NAME_LEN when a userspace program
    calls libbpf to create the map. A pinned map also generates a path
    in the /sys. If the previous program wanted to reuse the map,
    it can not get bpf_map by name, because the name of the map is only
    partially the same as the name which get from pinned path.
    
    The syscall information below show that map name "process_pinned_map"
    is truncated to "process_pinned_".
    
        bpf(BPF_OBJ_GET, {pathname="/sys/fs/bpf/process_pinned_map",
        bpf_fd=0, file_flags=0}, 144) = -1 ENOENT (No such file or directory)
    
        bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_HASH, key_size=4,
        value_size=4,max_entries=1024, map_flags=0, inner_map_fd=0,
        map_name="process_pinned_",map_ifindex=0, btf_fd=3, btf_key_type_id=6,
        btf_value_type_id=10,btf_vmlinux_value_type_id=0}, 72) = 4
    
    This patch check that if the name of pinned map are the same as the
    actual name for the first (BPF_OBJ_NAME_LEN - 1),
    bpf map still uses the name which is included in bpf object.
    
    Fixes: 26736eb9 ("tools: libbpf: allow map reuse")
    Signed-off-by: default avatarAnquan Wu <leiqi96@hotmail.com>
    Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/OSZP286MB1725CEA1C95C5CB8E7CCC53FB8869@OSZP286MB1725.JPNP286.PROD.OUTLOOK.COM
    bf3f0037
libbpf.c 320 KB