Skip to content

Commit e60572b

Browse files
yonghong-songAlexei Starovoitov
authored andcommitted
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 <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Cc: Rik van Riel <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent e679654 commit e60572b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/bpf/task_iter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ static struct task_struct *task_seq_get_next(struct pid_namespace *ns,
2929

3030
rcu_read_lock();
3131
retry:
32-
pid = idr_get_next(&ns->idr, tid);
32+
pid = find_ge_pid(*tid, ns);
3333
if (pid) {
34+
*tid = pid_nr_ns(pid, ns);
3435
task = get_pid_task(pid, PIDTYPE_PID);
3536
if (!task) {
3637
++*tid;

0 commit comments

Comments
 (0)