[PATCH] selftests/namespaces: Fix racy pipe handshake in timens and pidns_separate

Ricardo B. Marlière (SUSE) posted 1 patch 1 month, 2 weeks ago
tools/testing/selftests/namespaces/nsid_test.c | 4 ----
1 file changed, 4 deletions(-)
[PATCH] selftests/namespaces: Fix racy pipe handshake in timens and pidns_separate
Posted by Ricardo B. Marlière (SUSE) 1 month, 2 weeks ago
In timens_separate and pidns_separate both the child and the grandchild
write a 'Y' readiness byte to the same pipe, but the parent expects a
single 'Y' followed by the grandchild's pid. If the grandchild's byte
arrives first, the parent takes it for the child's and reads the pid
misaligned, ending up with a garbage value.

The parent stores that pid in self->grandchild_pid so that
FIXTURE_TEARDOWN() can kill the grandchild. A garbage pid leaves the real
grandchild alive in pause(), holding the test runner's TAP pipe open and
hanging the whole collection.

The grandchild has nothing to report, so drop its write() and leave the
child as the sole writer.

Fixes: fdb48976b637 ("selftests/namespaces: Kill grandchild in nsid fixture teardown")
Signed-off-by: Ricardo B. Marlière (SUSE) <ricardo@marliere.net>
---
Hi,

Please consider merging this simple fix. The error has been found through
openSUSE CI, which hits it sometimes:

https://openqa.opensuse.org/tests/6132140#step/kselftests_run/107

Thanks!
---
 tools/testing/selftests/namespaces/nsid_test.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/tools/testing/selftests/namespaces/nsid_test.c b/tools/testing/selftests/namespaces/nsid_test.c
index 46dc838cba82..a16f31f41d38 100644
--- a/tools/testing/selftests/namespaces/nsid_test.c
+++ b/tools/testing/selftests/namespaces/nsid_test.c
@@ -649,8 +649,6 @@ TEST_F(nsid, timens_separate)
 		/* Fork a grandchild to actually enter the new namespace */
 		pid_t grandchild = fork();
 		if (grandchild == 0) {
-			/* Grandchild is in the new namespace */
-			write(pipefd[1], "Y", 1);
 			close(pipefd[1]);
 			pause();
 			_exit(0);
@@ -771,8 +769,6 @@ TEST_F(nsid, pidns_separate)
 		/* Fork a grandchild to actually enter the new namespace */
 		pid_t grandchild = fork();
 		if (grandchild == 0) {
-			/* Grandchild is in the new namespace */
-			write(pipefd[1], "Y", 1);
 			close(pipefd[1]);
 			pause();
 			_exit(0);

---
base-commit: db2ddb87143519e20a95aa36c60b36107b736a58
change-id: 20260810-selftests-namespaces_race-d8ff98f35732

Best regards,
--  
Ricardo B. Marlière (SUSE) <ricardo@marliere.net>

Re: [PATCH] selftests/namespaces: Fix racy pipe handshake in timens and pidns_separate
Posted by Christian Brauner 1 month, 2 weeks ago
On Mon, 10 Aug 2026 17:56:00 -0300, Ricardo B. Marlière (SUSE) wrote:
> selftests/namespaces: Fix racy pipe handshake in timens and pidns_separate

Applied to the vfs-7.3.misc branch of the vfs/vfs.git tree.
Patches in the vfs-7.3.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.3.misc

[1/1] selftests/namespaces: Fix racy pipe handshake in timens and pidns_separate
      https://git.kernel.org/vfs/vfs/c/dcacab904fe7