public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf] bpf: fix bpffs non-array map seq_show issue
@ 2018-08-09  1:25 Yonghong Song
  2018-08-09  2:25 ` Alexei Starovoitov
  0 siblings, 1 reply; 10+ messages in thread
From: Yonghong Song @ 2018-08-09  1:25 UTC (permalink / raw)
  To: ast, daniel, netdev; +Cc: kernel-team

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")
Signed-off-by: Yonghong Song <yhs@fb.com>
---
 kernel/bpf/inode.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c
index 76efe9a183f5..794d06186e93 100644
--- a/kernel/bpf/inode.c
+++ b/kernel/bpf/inode.c
@@ -196,14 +196,17 @@ static void *map_seq_next(struct seq_file *m, void *v, loff_t *pos)
 {
 	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;
 	}
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-08-09 22:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-09  1:25 [PATCH bpf] bpf: fix bpffs non-array map seq_show issue Yonghong Song
2018-08-09  2:25 ` Alexei Starovoitov
2018-08-09  3:55   ` Yonghong Song
2018-08-09 14:24     ` Daniel Borkmann
2018-08-09 15:15       ` Yonghong Song
2018-08-09 15:59         ` Daniel Borkmann
2018-08-09 16:55           ` Yonghong Song
2018-08-09 17:02             ` Daniel Borkmann
2018-08-09 17:54               ` Yonghong Song
2018-08-09 19:44                 ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox