- To: libc-gnats at gnu dot org, gnats-admin at gnu dot org
- Subject: libc/2512: linxuthreads does not allow signal handlers to run onalternate stack
- From: hassanj at cs dot utexas dot edu
- Date: Mon, 03 Sep 2001 11:46:48 -0400
>Number: 2512
>Category: libc
>Synopsis: linxuthreads does not allow signal handlers to run on alternate stack
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: libc-gnats
>State: open
>Quarter:
>Keywords:
>Class: sw-bug
>Submitter-Id: gnatsweb
>Arrival-Date: Mon Sep 03 11:46:47 -0400 2001
>Cases:
>Originator: hassanj@cs.utexas.edu
>Release: linuxthreads 0.9 (accompanied by glibc-2.2.4)
>Organization:
University of Texas at Austin
>Environment:
Intel Pentium processor
Linux Kernel 2.2.19
glibc 2.2.4
linuxthreads 0.9
gcc 2.95
>Description:
A program that has been linked with linuxthreads produces a core dump when it receives any signal whose signal handler runs on an alternate stack.
>How-To-Repeat:
Compile as gcc -D_REENTRANT thread.cc -lpthread
Run as ./a.out
OUTPUT segmentation fault
If the program is not linked with the thread library (-lpthread is not used), no segmentation fault will occur.
Also, if you remove the ON_STACK flag (Line 52), so that the signal handler does not run on the alternate stack, no seg fault will occur.
>Fix:
unknown
>Unformatted:
- To: Andreas Jaeger <aj at suse dot de>
- Subject: Re: libc/2512: linxuthreads does not allow signal handlers to runon alternate stack
- From: "Hassan M. Jafri" <hassanj at cs dot utexas dot edu>
- Date: Tue, 4 Sep 2001 08:38:08 -0500 (CDT)
- Cc: <bugs at gnu dot org>
The attached file (thread.cc) has the source code that demonstrates the
problem.
Thanks,
Hassan
On Tue, 4 Sep 2001, Andreas Jaeger wrote:
> hassanj@cs.utexas.edu writes:
>
> > >Description:
> > A program that has been linked with linuxthreads produces a core dump when it receives any signal whose signal handler runs on an alternate stack.
> > >How-To-Repeat:
> > Compile as gcc -D_REENTRANT thread.cc -lpthread
> > Run as ./a.out
> > OUTPUT segmentation fault
>
> The program is not appended, can you resend it, please?
>
> Thanks,
> Andreas
> --
> Andreas Jaeger
> SuSE Labs aj@suse.de
> private aj@arthur.inka.de
> http://www.suse.de/~aj
>
#if (defined(_REENTRANT) || _POSIX_C_SOURCE >= 199506L)
extern int *___errno();
#define errno (*(___errno()))
#else
extern int errno;
#endif /* defined(_REENTRANT) || _POSIX_C_SOURCE >= 199506L) */
#include <pthread.h>
#include <stdio.h>
#include <signal.h>
#include <sys/mman.h>
#include <fcntl.h>
// A temporary stack
const int _tempStackSize = SIGSTKSZ;
static char* _tempStack;
void SIGHUPHandler(int sig)
{
if (sig == SIGHUP) {
printf("SIGHUP received\n");
signal(SIGHUP, SIGHUPHandler);
}
}
int main(void)
{
stack_t signalStack;
struct sigaction act;
sigset_t blockedSet;
int devZeroFd = open("/dev/zero", O_RDONLY);
_tempStack = (char *) mmap(0, SIGSTKSZ, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, devZeroFd, 0);
sigemptyset(&blockedSet);
sigprocmask(SIG_SETMASK, &blockedSet, NULL);
// pthread_sigmask(SIG_SETMASK, &blockedSet, NULL);
// This is the temporary stack
signalStack.ss_flags = 0;
signalStack.ss_size = _tempStackSize;
signalStack.ss_sp = _tempStack;
// install the stack.
if (sigaltstack(&signalStack, (stack_t *) NULL) < 0) {
printf("error installing signal stack");
exit(0);
}
act.sa_handler = SIGHUPHandler;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_ONSTACK | SA_RESTART | SA_NODEFER | SA_RESETHAND;
sigaction(SIGHUP, &act, NULL);
pthread_kill(pthread_self(), SIGHUP);
return 0;
}