diff mbox

[3/4] stdlib/tst-setcontext.c: Check for clobbering of signal stack

Message ID 1394707543-9690-3-git-send-email-will.newton@linaro.org
State Superseded
Headers show

Commit Message

Will Newton March 13, 2014, 10:45 a.m. UTC
On aarch64 calling swapcontext clobbers the state of the signal
stack (BZ #16629). Check that the address and size of the signal
stack before and after the call to swapcontext remains the same.

ChangeLog:

2014-03-13  Will Newton  <will.newton@linaro.org>

	* stdlib/tst-setcontext.c: Include signal.h.
	(main): Check that the signal stack before and
	after swapcontext is the same (BZ #16629).
---
 stdlib/tst-setcontext.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Carlos O'Donell March 30, 2014, 9:21 p.m. UTC | #1
On 03/13/2014 06:45 AM, Will Newton wrote:
> On aarch64 calling swapcontext clobbers the state of the signal
> stack (BZ #16629). Check that the address and size of the signal
> stack before and after the call to swapcontext remains the same.
> 
> ChangeLog:

OK to checkin with minor nits fixed.

> 2014-03-13  Will Newton  <will.newton@linaro.org>

	[BZ #16629]
> 
> 	* stdlib/tst-setcontext.c: Include signal.h.
> 	(main): Check that the signal stack before and
> 	after swapcontext is the same (BZ #16629).

Remove (BZ #16629), and use the standard markup as I
indicated. This doesn't mean the issue is fixed by this
checkin, just that it's related to BZ #16629. Don't add
16629 to NEWS until it's fixed.

> ---
>  stdlib/tst-setcontext.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/stdlib/tst-setcontext.c b/stdlib/tst-setcontext.c
> index ac9deb1..55984a4 100644
> --- a/stdlib/tst-setcontext.c
> +++ b/stdlib/tst-setcontext.c
> @@ -16,6 +16,7 @@
>     <http://www.gnu.org/licenses/>.  */
>  
>  #include <errno.h>
> +#include <signal.h>

OK.

>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> @@ -144,6 +145,9 @@ main (void)
>    atexit (check_called);
>  
>    char st1[32768];
> +  stack_t stack_before, stack_after;
> +
> +  sigaltstack(NULL, &stack_before);

OK, get the previous stack.

>    puts ("making contexts");
>    if (getcontext (&ctx[1]) != 0)
> @@ -207,6 +211,8 @@ main (void)
>    puts ("back at main program");
>    back_in_main = 1;
>  
> +  sigaltstack(NULL, &stack_after);
> +

OK, get it again afterwards.

>    if (was_in_f1 == 0)
>      {
>        puts ("didn't reach f1");
> @@ -218,6 +224,21 @@ main (void)
>        exit (1);
>      }
>  
> +  /* Check sigaltstack state is not clobbered as in BZ #16629.  */
> +  if (stack_before.ss_sp != stack_after.ss_sp)
> +    {
> +      printf ("stack ss_sp mismatch: %p %p\n",
> +	      stack_before.ss_sp, stack_after.ss_sp);
> +      exit (1);
> +    }
> +
> +  if (stack_before.ss_size != stack_after.ss_size)
> +    {
> +      printf ("stack ss_size mismatch: %zd %zd\n",
> +	      stack_before.ss_size, stack_after.ss_size);
> +      exit (1);
> +    }

OK. Compare and make sure they didn't change.

> +
>    puts ("test succeeded");
>    return 0;
>  }
> 

Cheers,
Carlos.
diff mbox

Patch

diff --git a/stdlib/tst-setcontext.c b/stdlib/tst-setcontext.c
index ac9deb1..55984a4 100644
--- a/stdlib/tst-setcontext.c
+++ b/stdlib/tst-setcontext.c
@@ -16,6 +16,7 @@ 
    <http://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -144,6 +145,9 @@  main (void)
   atexit (check_called);
 
   char st1[32768];
+  stack_t stack_before, stack_after;
+
+  sigaltstack(NULL, &stack_before);
 
   puts ("making contexts");
   if (getcontext (&ctx[1]) != 0)
@@ -207,6 +211,8 @@  main (void)
   puts ("back at main program");
   back_in_main = 1;
 
+  sigaltstack(NULL, &stack_after);
+
   if (was_in_f1 == 0)
     {
       puts ("didn't reach f1");
@@ -218,6 +224,21 @@  main (void)
       exit (1);
     }
 
+  /* Check sigaltstack state is not clobbered as in BZ #16629.  */
+  if (stack_before.ss_sp != stack_after.ss_sp)
+    {
+      printf ("stack ss_sp mismatch: %p %p\n",
+	      stack_before.ss_sp, stack_after.ss_sp);
+      exit (1);
+    }
+
+  if (stack_before.ss_size != stack_after.ss_size)
+    {
+      printf ("stack ss_size mismatch: %zd %zd\n",
+	      stack_before.ss_size, stack_after.ss_size);
+      exit (1);
+    }
+
   puts ("test succeeded");
   return 0;
 }