Skip to content

Commit 5a34f9d

Browse files
oleg-nesterovAlexei Starovoitov
authored andcommitted
bpf: bpf_iter_task_next: use __next_thread() rather than next_thread()
Lockless use of next_thread() should be avoided, kernel/bpf/task_iter.c is the last user and the usage is wrong. bpf_iter_task_next() can loop forever, "kit->pos == kit->task" can never happen if kit->pos execs. Change this code to use __next_thread(). With or without this change the usage of kit->pos/task and next_task() doesn't look nice, see the next patch. Signed-off-by: Oleg Nesterov <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 2d16180 commit 5a34f9d

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

kernel/bpf/task_iter.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,12 +1015,11 @@ __bpf_kfunc struct task_struct *bpf_iter_task_next(struct bpf_iter_task *it)
10151015
if (flags == BPF_TASK_ITER_ALL_PROCS)
10161016
goto get_next_task;
10171017

1018-
kit->pos = next_thread(kit->pos);
1019-
if (kit->pos == kit->task) {
1020-
if (flags == BPF_TASK_ITER_PROC_THREADS) {
1021-
kit->pos = NULL;
1018+
kit->pos = __next_thread(kit->pos);
1019+
if (!kit->pos) {
1020+
if (flags == BPF_TASK_ITER_PROC_THREADS)
10221021
return pos;
1023-
}
1022+
kit->pos = kit->task;
10241023
} else
10251024
return pos;
10261025

0 commit comments

Comments
 (0)