lkml.org 
[lkml]   [2018]   [Sep]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 4.18 097/197] bpf: fix bpffs non-array map seq_show issue
    Date
    4.18-stable review patch.  If anyone has any objections, please let me know.

    ------------------

    From: Yonghong Song <yhs@fb.com>

    [ Upstream commit dc1508a579e682a1e5f1ed0753390e0aa7c23a97 ]

    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: a26ca7c982cb5 ("bpf: btf: Add pretty print support to the basic arraymap")
    Acked-by: Alexei Starovoitov <ast@kernel.org>
    Signed-off-by: Yonghong Song <yhs@fb.com>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    ---
    kernel/bpf/inode.c | 8 +++++---
    1 file changed, 5 insertions(+), 3 deletions(-)

    --- a/kernel/bpf/inode.c
    +++ b/kernel/bpf/inode.c
    @@ -196,19 +196,21 @@ static void *map_seq_next(struct seq_fil
    {
    struct bpf_map *map = seq_file_to_map(m);
    void *key = map_iter(m)->key;
    + void *prev_key;

    if (map_iter(m)->done)
    return NULL;

    if (unlikely(v == SEQ_START_TOKEN))
    - goto done;
    + prev_key = NULL;
    + else
    + prev_key = key;

    - if (map->ops->map_get_next_key(map, key, key)) {
    + if (map->ops->map_get_next_key(map, prev_key, key)) {
    map_iter(m)->done = true;
    return NULL;
    }

    -done:
    ++(*pos);
    return key;
    }

    \
     
     \ /
      Last update: 2018-09-13 16:09    [W:4.027 / U:0.192 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site