NetBSD Problem Report #41076
From www@NetBSD.org Wed Mar 25 23:04:53 2009
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by www.NetBSD.org (Postfix) with ESMTP id B69D063BAFE
for <gnats-bugs@gnats.netbsd.org>; Wed, 25 Mar 2009 23:04:53 +0000 (UTC)
Message-Id: <20090325230453.5707663B8BA@www.NetBSD.org>
Date: Wed, 25 Mar 2009 23:04:53 +0000 (UTC)
From: matteo@beccati.com
Reply-To: matteo@beccati.com
To: gnats-bugs@NetBSD.org
Subject: sigwaitinfo and sigtimedwait don't properly set siginfo
X-Send-Pr-Version: www-1.0
>Number: 41076
>Category: kern
>Synopsis: sigwaitinfo and sigtimedwait don't properly set siginfo
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: kern-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Mar 25 23:05:00 +0000 2009
>Closed-Date: Wed Apr 01 17:03:51 +0000 2009
>Last-Modified: Fri Apr 10 20:25:01 +0000 2009
>Originator: Matteo Beccati
>Release: 4.0 (XEN DOM0)
>Organization:
>Environment:
NetBSD epia.hq.beccati.com 4.0 NetBSD 4.0 (EPIA) #2: Sun Aug 10 00:15:28 CEST 2008 root@epia.hq.beccati.com:/mnt/usb/src/sys/arch/i386/compile/obj/EPIA i386
>Description:
As far as I could see, sigtimedwait and sigwaitinfo only set si_signo and si_code. According to the manual, si_pid and si_uid should be set when si_code == SI_USER (== 0), and si_sigval should be set when si_code == SI_TIMER (== -2). That doesn't seem to happen.
>How-To-Repeat:
user@epia:~$ cat sigwaitinfo.c
#include <stdio.h>
#include <signal.h>
int main(int argc, char **argv)
{
pid_t pid = getpid();
sigset_t mask;
siginfo_t info;
printf("Pid: %d\n", pid);
sigemptyset(&mask);
sigaddset(&mask, SIGTERM);
sigprocmask(SIG_BLOCK, &mask, NULL);
kill(pid, SIGTERM);
sigwaitinfo(&mask, &info);
printf("Signal: %d, Code: %d, Pid: %d, Uid %d\n", info.si_signo, info.si_code, info.si_pid, info.si_uid);
sigaddset(&mask, SIGALRM);
sigprocmask(SIG_BLOCK, &mask, NULL);
alarm(2);
sigwaitinfo(&mask, &info);
printf("Signal: %d, Code: %d, Sigval: %d\n", info.si_signo, info.si_code, info.si_sigval);
return 0;
}
user@epia:~$ gcc sigwaitinfo.c
user@epia:~$ ./a.out
Pid: 19765
Signal: 15, Code: 0, Pid: 0, Uid 0
Signal: 14, Code: -2, Sigval: 0
>Fix:
>Release-Note:
>Audit-Trail:
From: Matthias Drochner <M.Drochner@fz-juelich.de>
To: gnats-bugs@NetBSD.org
Cc: kern-bug-people@NetBSD.org, gnats-admin@NetBSD.org,
netbsd-bugs@NetBSD.org
Subject: Re: kern/41076: sigwaitinfo and sigtimedwait don't properly set
siginfo
Date: Thu, 26 Mar 2009 17:13:06 +0100
This is a multipart MIME message.
--==_Exmh_21140580013800
Content-Type: text/plain; charset=us-ascii
matteo@beccati.com said:
> si_pid and si_uid should be set when si_code == SI_USER (== 0)
There is a bug in the kernel - the appended patch fixes it
for -current. I'm assuming that the code looks similar
in 4.0 - can you give it a try?
> si_sigval should be set when si_code == SI_TIMER (== -2)
It says it is set to the value of timer_create. You didn't
use timer_create... If you modify your test program to do:
timer_t tid;
struct itimerspec to;
timer_create(CLOCK_REALTIME, 0, &tid);
printf("timer=%d\n", tid);
memset(&to, 0, sizeof to);
to.it_value.tv_sec = 2;
timer_settime(tid, TIMER_RELTIME, &to, 0);
you'll see that it works. At least it does in -current.
best regards
Matthias
-------------------------------------------------------------------
-------------------------------------------------------------------
Forschungszentrum Juelich GmbH
52425 Juelich
Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzende des Aufsichtsrats: MinDir'in Baerbel Brumme-Bothe
Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
Dr. Ulrich Krafft (stellv. Vorsitzender), Prof. Dr. Harald Bolt,
Dr. Sebastian M. Schmidt
-------------------------------------------------------------------
-------------------------------------------------------------------
--==_Exmh_21140580013800
Content-Type: text/plain ; name="sig.txt"; charset=us-ascii
Content-Description: sig.txt
Content-Disposition: attachment; filename="sig.txt"
#
# old_revision [41ea70456886a52c1c72a5950be895a5bb5994a9]
#
# patch "sys/kern/kern_sig.c"
# from [58c4b0b2d0b7f723528f92694e187ef246b1d96b]
# to [f74ec2cbcddb2e978482f54a8b9b64652de4345d]
#
============================================================
--- sys/kern/kern_sig.c 58c4b0b2d0b7f723528f92694e187ef246b1d96b
+++ sys/kern/kern_sig.c f74ec2cbcddb2e978482f54a8b9b64652de4345d
@@ -549,14 +549,12 @@ out:
/*
* sigput:
*
- * Append a new ksiginfo element to the list of pending ksiginfo's, if
- * we need to (e.g. SA_SIGINFO was requested).
+ * Append a new ksiginfo element to the list of pending ksiginfo's.
*/
void
sigput(sigpend_t *sp, struct proc *p, ksiginfo_t *ksi)
{
ksiginfo_t *kp;
- struct sigaction *sa = &SIGACTION_PS(p->p_sigacts, ksi->ksi_signo);
KASSERT(mutex_owned(p->p_lock));
KASSERT((ksi->ksi_flags & KSI_QUEUED) == 0);
@@ -564,11 +562,9 @@ sigput(sigpend_t *sp, struct proc *p, ks
sigaddset(&sp->sp_set, ksi->ksi_signo);
/*
- * If there is no siginfo, or is not required (and we don't add
- * it for the benefit of ktrace, we are done).
+ * If there is no siginfo, we are done.
*/
- if (KSI_EMPTY_P(ksi) ||
- (!KTRPOINT(p, KTR_PSIG) && (sa->sa_flags & SA_SIGINFO) == 0))
+ if (KSI_EMPTY_P(ksi))
return;
KASSERT((ksi->ksi_flags & KSI_FROMPOOL) != 0);
--==_Exmh_21140580013800--
From: Matteo Beccati <matteo@beccati.com>
To: gnats-bugs@NetBSD.org
Cc: Matthias Drochner <M.Drochner@fz-juelich.de>
Subject: Re: kern/41076: sigwaitinfo and sigtimedwait don't properly set
siginfo
Date: Thu, 26 Mar 2009 18:38:46 +0100
This is a multi-part message in MIME format.
--------------060008080904090108060605
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Hi,
> From: Matthias Drochner <M.Drochner@fz-juelich.de>
> To: gnats-bugs@NetBSD.org
> Cc: kern-bug-people@NetBSD.org, gnats-admin@NetBSD.org,
> netbsd-bugs@NetBSD.org
> Subject: Re: kern/41076: sigwaitinfo and sigtimedwait don't properly set
> siginfo
> Date: Thu, 26 Mar 2009 17:13:06 +0100
>
> This is a multipart MIME message.
>
> --==_Exmh_21140580013800
> Content-Type: text/plain; charset=us-ascii
>
>
> matteo@beccati.com said:
> > si_pid and si_uid should be set when si_code == SI_USER (== 0)
>
> There is a bug in the kernel - the appended patch fixes it
> for -current. I'm assuming that the code looks similar
> in 4.0 - can you give it a try?
The patch doesn't cleanly apply as the code is a bit different (the
check for (sa->sa_flags & SA_SIGINFO) == 0) is a few lines above and has
its how if/return.
The fix is working, I'm attaching a diff for the netbsd-4 branch in case
you want to apply it.
> > si_sigval should be set when si_code == SI_TIMER (== -2)
>
> It says it is set to the value of timer_create. You didn't
> use timer_create... If you modify your test program to do:
Right. The test code is working fine.
Cheers
--
Matteo Beccati
OpenX - http://www.openx.org
--------------060008080904090108060605
Content-Type: text/plain;
name="kern_sig_netbsd_4.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="kern_sig_netbsd_4.diff"
diff -u -r1.240.2.2 kern_sig.c
--- sys/kern/kern_sig.c 7 Oct 2007 14:21:11 -0000 1.240.2.2
+++ sys/kern/kern_sig.c 26 Mar 2009 17:12:51 -0000
@@ -180,21 +180,17 @@
}
/*
- * Append a new ksiginfo element to the list of pending ksiginfo's, if
- * we need to (SA_SIGINFO was requested). We replace non RT signals if
- * they already existed in the queue and we add new entries for RT signals,
- * or for non RT signals with non-existing entries.
+ * Append a new ksiginfo element to the list of pending ksiginfo's.
+ * We replace non RT signals if they already existed in the queue
+ * and we add new entries for RT signals, or for non RT signals
+ * with non-existing entries.
*/
static void
ksiginfo_queue(struct proc *p, const ksiginfo_t *ksi, ksiginfo_t **newkp)
{
ksiginfo_t *kp;
- struct sigaction *sa = &SIGACTION_PS(p->p_sigacts, ksi->ksi_signo);
int s;
- if ((sa->sa_flags & SA_SIGINFO) == 0)
- return;
-
/*
* If there's no info, don't save it.
*/
--------------060008080904090108060605--
From: Matthias Drochner <drochner@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/41076 CVS commit: src/sys/kern
Date: Fri, 27 Mar 2009 10:58:38 +0000
Module Name: src
Committed By: drochner
Date: Fri Mar 27 10:58:38 UTC 2009
Modified Files:
src/sys/kern: kern_sig.c
Log Message:
In sigput(), save the siginfo no matter whether SA_SIGINFO is set or not.
There are also sigtimedwait(2) et al. to catch signals without invoking
a signal handler. Fixes PR kern/41076 by Matteo Beccati (the first
test case, where the signal is sent before sigwaitinfo(2) gets called).
To generate a diff of this commit:
cvs rdiff -u -r1.295 -r1.296 src/sys/kern/kern_sig.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: Matthias Drochner <M.Drochner@fz-juelich.de>
To: Matteo Beccati <matteo@beccati.com>
Cc: gnats-bugs@NetBSD.org
Subject: Re: kern/41076: sigwaitinfo and sigtimedwait don't properly set
siginfo
Date: Fri, 27 Mar 2009 12:04:00 +0100
matteo@beccati.com said:
> The fix is working, I'm attaching a diff for the netbsd-4 branch in
> case you want to apply it.
Great - thanks. Could you please exercise the code a bit.
I want to be sure that this doesn't cause a memory leak.
(In theory it can't because siginfo allocation/deallocation
is done in a higher layer than the trampoline code which
interprets the SA_SIGINFO flag.)
best regards
Matthias
-------------------------------------------------------------------
-------------------------------------------------------------------
Forschungszentrum Juelich GmbH
52425 Juelich
Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzende des Aufsichtsrats: MinDir'in Baerbel Brumme-Bothe
Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
Dr. Ulrich Krafft (stellv. Vorsitzender), Prof. Dr. Harald Bolt,
Dr. Sebastian M. Schmidt
-------------------------------------------------------------------
-------------------------------------------------------------------
From: Matteo Beccati <matteo@beccati.com>
To: M.Drochner@fz-juelich.de
Cc: gnats-bugs@NetBSD.org
Subject: Re: kern/41076: sigwaitinfo and sigtimedwait don't properly set
siginfo
Date: Fri, 27 Mar 2009 13:43:18 +0100
Matthias Drochner ha scritto:
> matteo@beccati.com said:
>> The fix is working, I'm attaching a diff for the netbsd-4 branch in
>> case you want to apply it.
>
> Great - thanks. Could you please exercise the code a bit.
> I want to be sure that this doesn't cause a memory leak.
> (In theory it can't because siginfo allocation/deallocation
> is done in a higher layer than the trampoline code which
> interprets the SA_SIGINFO flag.)
I've wrapped a loop around the code and all the memory allocated is
released when execution ends from what I could see in vmstat.
Cheers
--
Matteo Beccati
OpenX - http://www.openx.org
From: Matteo Beccati <matteo@beccati.com>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: kern/41076: sigwaitinfo and sigtimedwait don't properly set
siginfo
Date: Wed, 01 Apr 2009 17:49:13 +0200
The fix is working good.
Can I ask a pullup to netbsd-5?
cvs rdiff -r 1.295 -r 1.296 src/sys/kern/kern_sig.c
I've switched to netbsd-5 now, but I can confirm my modified patch was
woking for netbsd-4. I'm just not sure if it's still open for bug fixes.
Thanks
From: Matthias Drochner <M.Drochner@fz-juelich.de>
To: gnats-bugs@NetBSD.org
Cc: kern-bug-people@NetBSD.org, gnats-admin@NetBSD.org,
netbsd-bugs@NetBSD.org, matteo@beccati.com
Subject: Re: kern/41076: sigwaitinfo and sigtimedwait don't properly set
siginfo
Date: Wed, 01 Apr 2009 18:52:34 +0200
matteo@beccati.com said:
> Can I ask a pullup to netbsd-5?
Oh, almost forgot about that one...
Just submitted a request to releng.
> I can confirm my modified patch was
> woking for netbsd-4. I'm just not sure if it's still open for bug fixes.
netbsd-4 is still the last official release, fixes are still applied.
I've just sent a request for than one too.
best regards
Matthias
-------------------------------------------------------------------
-------------------------------------------------------------------
Forschungszentrum Juelich GmbH
52425 Juelich
Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzende des Aufsichtsrats: MinDir'in Baerbel Brumme-Bothe
Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
Dr. Ulrich Krafft (stellv. Vorsitzender), Prof. Dr. Harald Bolt,
Dr. Sebastian M. Schmidt
-------------------------------------------------------------------
-------------------------------------------------------------------
State-Changed-From-To: open->closed
State-Changed-By: drochner@NetBSD.org
State-Changed-When: Wed, 01 Apr 2009 17:03:51 +0000
State-Changed-Why:
submitter confirmed, pullups requested
From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, kern-bug-people@netbsd.org,
gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, matteo@beccati.com
Cc:
Subject: Re: kern/41076: sigwaitinfo and sigtimedwait don't properly set siginfo
Date: Wed, 1 Apr 2009 13:55:52 -0400
On Apr 1, 3:50pm, matteo@beccati.com (Matteo Beccati) wrote:
-- Subject: Re: kern/41076: sigwaitinfo and sigtimedwait don't properly set s
| The following reply was made to PR kern/41076; it has been noted by GNATS.
|
| From: Matteo Beccati <matteo@beccati.com>
| To: gnats-bugs@NetBSD.org
| Cc:
| Subject: Re: kern/41076: sigwaitinfo and sigtimedwait don't properly set
| siginfo
| Date: Wed, 01 Apr 2009 17:49:13 +0200
|
| The fix is working good.
|
| Can I ask a pullup to netbsd-5?
|
| cvs rdiff -r 1.295 -r 1.296 src/sys/kern/kern_sig.c
|
| I've switched to netbsd-5 now, but I can confirm my modified patch was
| woking for netbsd-4. I'm just not sure if it's still open for bug fixes.
|
| Thanks
I've asked.
christos
From: Soren Jacobsen <snj@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/41076 CVS commit: [netbsd-5] src/sys/kern
Date: Wed, 1 Apr 2009 21:56:51 +0000
Module Name: src
Committed By: snj
Date: Wed Apr 1 21:56:51 UTC 2009
Modified Files:
src/sys/kern [netbsd-5]: kern_sig.c
Log Message:
Pull up following revision(s) (requested by drochner in ticket #640):
sys/kern/kern_sig.c: revision 1.296
In sigput(), save the siginfo no matter whether SA_SIGINFO is set or not.
There are also sigtimedwait(2) et al. to catch signals without invoking
a signal handler. Fixes PR kern/41076 by Matteo Beccati (the first
test case, where the signal is sent before sigwaitinfo(2) gets called).
To generate a diff of this commit:
cvs rdiff -u -r1.289.4.4 -r1.289.4.5 src/sys/kern/kern_sig.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: Soren Jacobsen <snj@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/41076 CVS commit: [netbsd-4] src/sys/kern
Date: Fri, 10 Apr 2009 20:20:45 +0000
Module Name: src
Committed By: snj
Date: Fri Apr 10 20:20:45 UTC 2009
Modified Files:
src/sys/kern [netbsd-4]: kern_sig.c
Log Message:
Pull up following revision(s) (requested by drochner in ticket #1299):
sys/kern/kern_sig.c: revision 1.296 via patch
In sigput(), save the siginfo no matter whether SA_SIGINFO is set or not.
There are also sigtimedwait(2) et al. to catch signals without invoking
a signal handler. Fixes PR kern/41076 by Matteo Beccati (the first
test case, where the signal is sent before sigwaitinfo(2) gets called).
To generate a diff of this commit:
cvs rdiff -u -r1.240.2.2 -r1.240.2.3 src/sys/kern/kern_sig.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.