[PATCH] yama: fix use-after-free read of a dead PR_SET_PTRACER tracer
Guicai Ma
maguicai at kylinos.cn
Tue Nov 24 10:41:04 UTC 2026
On Tue, Nov 24, 2026 at 12:53:57AM +0800, Henry Martin wrote:
> Keep the tracer's struct pid alive for the lifetime of the relation and
> resolve it with pid_task() under RCU at access-check time. Pinning the
> task_struct itself would not work: the relation is only invalidated from
> yama_task_free(), which runs when the tracer's task_struct is finally
> released, so a task reference would keep the relation, and therefore the
> task, alive forever.
Looks good to me. Checking !relation->tracer before pid_task() also
handles the case where the tracer detaches its pid between
find_get_task_by_vpid() and get_task_pid(), so a NULL tracer_pid is not
treated as PR_SET_PTRACER_ANY, and yama_task_free() still cleans the
entry up on the final put_task_struct(). Calling put_pid() from the RCU
callback is safe here as well.
Tested on 7.4.0-rc3 arm64 in QEMU with KASAN, lockdep and
CONFIG_SECURITY_YAMA=y (ptrace_scope=1): built cleanly with W=1, ran
PR_SET_PTRACER functional checks and a concurrent process_vm_readv()
stress loop against exiting tracers with no KASAN or lockdep warnings.
Reviewed-by: Guicai Ma <maguicai at kylinos.cn>
Tested-by: Guicai Ma <maguicai at kylinos.cn>
More information about the Linux-security-module-archive
mailing list