mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-10 15:58:47 +00:00
bpf: Fix pos computation for bpf_iter seq_ops->start()
Currently, the pos pointer in bpf iterator map/task/task_file seq_ops->start() is always incremented. This is incorrect. It should be increased only if *pos is 0 (for SEQ_START_TOKEN) since these start() function actually returns the first real object. If *pos is not 0, it merely found the object based on the state in seq->private, and not really advancing the *pos. This patch fixed this issue by only incrementing *pos if it is 0. Note that the old *pos calculation, although not correct, does not affect correctness of bpf_iter as bpf_iter seq_file->read() does not support llseek. This patch also renamed "mid" in bpf_map iterator seq_file private data to "map_id" for better clarity. Fixes: 6086d29def80 ("bpf: Add bpf_map iterator") Fixes: eaaacd23910f ("bpf: Add task and task/file iterator targets") Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200722195156.4029817-1-yhs@fb.com
This commit is contained in:
parent
86176a1821
commit
3f9969f2c0
@ -7,7 +7,7 @@
|
|||||||
#include <linux/btf_ids.h>
|
#include <linux/btf_ids.h>
|
||||||
|
|
||||||
struct bpf_iter_seq_map_info {
|
struct bpf_iter_seq_map_info {
|
||||||
u32 mid;
|
u32 map_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void *bpf_map_seq_start(struct seq_file *seq, loff_t *pos)
|
static void *bpf_map_seq_start(struct seq_file *seq, loff_t *pos)
|
||||||
@ -15,10 +15,11 @@ static void *bpf_map_seq_start(struct seq_file *seq, loff_t *pos)
|
|||||||
struct bpf_iter_seq_map_info *info = seq->private;
|
struct bpf_iter_seq_map_info *info = seq->private;
|
||||||
struct bpf_map *map;
|
struct bpf_map *map;
|
||||||
|
|
||||||
map = bpf_map_get_curr_or_next(&info->mid);
|
map = bpf_map_get_curr_or_next(&info->map_id);
|
||||||
if (!map)
|
if (!map)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (*pos == 0)
|
||||||
++*pos;
|
++*pos;
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
@ -26,16 +27,11 @@ static void *bpf_map_seq_start(struct seq_file *seq, loff_t *pos)
|
|||||||
static void *bpf_map_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
static void *bpf_map_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
||||||
{
|
{
|
||||||
struct bpf_iter_seq_map_info *info = seq->private;
|
struct bpf_iter_seq_map_info *info = seq->private;
|
||||||
struct bpf_map *map;
|
|
||||||
|
|
||||||
++*pos;
|
++*pos;
|
||||||
++info->mid;
|
++info->map_id;
|
||||||
bpf_map_put((struct bpf_map *)v);
|
bpf_map_put((struct bpf_map *)v);
|
||||||
map = bpf_map_get_curr_or_next(&info->mid);
|
return bpf_map_get_curr_or_next(&info->map_id);
|
||||||
if (!map)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bpf_iter__bpf_map {
|
struct bpf_iter__bpf_map {
|
||||||
|
@ -51,6 +51,7 @@ static void *task_seq_start(struct seq_file *seq, loff_t *pos)
|
|||||||
if (!task)
|
if (!task)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (*pos == 0)
|
||||||
++*pos;
|
++*pos;
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
@ -210,6 +211,7 @@ static void *task_file_seq_start(struct seq_file *seq, loff_t *pos)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (*pos == 0)
|
||||||
++*pos;
|
++*pos;
|
||||||
info->task = task;
|
info->task = task;
|
||||||
info->files = files;
|
info->files = files;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user