Skip to content

Commit

Permalink
bpf: bpf_iter_task_next: use __next_thread() rather than next_thread()
Browse files Browse the repository at this point in the history
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 <oleg@redhat.com>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20231114163237.GA897@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Oleg Nesterov authored and Alexei Starovoitov committed Nov 19, 2023
1 parent 2d16180 commit 5a34f9d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions kernel/bpf/task_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,12 +1015,11 @@ __bpf_kfunc struct task_struct *bpf_iter_task_next(struct bpf_iter_task *it)
if (flags == BPF_TASK_ITER_ALL_PROCS)
goto get_next_task;

kit->pos = next_thread(kit->pos);
if (kit->pos == kit->task) {
if (flags == BPF_TASK_ITER_PROC_THREADS) {
kit->pos = NULL;
kit->pos = __next_thread(kit->pos);
if (!kit->pos) {
if (flags == BPF_TASK_ITER_PROC_THREADS)
return pos;
}
kit->pos = kit->task;
} else
return pos;

Expand Down

0 comments on commit 5a34f9d

Please sign in to comment.