OSDN Git Service

bpf: Avoid visit same object multiple times
authorYonghong Song <yhs@fb.com>
Tue, 18 Aug 2020 22:23:10 +0000 (15:23 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 19 Aug 2020 00:36:23 +0000 (17:36 -0700)
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
kernel/bpf/task_iter.c

index f21b5e1..99af4ce 100644 (file)
@@ -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;