* [PATCH v2] selftests/mm: fix ptrace PEEKDATA check in memfd_secret test
@ 2026-09-10 6:44 Hongfu Li
0 siblings, 0 replies; only message in thread
From: Hongfu Li @ 2026-09-10 6:44 UTC (permalink / raw)
To: akpm, david, ljs, liam, vbabka, rppt, surenb, mhocko, shuah,
James.Bottomley
Cc: linux-mm, linux-kselftest, linux-kernel, Hongfu Li
From: Hongfu Li <lihongfu@kylinos.cn>
try_ptrace() treats PTRACE_PEEKDATA return value as a boolean
check. A successful read returns non-zero data (memory filled with
0x55), causing the test to incorrectly report PASS when secret memory
protection is broken.
Check the return value against -1 instead. The test should only pass
when PTRACE_PEEKDATA fails, which means secret memory protection works.
Fixes: 76fe17ef588a ("secretmem: test: add basic selftest for memfd_secret(2)")
Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
v2:
- Add a comment explaining why PEEKDATA on secret memory is expected to
fail, as suggested during review.
- Add Acked-by from Lorenzo Stoakes and Mike Rapoport
---
tools/testing/selftests/mm/memfd_secret.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/memfd_secret.c b/tools/testing/selftests/mm/memfd_secret.c
index c55d84c5e613..aef774be87f1 100644
--- a/tools/testing/selftests/mm/memfd_secret.c
+++ b/tools/testing/selftests/mm/memfd_secret.c
@@ -145,7 +145,8 @@ static void try_ptrace(int fd, int pipefd[2])
exit(KSFT_FAIL);
}
- if (ptrace(PTRACE_PEEKDATA, ppid, mem, 0))
+ /* PEEKDATA on secret memory must fail, else protection is broken. */
+ if (ptrace(PTRACE_PEEKDATA, ppid, mem, 0) == -1)
exit(KSFT_PASS);
exit(KSFT_FAIL);
--
2.54.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-09-10 6:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-10 6:44 [PATCH v2] selftests/mm: fix ptrace PEEKDATA check in memfd_secret test Hongfu Li
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.