Re: [PATCH RESEND 1/1] yama: clean-up ptrace relations upon activating YAMA_SCOPE_NO_ATTACH

From: Guicai Ma

Date: Wed Nov 25 2026 - 03:24:26 EST


On Tue, 26 May 2026 11:35:42 -0400, Ethan Ferguson wrote:
> @@ -224,6 +226,9 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
> int rc = -ENOSYS;
> struct task_struct *myself;
>
> + if (ptrace_scope == max_scope)
> + return -EPERM;
> +
> switch (option) {

This check sits above the switch, so it runs for every prctl() option,
not just PR_SET_PTRACER. security_task_prctl() propagates any return
value other than -ENOSYS straight back to userspace, so once
ptrace_scope is set to 3 every prctl() in the system fails with -EPERM,
including PR_SET_NAME, PR_SET_DUMPABLE and PR_SET_NO_NEW_PRIVS. The
check needs to live inside `case PR_SET_PTRACER:`.

> @@ -204,7 +205,8 @@ static void yama_ptracer_del(struct task_struct *tracer,
> */
> static void yama_task_free(struct task_struct *task)
> {
> - yama_ptracer_del(task, task);
> + if (ptrace_scope <= max_scope)
> + yama_ptracer_del(task, task);
> }

ptrace_scope is clamped to [0, max_scope] by the sysctl handler, so this
condition is always true and the hunk is a no-op. Changing it to
`< max_scope` would not be safe either: a prctl(PR_SET_PTRACER) that passes
the scope check just before the sysctl raises it to 3 can insert a relation
after yama_relation_cleanup() has already run, and since scope 3 is
irreversible nothing would mark that entry invalid again. Walking the list
in yama_ptracer_del() is cheap, so dropping this hunk looks safer.

This is a static review against v7.4-rc3; I have not booted the patch.
Are you still working on a respin? I can test one on arm64 with
KASAN/lockdep if that helps.

Thanks,
Guicai