Re: [PATCH bpf-next 1/3] bpf: Make struct task_struct an RCU-safe type
From: Alexei Starovoitov
Date: Fri Mar 31 2023 - 13:05:41 EST
On Thu, Mar 30, 2023 at 07:57:31PM -0500, David Vernet wrote:
> kernel/bpf/helpers.c | 11 ++-
> kernel/bpf/verifier.c | 1 +
> .../selftests/bpf/prog_tests/task_kfunc.c | 2 +
> .../selftests/bpf/progs/task_kfunc_common.h | 5 +
> .../selftests/bpf/progs/task_kfunc_failure.c | 98 +++++++++++++++++--
> .../selftests/bpf/progs/task_kfunc_success.c | 52 +++++++++-
> 6 files changed, 153 insertions(+), 16 deletions(-)
See CI failures on gcc compiled kernel:
https://github.com/kernel-patches/bpf/actions/runs/4570493668/jobs/8068004031
> __bpf_kfunc struct task_struct *bpf_task_acquire(struct task_struct *p)
> {
> - return get_task_struct(p);
> + if (refcount_inc_not_zero(&p->rcu_users))
> + return p;
> + return NULL;
> }
I wonder whether we should add a bit of safety net here.
Like do not allow acquire of tasks with PF_KTHREAD | PF_EXITING
or at least is_idle_task ?