1 /* Verify longjmp fortify checking does not reject signal stacks.
3 Test case mostly written by Paolo Bonzini <pbonzini@redhat.com>. */
11 #include <sys/resource.h>
14 static jmp_buf mainloop
;
15 static sigset_t mainsigset
;
20 stackoverflow_handler (int sig
)
23 /* Sanity check to keep test from looping forever (in case the longjmp
24 chk code is slightly broken). */
27 sigaltstack (NULL
, &altstack
);
28 /* Using printf is not really kosher in signal handlers but we know
30 printf ("%*sin signal handler\n", pass
, "");
31 if (altstack
.ss_flags
& SS_ONSTACK
)
32 printf ("%*son alternate stack\n", pass
, "");
33 siglongjmp (mainloop
, pass
);
38 recurse_1 (int n
, volatile int *p
)
41 *recurse_1 (n
+ 1, p
) += n
;
50 return *recurse_1 (n
, &sum
);
57 char mystack
[SIGSTKSZ
];
59 struct sigaction action
;
61 /* Before starting the endless recursion, try to be friendly to the user's
62 machine. On some Linux 2.2.x systems, there is no stack limit for user
63 processes at all. We don't want to kill such systems. */
65 rl
.rlim_cur
= rl
.rlim_max
= 0x100000; /* 1 MB */
66 setrlimit (RLIMIT_STACK
, &rl
);
67 /* Install the alternate stack. */
68 altstack
.ss_sp
= mystack
;
69 altstack
.ss_size
= sizeof (mystack
);
70 altstack
.ss_flags
= 0; /* no SS_DISABLE */
71 if (sigaltstack (&altstack
, NULL
) < 0)
73 puts ("first sigaltstack failed");
76 /* Install the SIGSEGV handler. */
77 sigemptyset (&action
.sa_mask
);
78 action
.sa_handler
= &stackoverflow_handler
;
79 action
.sa_flags
= SA_ONSTACK
;
80 sigaction (SIGSEGV
, &action
, (struct sigaction
*) NULL
);
81 sigaction (SIGBUS
, &action
, (struct sigaction
*) NULL
);
83 /* Save the current signal mask. */
84 sigemptyset (&emptyset
);
85 sigprocmask (SIG_BLOCK
, &emptyset
, &mainsigset
);
87 /* Provoke two stack overflows in a row. */
88 if (sigsetjmp (mainloop
, 1) != 0)
91 printf ("%*sout of signal handler\n", pass
, "");
96 sigaltstack (NULL
, &altstack
);
97 if (altstack
.ss_flags
& SS_ONSTACK
)
98 printf ("%*son alternate stack\n", pass
, "");
100 printf ("%*snot on alternate stack\n", pass
, "");
105 puts ("recurse call returned");
109 altstack
.ss_flags
|= SS_DISABLE
;
110 if (sigaltstack (&altstack
, NULL
) == -1)
111 printf ("disabling alternate stack failed\n");
113 printf ("disabling alternate stack succeeded \n");
118 #define TEST_FUNCTION do_test ()
119 #include "../test-skeleton.c"