summaryrefslogtreecommitdiffstats
path: root/kernel/bpf/task_iter.c
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2020-08-18 15:23:10 -0700
committerAlexei Starovoitov <ast@kernel.org>2020-08-18 17:36:23 -0700
commite60572b8d4c39572be6857d1ec91fdf979f8775f (patch)
treed4ab349e5c3baa0fb8f2f82ba9dd804e74ada523 /kernel/bpf/task_iter.c
parente679654a704e5bd676ea6446fa7b764cbabf168a (diff)
downloadlinux-e60572b8d4c39572be6857d1ec91fdf979f8775f.tar.bz2
bpf: Avoid visit same object multiple times
Currently when traversing all tasks, the next tid is always increased by one. This may result in visiting the same task multiple times in a pid namespace. This patch fixed the issue by seting the next tid as pid_nr_ns(pid, ns) + 1, similar to funciton next_tgid(). Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Cc: Rik van Riel <riel@surriel.com> Link: https://lore.kernel.org/bpf/20200818222310.2181500-1-yhs@fb.com
Diffstat (limited to 'kernel/bpf/task_iter.c')
-rw-r--r--kernel/bpf/task_iter.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c
index f21b5e1e4540..99af4cea1102 100644
--- a/kernel/bpf/task_iter.c
+++ b/kernel/bpf/task_iter.c
@@ -29,8 +29,9 @@ static struct task_struct *task_seq_get_next(struct pid_namespace *ns,
rcu_read_lock();
retry:
- pid = idr_get_next(&ns->idr, tid);
+ pid = find_ge_pid(*tid, ns);
if (pid) {
+ *tid = pid_nr_ns(pid, ns);
task = get_pid_task(pid, PIDTYPE_PID);
if (!task) {
++*tid;