Re: [PATCH] yama: hold the PR_SET_PTRACER tracer by its struct pid

From: Guicai Ma

Date: Fri Nov 20 2026 - 02:53:10 EST


On Thu, Nov 19, 2026 at 11:59:18AM +0900, JunYoung Lee wrote:
> Once the tracer has been reaped,
> pid_task() returns NULL and the relation matches no tracer. That is
> what an invalidated relation did before, so the tracer side of
> yama_task_free() is no longer needed. The relation itself is still
> removed when the tracee goes away or registers a new tracer. The pid
> reference is dropped from an RCU callback after the relation is
> unlinked.

Since yama_ptracer_add() replaces any existing entry for the same tracee
and release_task() frees the pid number on reap, leaving the relation in
place only pins at most one struct pid per live tracee until replacement
or tracee exit. The pid refcounting and call_rcu() teardown look good to
me.

Tested on arm64 under KASAN (ptrace_scope=1), covering the PR_SET_PTRACER
cases (including from a non-leader thread), relation replacement churn,
and concurrent process_vm_readv() against rapid tracer fork/reap.

Reviewed-by: Guicai Ma <maguicai@xxxxxxxxxx>
Tested-by: Guicai Ma <maguicai@xxxxxxxxxx>