selftests/clone3: Check that the child exited cleanly
authorMark Brown <broonie@kernel.org>
Tue, 9 Apr 2024 20:39:43 +0000 (21:39 +0100)
committerShuah Khan <skhan@linuxfoundation.org>
Mon, 6 May 2024 19:57:20 +0000 (13:57 -0600)
When the child exits during the clone3() selftest we use WEXITSTATUS() to
get the exit status from the process without first checking WIFEXITED() to
see if the result will be valid. This can lead to incorrect results, for
example if the child exits due to signal. Add a WIFEXTED() check and report
any non-standard exit as a failure, using EXIT_FAILURE as the exit status
for call_clone3() since we otherwise report 0 or negative errnos.

Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/clone3/clone3.c

index 3c9bf0cd82a80dfe4189e273efbd9693f4f61b22..0e0e5dfa97c655dcf4cfbb1e63ba770bf924cb9f 100644 (file)
@@ -98,6 +98,11 @@ static int call_clone3(uint64_t flags, size_t size, enum test_mode test_mode)
                ksft_print_msg("Child returned %s\n", strerror(errno));
                return -errno;
        }
+       if (!WIFEXITED(status)) {
+               ksft_print_msg("Child did not exit normally, status 0x%x\n",
+                              status);
+               return EXIT_FAILURE;
+       }
        if (WEXITSTATUS(status))
                return WEXITSTATUS(status);