linux/tools/testing/selftests/memfd
Aristeu Rozanski b24335521d selftests/memfd: use IPC semaphore instead of SIGSTOP/SIGCONT
selftests/memfd: use IPC semaphore instead of SIGSTOP/SIGCONT

In order to synchronize new processes to test inheritance of memfd_noexec
sysctl, memfd_test sets up the sysctl with a value before creating the new
process.  The new process then sends itself a SIGSTOP in order to wait for
the parent to flip the sysctl value and send a SIGCONT signal.

This would work as intended if it wasn't the fact that the new process is
being created with CLONE_NEWPID, which creates a new PID namespace and the
new process has PID 1 in this namespace.  There're restrictions on sending
signals to PID 1 and, although it's relaxed for other than root PID
namespace, it's biting us here.  In this specific case the SIGSTOP sent by
the new process is ignored (no error to kill() is returned) and it never
stops its execution.  This is usually not noticiable as the parent usually
manages to set the new sysctl value before the child has a chance to run
and the test succeeds.  But if you run the test in a loop, it eventually
reproduces:

	while [ 1 ]; do ./memfd_test >log 2>&1 || break; done; cat log

So this patch replaces the SIGSTOP/SIGCONT synchronization with IPC
semaphore.

Link: https://lkml.kernel.org/r/a7776389-b3d6-4b18-b438-0b0e3ed1fd3b@work
Fixes: 6469b66e3f ("selftests: improve vm.memfd_noexec sysctl tests")
Signed-off-by: Aristeu Rozanski <aris@redhat.com>
Cc: Aleksa Sarai <cyphar@cyphar.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: liuye <liuye@kylinos.cn>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2026-02-12 15:45:57 -08:00
..
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
common.c memfd-test: move common code to a shared unit 2018-01-31 17:18:39 -08:00
common.h memfd-test: move common code to a shared unit 2018-01-31 17:18:39 -08:00
config selftests: memfd: add config fragment for fuse 2018-02-13 14:13:53 -07:00
fuse_mnt.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
fuse_test.c selftests/memfd: fix spelling mistakes 2024-05-07 10:36:59 -07:00
Makefile selftests: memfd: Use installed kernel headers search path 2023-02-13 09:09:46 -07:00
memfd_test.c selftests/memfd: use IPC semaphore instead of SIGSTOP/SIGCONT 2026-02-12 15:45:57 -08:00
run_fuse_test.sh memfd-test: run fuse test on hugetlb backend memory 2018-01-31 17:18:39 -08:00
run_hugetlbfs_test.sh selftests: memfd: split regular and hugetlbfs tests 2018-05-30 15:29:06 -06:00