tunables: Fail tests correctly when setgid does not work

Message ID 1486060295-4624-1-git-send-email-siddhesh@sourceware.org
State New, archived
Headers

Commit Message

Siddhesh Poyarekar Feb. 2, 2017, 6:31 p.m. UTC
  The child process of the tst-env-setuid process was failing correctly
with EXIT_UNSUPPORTED but the parent did not carry that status forward
and failed instead.  This patch fixes this so that tests on nosuid
/tmp fails gracefully with UNSUPPORTED.  Tested by making my tmpfs
nosuid.

	* elf/tst-env-setuid.c (do_execve): Return EXIT_UNSUPPORTED in
	parent if child exited in that manner.  Print WEXITSTATUS
	instead of the raw status.
	(do_test_prep): Rename to do_test.
	(do_test): Return the result of run_executable_sgid.
	(TEST_FUNCTION_ARGV): Adjust.
---
 elf/tst-env-setuid.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
  

Comments

Siddhesh Poyarekar Feb. 3, 2017, 10:36 a.m. UTC | #1
Ping, I'll commit this before I cut the release on Sunday if there are
no objections since I got Carlos also to test an initial version of the
patch last night.

Siddhesh

On Friday 03 February 2017 12:01 AM, Siddhesh Poyarekar wrote:
> The child process of the tst-env-setuid process was failing correctly
> with EXIT_UNSUPPORTED but the parent did not carry that status forward
> and failed instead.  This patch fixes this so that tests on nosuid
> /tmp fails gracefully with UNSUPPORTED.  Tested by making my tmpfs
> nosuid.
> 
> 	* elf/tst-env-setuid.c (do_execve): Return EXIT_UNSUPPORTED in
> 	parent if child exited in that manner.  Print WEXITSTATUS
> 	instead of the raw status.
> 	(do_test_prep): Rename to do_test.
> 	(do_test): Return the result of run_executable_sgid.
> 	(TEST_FUNCTION_ARGV): Adjust.
> ---
>  elf/tst-env-setuid.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/elf/tst-env-setuid.c b/elf/tst-env-setuid.c
> index 85d423d..6ec3fa5 100644
> --- a/elf/tst-env-setuid.c
> +++ b/elf/tst-env-setuid.c
> @@ -87,10 +87,13 @@ do_execve (char **args)
>        return 1;
>      }
>  
> +  if (WEXITSTATUS (status) == EXIT_UNSUPPORTED)
> +    return EXIT_UNSUPPORTED;
> +
>    if (!WIFEXITED (status) || WEXITSTATUS (status) != CHILD_STATUS)
>      {
>        printf ("Unexpected exit status %d from child process\n",
> -	      status);
> +	      WEXITSTATUS (status));
>        return 1;
>      }
>    return 0;
> @@ -235,7 +238,7 @@ test_parent (void)
>  #endif
>  
>  static int
> -do_test_prep (int argc, char **argv)
> +do_test (int argc, char **argv)
>  {
>    /* Setgid child process.  */
>    if (argc == 2 && strcmp (argv[1], SETGID_CHILD) == 0)
> @@ -270,13 +273,12 @@ do_test_prep (int argc, char **argv)
>  	  exit (0);
>  	}
>  
> -      if (run_executable_sgid (target) == 0)
> -	exit (0);
> +      return run_executable_sgid (target);
>      }
>  
>    /* Something went wrong and our argv was corrupted.  */
>    _exit (1);
>  }
>  
> -#define TEST_FUNCTION_ARGV do_test_prep
> +#define TEST_FUNCTION_ARGV do_test
>  #include <support/test-driver.c>
>
  
Carlos O'Donell Feb. 4, 2017, 1:07 a.m. UTC | #2
On Thu, Feb 2, 2017 at 1:31 PM, Siddhesh Poyarekar
<siddhesh@sourceware.org> wrote:
> The child process of the tst-env-setuid process was failing correctly
> with EXIT_UNSUPPORTED but the parent did not carry that status forward
> and failed instead.  This patch fixes this so that tests on nosuid
> /tmp fails gracefully with UNSUPPORTED.  Tested by making my tmpfs
> nosuid.
>
>         * elf/tst-env-setuid.c (do_execve): Return EXIT_UNSUPPORTED in
>         parent if child exited in that manner.  Print WEXITSTATUS
>         instead of the raw status.
>         (do_test_prep): Rename to do_test.
>         (do_test): Return the result of run_executable_sgid.
>         (TEST_FUNCTION_ARGV): Adjust.

This works as expected.

Both tests are now UNSUPPORTED on my system where /tmp is mounted as nosuid.

For this test to pass I need to use a TMPDIR which is not nosuid.

Cheers,
Carlos.
  

Patch

diff --git a/elf/tst-env-setuid.c b/elf/tst-env-setuid.c
index 85d423d..6ec3fa5 100644
--- a/elf/tst-env-setuid.c
+++ b/elf/tst-env-setuid.c
@@ -87,10 +87,13 @@  do_execve (char **args)
       return 1;
     }
 
+  if (WEXITSTATUS (status) == EXIT_UNSUPPORTED)
+    return EXIT_UNSUPPORTED;
+
   if (!WIFEXITED (status) || WEXITSTATUS (status) != CHILD_STATUS)
     {
       printf ("Unexpected exit status %d from child process\n",
-	      status);
+	      WEXITSTATUS (status));
       return 1;
     }
   return 0;
@@ -235,7 +238,7 @@  test_parent (void)
 #endif
 
 static int
-do_test_prep (int argc, char **argv)
+do_test (int argc, char **argv)
 {
   /* Setgid child process.  */
   if (argc == 2 && strcmp (argv[1], SETGID_CHILD) == 0)
@@ -270,13 +273,12 @@  do_test_prep (int argc, char **argv)
 	  exit (0);
 	}
 
-      if (run_executable_sgid (target) == 0)
-	exit (0);
+      return run_executable_sgid (target);
     }
 
   /* Something went wrong and our argv was corrupted.  */
   _exit (1);
 }
 
-#define TEST_FUNCTION_ARGV do_test_prep
+#define TEST_FUNCTION_ARGV do_test
 #include <support/test-driver.c>