From: Davide Libenzi <davidel@xmailserver.org>
To: Steve G <linux_4ever@yahoo.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: 2.6.x signal handler bug
Date: Sat, 26 Jun 2004 09:05:34 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.58.0406260839460.10038@bigblue.dev.mdolabs.com> (raw)
In-Reply-To: <20040626143326.50865.qmail@web50607.mail.yahoo.com>
On Sat, 26 Jun 2004, Steve G wrote:
> Hi,
>
> I looked at the test program and do not see anything wrong with the code.
> Contrary to what's already been said in this thread, sigsetjmp/siglongjmp only
> differ in that they restore the signal context. This should never cause a
> segfault.
>
> Regarding re-entrancy, longjmp is stated as one of only 2 ways to exit signal
> handlers. Also, while the printf is not signal safe, it is not your problem
> either. BTW, this mechanism is used by some servers to prevent crashes even in
> the face of big problems. xinetd for one does this...so its important to have
> working.
>
> I ran the test program on my machine under 2.4 and all works as expected. Under
> 2.6, it definitely segfaults. I tried using Electric Fence and valgrind to trap
> the error. Neither one could.
>
> In summary, the program is valid and real world servers do this kind of thing. It
> does segfault under 2.6.
You're receiving a SIGSEGV while SIGSEGV is blocked (force_sig_info). The
force_sig_info call wants to send a signal that the task can't refuse
(kinda The GodFather offers ;). The kernel will noticed this and will
restore the handler to SIG_DFL. All three examples below works fine on 2.6.
- Davide
--------------------------------------------------------------------
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
volatile int len;
volatile int real;
volatile int caught;
jmp_buf env;
void catcher(int sig){
signal(SIGSEGV, catcher);
printf("requested: %9d malloced: %9d\n",len,real);
longjmp(env, 1);
}
int main(){
char* p=0;
sigset_t m;
len = 0;
sigemptyset(&m);
sigaddset(&m, SIGSEGV);
signal(SIGSEGV, catcher);
setjmp(env);
sigprocmask(SIG_UNBLOCK, &m, NULL);
printf("len %d\n", len);
len++;
free(p);
p = malloc(len);
real = 0;
while(1){
p[real] = 0;
real++;
}
return 0;
}
--------------------------------------------------------------------
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
volatile int len;
volatile int real;
volatile int caught;
jmp_buf env;
void catcher(int sig){
signal(SIGSEGV, catcher);
printf("requested: %9d malloced: %9d\n",len,real);
siglongjmp(env, 1);
}
int main(){
char* p=0;
len = 0;
signal(SIGSEGV, catcher);
sigsetjmp(env, 1);
printf("len %d\n", len);
len++;
free(p);
p = malloc(len);
real = 0;
while(1){
p[real] = 0;
real++;
}
return 0;
}
--------------------------------------------------------------------
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
volatile int len;
volatile int real;
volatile int caught;
jmp_buf env;
void catcher(int sig){
printf("requested: %9d malloced: %9d\n",len,real);
longjmp(env, 1);
}
int main(){
char* p=0;
struct sigaction act;
len = 0;
act.sa_handler = catcher;
act.sa_flags = SA_NODEFER;
sigaction(SIGSEGV, &act, NULL);
setjmp(env);
printf("len %d\n", len);
len++;
free(p);
p = malloc(len);
real = 0;
while(1){
p[real] = 0;
real++;
}
return 0;
}
next prev parent reply other threads:[~2004-06-26 16:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-26 14:33 Steve G
2004-06-26 16:05 ` Davide Libenzi [this message]
2004-06-27 22:16 ` Andries Brouwer
2004-06-27 22:45 ` Davide Libenzi
2004-06-27 22:51 ` Davide Libenzi
2004-06-28 2:01 ` Steve G
2004-06-28 11:26 ` Steve G
2004-06-28 14:56 ` Davide Libenzi
-- strict thread matches above, loose matches on Subject: below --
2004-06-25 23:56 Paul Maurides
2004-06-26 0:07 ` Andrew Morton
2004-06-26 1:33 ` David Wagner
2004-06-28 21:56 ` Jörn Engel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.58.0406260839460.10038@bigblue.dev.mdolabs.com \
--to=davidel@xmailserver.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux_4ever@yahoo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®