linux/tools/testing/selftests/prctl
Hongfu Li 8f1d96a16c selftests/prctl: fix non-anonymous VMA mapping in set-anon-vma-name test
The test creates a non-anonymous VMA (ptr_not_anon) via mmap() with
MAP_PRIVATE but without MAP_ANONYMOUS, using fd=0 (stdin) as the file
descriptor.  This always fails because fd=0 is not a regular file, and the
failure was hidden because ASSERT_NE() incorrectly checked for NULL
instead of MAP_FAILED.

Fix by using mkstemp() + ftruncate() to create a real temporary file, then
mapping it with MAP_PRIVATE to obtain a genuine file-backed VMA.  Also fix
the mmap() error checks to use MAP_FAILED instead of NULL, and pass fd=-1
for the anonymous mapping for clarity.  The temp file is unlinked
immediately so it does not persist on disk.

Link: https://lore.kernel.org/20260803103046.14324-1-hongfu.li@linux.dev
Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Wei Yang <richard.weiyang@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2026-08-13 15:42:07 -07:00
..
.gitignore selftests:prctl: add set-process-name to .gitignore 2023-07-25 10:33:25 -06:00
config selftests: prctl: Add new prctl test for PR_SET_VMA action 2023-03-28 10:28:33 -06:00
disable-tsc-ctxt-sw-stress-test.c selftests: Fix spelling mistake "allright" -> "all right" 2023-02-13 09:09:46 -07:00
disable-tsc-on-off-stress-test.c selftests: Fix spelling mistake "allright" -> "all right" 2023-02-13 09:09:46 -07:00
disable-tsc-test.c
Makefile selftests: fix ARCH normalization to handle command-line argument 2026-03-27 21:19:44 -07:00
set-anon-vma-name-test.c selftests/prctl: fix non-anonymous VMA mapping in set-anon-vma-name test 2026-08-13 15:42:07 -07:00
set-process-name.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00