diff mbox series

[RFC,3/3] selftests: memfd: error out test process when child test fails

Message ID 20230713143406.14342-4-cyphar@cyphar.com (mailing list archive)
State Accepted
Commit 99f34659e78b9b781a3248e0b080b4dfca4957e2
Headers show
Series memfd: cleanups for vm.memfd_noexec | expand

Commit Message

Aleksa Sarai July 13, 2023, 2:33 p.m. UTC
Before this change, a test runner using this self test would see a
return code of 0 when the tests using a child process (namely the
MFD_NOEXEC_SEAL and MFD_EXEC tests) failed, masking test failures.

Fixes: 11f75a01448f ("selftests/memfd: add tests for MFD_NOEXEC_SEAL MFD_EXEC")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
---
 tools/testing/selftests/memfd/memfd_test.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Comments

Jeff Xu July 19, 2023, 11:38 p.m. UTC | #1
On Thu, Jul 13, 2023 at 7:34 AM Aleksa Sarai <cyphar@cyphar.com> wrote:
>
> Before this change, a test runner using this self test would see a
> return code of 0 when the tests using a child process (namely the
> MFD_NOEXEC_SEAL and MFD_EXEC tests) failed, masking test failures.
>
> Fixes: 11f75a01448f ("selftests/memfd: add tests for MFD_NOEXEC_SEAL MFD_EXEC")
> Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
> ---
>  tools/testing/selftests/memfd/memfd_test.c | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
> index d8342989c547..8b7390ad81d1 100644
> --- a/tools/testing/selftests/memfd/memfd_test.c
> +++ b/tools/testing/selftests/memfd/memfd_test.c
> @@ -1219,7 +1219,24 @@ static pid_t spawn_newpid_thread(unsigned int flags, int (*fn)(void *))
>
>  static void join_newpid_thread(pid_t pid)
>  {
> -       waitpid(pid, NULL, 0);
> +       int wstatus;
> +
> +       if (waitpid(pid, &wstatus, 0) < 0) {
> +               printf("newpid thread: waitpid() failed: %m\n");
> +               abort();
> +       }
> +
> +       if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != 0) {
> +               printf("newpid thread: exited with non-zero error code %d\n",
> +                      WEXITSTATUS(wstatus));
> +               abort();
> +       }
> +
> +       if (WIFSIGNALED(wstatus)) {
> +               printf("newpid thread: killed by signal %d\n",
> +                      WTERMSIG(wstatus));
> +               abort();
> +       }
>  }
>
Signed-off-by: Jeff Xu <jeffxu@google.com>

-Jeff Xu

>  /*
> --
> 2.41.0
>
Aleksa Sarai Aug. 3, 2023, 2:25 a.m. UTC | #2
On 2023-07-19, Jeff Xu <jeffxu@google.com> wrote:
> On Thu, Jul 13, 2023 at 7:34 AM Aleksa Sarai <cyphar@cyphar.com> wrote:
> >
> > Before this change, a test runner using this self test would see a
> > return code of 0 when the tests using a child process (namely the
> > MFD_NOEXEC_SEAL and MFD_EXEC tests) failed, masking test failures.
> >
> > Fixes: 11f75a01448f ("selftests/memfd: add tests for MFD_NOEXEC_SEAL MFD_EXEC")
> > Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
> > ---
> >  tools/testing/selftests/memfd/memfd_test.c | 19 ++++++++++++++++++-
> >  1 file changed, 18 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
> > index d8342989c547..8b7390ad81d1 100644
> > --- a/tools/testing/selftests/memfd/memfd_test.c
> > +++ b/tools/testing/selftests/memfd/memfd_test.c
> > @@ -1219,7 +1219,24 @@ static pid_t spawn_newpid_thread(unsigned int flags, int (*fn)(void *))
> >
> >  static void join_newpid_thread(pid_t pid)
> >  {
> > -       waitpid(pid, NULL, 0);
> > +       int wstatus;
> > +
> > +       if (waitpid(pid, &wstatus, 0) < 0) {
> > +               printf("newpid thread: waitpid() failed: %m\n");
> > +               abort();
> > +       }
> > +
> > +       if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != 0) {
> > +               printf("newpid thread: exited with non-zero error code %d\n",
> > +                      WEXITSTATUS(wstatus));
> > +               abort();
> > +       }
> > +
> > +       if (WIFSIGNALED(wstatus)) {
> > +               printf("newpid thread: killed by signal %d\n",
> > +                      WTERMSIG(wstatus));
> > +               abort();
> > +       }
> >  }
> >
> Signed-off-by: Jeff Xu <jeffxu@google.com>

Did you mean for this to a Reviewed-by?
Jeff Xu Aug. 3, 2023, 2:55 a.m. UTC | #3
On Wed, Aug 2, 2023 at 7:25 PM Aleksa Sarai <cyphar@cyphar.com> wrote:
>
> On 2023-07-19, Jeff Xu <jeffxu@google.com> wrote:
> > On Thu, Jul 13, 2023 at 7:34 AM Aleksa Sarai <cyphar@cyphar.com> wrote:
> > >
> > > Before this change, a test runner using this self test would see a
> > > return code of 0 when the tests using a child process (namely the
> > > MFD_NOEXEC_SEAL and MFD_EXEC tests) failed, masking test failures.
> > >
> > > Fixes: 11f75a01448f ("selftests/memfd: add tests for MFD_NOEXEC_SEAL MFD_EXEC")
> > > Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
> > > ---
> > >  tools/testing/selftests/memfd/memfd_test.c | 19 ++++++++++++++++++-
> > >  1 file changed, 18 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
> > > index d8342989c547..8b7390ad81d1 100644
> > > --- a/tools/testing/selftests/memfd/memfd_test.c
> > > +++ b/tools/testing/selftests/memfd/memfd_test.c
> > > @@ -1219,7 +1219,24 @@ static pid_t spawn_newpid_thread(unsigned int flags, int (*fn)(void *))
> > >
> > >  static void join_newpid_thread(pid_t pid)
> > >  {
> > > -       waitpid(pid, NULL, 0);
> > > +       int wstatus;
> > > +
> > > +       if (waitpid(pid, &wstatus, 0) < 0) {
> > > +               printf("newpid thread: waitpid() failed: %m\n");
> > > +               abort();
> > > +       }
> > > +
> > > +       if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != 0) {
> > > +               printf("newpid thread: exited with non-zero error code %d\n",
> > > +                      WEXITSTATUS(wstatus));
> > > +               abort();
> > > +       }
> > > +
> > > +       if (WIFSIGNALED(wstatus)) {
> > > +               printf("newpid thread: killed by signal %d\n",
> > > +                      WTERMSIG(wstatus));
> > > +               abort();
> > > +       }
> > >  }
> > >
> > Signed-off-by: Jeff Xu <jeffxu@google.com>
>
> Did you mean for this to a Reviewed-by?
>
Yes! Thanks for asking.

Reviewed-by: Jeff Xu <jeffxu@google.com>


> --
> Aleksa Sarai
> Senior Software Engineer (Containers)
> SUSE Linux GmbH
> <https://www.cyphar.com/>
diff mbox series

Patch

diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
index d8342989c547..8b7390ad81d1 100644
--- a/tools/testing/selftests/memfd/memfd_test.c
+++ b/tools/testing/selftests/memfd/memfd_test.c
@@ -1219,7 +1219,24 @@  static pid_t spawn_newpid_thread(unsigned int flags, int (*fn)(void *))
 
 static void join_newpid_thread(pid_t pid)
 {
-	waitpid(pid, NULL, 0);
+	int wstatus;
+
+	if (waitpid(pid, &wstatus, 0) < 0) {
+		printf("newpid thread: waitpid() failed: %m\n");
+		abort();
+	}
+
+	if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus) != 0) {
+		printf("newpid thread: exited with non-zero error code %d\n",
+		       WEXITSTATUS(wstatus));
+		abort();
+	}
+
+	if (WIFSIGNALED(wstatus)) {
+		printf("newpid thread: killed by signal %d\n",
+		       WTERMSIG(wstatus));
+		abort();
+	}
 }
 
 /*