]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/namespaces: Fix racy pipe handshake in timens and pidns_separate
authorRicardo B. Marlière (SUSE) <ricardo@marliere.net>
Mon, 10 Aug 2026 20:56:00 +0000 (17:56 -0300)
committerChristian Brauner <brauner@kernel.org>
Thu, 13 Aug 2026 10:20:42 +0000 (12:20 +0200)
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>
Link: https://patch.msgid.link/20260810-selftests-namespaces_race-v1-1-4307e833783e@marliere.net
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
tools/testing/selftests/namespaces/nsid_test.c

index 46dc838cba82d2ed72736f03f26e951f6d0dff28..a16f31f41d38fdc301c0c46ce34fc52fc501d9eb 100644 (file)
@@ -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);