• Yonghong Song's avatar
    bpf: fix bpffs non-array map seq_show issue · dc1508a5
    Yonghong Song authored
    In function map_seq_next() of kernel/bpf/inode.c,
    the first key will be the "0" regardless of the map type.
    This works for array. But for hash type, if it happens
    key "0" is in the map, the bpffs map show will miss
    some items if the key "0" is not the first element of
    the first bucket.
    
    This patch fixed the issue by guaranteeing to get
    the first element, if the seq_show is just started,
    by passing NULL pointer key to map_get_next_key() callback.
    This way, no missing elements will occur for
    bpffs hash table show even if key "0" is in the map.
    
    Fixes: a26ca7c9 ("bpf: btf: Add pretty print support to the basic arraymap")
    Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Signed-off-by: default avatarYonghong Song <yhs@fb.com>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    dc1508a5
inode.c 13.5 KB