[PATCH 0/2] selftests/yama: add ptrace_scope and PR_SET_PTRACER tests
From: Guicai Ma
Date: Wed Nov 25 2026 - 08:00:02 EST
Yama has no selftest coverage. This series adds a new selftests/yama
directory: 1/2 provides the scaffolding and covers the ptrace_scope
sysctl and the attach matrix, 2/2 adds the PR_SET_PTRACER exception
tests.
The PR_SET_PTRACER lifecycle tests exercise the same grant, replacement
and revocation semantics as the recent tracer-lifetime fix linked below,
and pass both on mainline and with that fix applied.
Scope 3 is irreversible until reboot, so it is only tested when
ptrace_scope is already 3, or when YAMA_TEST_NO_ATTACH=1 opts in.
Privileged cases are skipped when the capability set does not allow
them, so the tests also run in restricted containers.
Tested on arm64 (QEMU/KVM, KASAN + lockdep): 10 rounds of both binaries
as root and as an unprivileged user, plus a final ptrace_scope=3 pass;
a boot with lsm=capability verifies that every test skips cleanly when
Yama is inactive.
Link: https://lore.kernel.org/r/20261123165357.4092273-1-bsdhenrymartin@xxxxxxxxx
Guicai Ma (2):
selftests/yama: add ptrace_scope selftests
selftests/yama: add PR_SET_PTRACER tests
MAINTAINERS | 1 +
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/yama/.gitignore | 3 +
tools/testing/selftests/yama/Makefile | 13 +
tools/testing/selftests/yama/common.h | 233 +++++++++
tools/testing/selftests/yama/config | 4 +
.../selftests/yama/ptrace_scope_test.c | 452 ++++++++++++++++++
tools/testing/selftests/yama/ptracer_test.c | 403 ++++++++++++++++
8 files changed, 1110 insertions(+)
create mode 100644 tools/testing/selftests/yama/.gitignore
create mode 100644 tools/testing/selftests/yama/Makefile
create mode 100644 tools/testing/selftests/yama/common.h
create mode 100644 tools/testing/selftests/yama/config
create mode 100644 tools/testing/selftests/yama/ptrace_scope_test.c
create mode 100644 tools/testing/selftests/yama/ptracer_test.c
--
2.47.3