Crash or hang if SIGSEGV+SIGALRM are nested

Christian Franke Christian.Franke@t-online.de
Mon May 19 10:55:46 GMT 2025


The attached testcase was originally intended to investigate why a 
SIGSEGV from non-signal code could interrupt an already running signal 
handler.
https://sourceware.org/pipermail/cygwin-patches/2025q2/013703.html
If run without strace, the testcase may crash silently (with exit status 0):
$ uname -r
3.7.0-0.98.gb39b510c1ce6.x86_64
$ gcc -o sigsegvalrm sigsegvalrm.c
$ while { ./sigsegvalrm; s=$?; echo exit $s; test $s = 42; }; do :; done
...
[SEGV during ALRM]
[SEGV]
[ALRM during SEGV]
[ALRM]
101 total, 24 ALRM during SEGV, 13 SEGV during ALRM
exit 42
...
[SEGV during ALRM]
[ALRM]
[SEGV]
[ALRM]
[SEGV]
[ALRM during SEGV]
[SEGV]
[ALRM]
[SEGV]
exit 0
If the above was run with 'strace ./sigsegvalrm', the result was an 
infinte loop:
https://cygwin.com/pipermail/cygwin/2025-May/258144.html
Fortunately this is fixed since b39b510c. A new result:
...
[SEGV during ALRM]
   205  556472 [main] sigsegvalrm 1342 fhandler_console::write: 19 = 
fhandler_console::write(...)
    91  556563 [main] sigsegvalrm 1342 write: 19 = write(1, 0x100403020, 19)
    81  556644 [main] sigsegvalrm 1342 clock_nanosleep: clock_nanosleep 
(0.001000000)
  8396  565040 [itimer] sigsegvalrm 1342 timer_tracker::thread_func: 
0x7FFE4CC69640 timer expired
   230  565270 [main] sigsegvalrm 1342 clock_nanosleep: 0 = 
clock_nanosleep(1, 0, 0.001000000, 0.d)
   123  565393 [itimer] sigsegvalrm 1342 timer_tracker::thread_func: 
0x7FFE4CC69640 sending signal 14
   230  565623 [main] sigsegvalrm 1342 set_signal_mask: setmask 2400, 
newmask 0, mask_bits 2400
   147  565770 [main] sigsegvalrm 1342 pthread_sigmask: 0 = 
pthread_sigmask(0, 0x100407128, 0x0)
   220  565990 [itimer] sigsegvalrm 1342 sig_send: sendsig 0x158, pid 
1342, signal 14, its_me 1
   278  566268 [main] sigsegvalrm 1342 pthread_sigmask: 0 = 
pthread_sigmask(0, 0x0, 0x100407128)
--- Process 148 (pid: 1342), exception c0000005 at 0000000100401287
  1579  567847 [sig] sigsegvalrm 1342 sigpacket::process: signal 14 
processing
   189  568036 [sig] sigsegvalrm 1342 init_cygheap::find_tls: sig 14
   235  568271 [sig] sigsegvalrm 1342 sigpacket::process: using tls 
0x7FFFFCE00
   195  568466 [main] sigsegvalrm 1342 exception::handle: In 
cygwin_except_handler exception 0xC0000005 at 0x100401287 sp 0x7FFFFCBE0
   131  568597 [sig] sigsegvalrm 1342 sigpacket::process: signal 14, 
signal handler 0x100401080
    82  568679 [main] sigsegvalrm 1342 exception::handle: In 
cygwin_except_handler signal 11 at 0x100401287
    79  568758 [sig] sigsegvalrm 1342 sigpacket::setup_handler: 
suspending thread, tls 0x7FFFFCE00, _main_tls 0x7FFFFCE00
[~30s delay]
--- Process 148 (pid: 1342) thread 14964 created
--- Process 148 (pid: 1342) thread 14048 created
[~30s delay]
--- Process 148 (pid: 1342) thread 5184 exited with status 0x0
--- Process 148 (pid: 1342) thread 5056 exited with status 0x0
[several minutes delay]
--- Process 148 (pid: 1342) thread 9388 created
The process then ignores SIGKILL.
BTW, this testcase without a second signal now works as expected:
https://sourceware.org/pipermail/cygwin/2025-March/257726.html
-- 
Regards,
Christian
-------------- next part --------------
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
static volatile sig_atomic_t total, nest1, nest2;
static volatile sig_atomic_t insig1, insig2;
static sigjmp_buf sjb;
static const int delay = 1000;
static void sighandler1(int sig)
{
 (void)sig;
 insig1 = 1;
 total++;
 if (insig2) {
 write(1, "[ALRM during SEGV]\n", 19);
 nest1++;
 }
 else
 write(1, "[ALRM]\n", 7);
 insig1 = 0;
}
static void sighandler2(int sig)
{
 (void)sig;
 insig2 = 1;
 total++;
 if (insig1) {
 insig1 = 0;
 write(1, "[SEGV during ALRM]\n", 19);
 nest2++;
 }
 else
 write(1, "[SEGV]\n", 7);
 usleep(delay);
 insig2 = 0;
 siglongjmp(sjb, 1);
 write(1, "[FAIL]\n", 7);
}
int main()
{
 signal(SIGALRM, sighandler1);
 signal(SIGSEGV, sighandler2);
 ualarm(delay, delay);
 while (sigsetjmp(sjb, 1))
 ;
 // loop:
 if (total < 100)
 *(volatile char *)0 = 0; // goto loop;
 ualarm(0, 0);
 printf("%d total, %d ALRM during SEGV, %d SEGV during ALRM\n",
 total, nest1, nest2);
 return 42;
}


More information about the Cygwin mailing list

AltStyle によって変換されたページ (->オリジナル) /