From nobody@FreeBSD.org  Thu Dec 24 16:15:53 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id A2B4E1065694
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 24 Dec 2009 16:15:53 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 9272B8FC13
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 24 Dec 2009 16:15:53 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id nBOGFqZD085257
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 24 Dec 2009 16:15:52 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id nBOGFqgx085256;
	Thu, 24 Dec 2009 16:15:52 GMT
	(envelope-from nobody)
Message-Id: <200912241615.nBOGFqgx085256@www.freebsd.org>
Date: Thu, 24 Dec 2009 16:15:52 GMT
From: BERTRAND Jol <joel.bertrand@systella.fr>
To: freebsd-gnats-submit@FreeBSD.org
Subject: siginfo->si_pid null in signal handler
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         141956
>Category:       kern
>Synopsis:       [libc] signal(3): siginfo->si_pid null in signal handler [regression]
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 24 16:20:02 UTC 2009
>Closed-Date:    Sat Apr 10 22:29:39 UTC 2010
>Last-Modified:  Sat Apr 10 22:29:39 UTC 2010
>Originator:     BERTRAND Jol
>Release:        8.0-STABLE
>Organization:
>Environment:
FreeBSD gauss.systella.fr 8.0-STABLE FreeBSD 8.0-STABLE #1: Mon Dec  7 15:46:01 CET 2009     root@gauss.systella.fr:/usr/obj/usr/src/sys/CUSTOM  i386

>Description:
RPL/2 (http://www.rpl2.net) enters in deadlock when I try to quit
application with ABORT intrinsic. I have written some test code and I
find that the following code

void
interruption5(int signal, siginfo_t *siginfo, void *context)
{
    pthread_t               thread;
    struct_processus        *s_etat_processus;

    verrouillage_gestionnaire_signaux();

    uprintf("<1> %d %d\n", (*siginfo).si_pid, getpid());
    // uprintf is a macro defined by fprintf(stderr, ...)
    exit(0);
    ...
} // from src/interruptions.c

prints :

gauss:[~/rpl/build/src] > ./rpl -is
+++RPL/2 (R) version 4.0.8 (Thursday 12/24/09, 16:54:22 CET)
+++Copyright (C) 1989  2008, 2009 BERTRAND Jol

+++Ce logiciel est un logiciel libre sans aucune garantie de fonctionnement.
+++Pour plus de dtails, utilisez la commande 'warranty'.

RPL/2> abort
<1> 0 32877
gauss:[~/rpl/build/src] > 

In this case, I have to see :
<1> 32877 32877
because calling process is in my case 32877 and cannot be null. RPL/2
uses this value to send a signal to a specified thread. As this value
is always null, signal cannot be processed.

Of course, signal handler specification is :

        action.sa_sigaction = interruption5;
        action.sa_flags = SA_NODEFER | SA_ONSTACK | SA_SIGINFO;
        // from src/rpl.c

thus siginfo->si_pid has to be filled.
>How-To-Repeat:
Build RPL/2 and try to quit application with ABORT. The same program
worked fine with FreeBSD 7.x (and with NetBSD, Linux, Solaris...).
>Fix:


>Release-Note:
>Audit-Trail:

From: Patrick Lamaiziere <patfbsd@davenulle.org>
To: bug-followup@FreeBSD.org <bug-followup@FreeBSD.org>
Cc: BERTRAND =?ISO-8859-1?Q?Jo=EBl?= <joel.bertrand@systella.fr>
Subject: Re: misc/141956: siginfo->si_pid null in signal handler
Date: Fri, 29 Jan 2010 15:46:50 +0100

 Le Thu, 24 Dec 2009 16:15:52 GMT,
 BERTRAND Jol <joel.bertrand@systella.fr> a crit :
 
 > thus siginfo->si_pid has to be filled.
 
 According to guys from news:fr.comp.os.bsd it has been fixed by kib@ in
 head (SVN rev 199335) and RELENG_8 (MFC svn rev 200729)
 
 Regards.

From: Bruno Ducrot <ducrot@echo.fr>
To: bug-followup@FreeBSD.org, joel.bertrand@systella.fr
Cc:  
Subject: Re: kern/141956: [libc] signal(3): siginfo-&gt;si_pid null in signal
 handler [regression]
Date: Fri, 29 Jan 2010 15:31:34 +0100

 Hi,
 
 With this test :
 #include <stdio.h>
 #include <stdlib.h>
 #include <signal.h>
 #include <unistd.h>
 
 
 void
 handler(int signal, siginfo_t *siginfo, void *context)
 {
          int i;
          char *p = (char *)siginfo;
 
          printf("si_pid: %d (%d)\n", siginfo->si_pid, getpid());
          printf("si_uid: %d\n", siginfo->si_uid);
 
          _exit(1);
 }
 
 int
 main(void)
 {
          struct sigaction sa;
 
          sa.sa_sigaction = handler;
          sa.sa_flags = SA_SIGINFO;
          sigemptyset(&sa.sa_mask);
 
          sigaction(SIGABRT, &sa, NULL);
          abort();
          return 0;
 }
 
 I can indeed reproduce the same behaviour with RELENG_8_0 at least.
 
 But it seems this has been fixed by kid@ under CURRENT (SVN rev 199355).
 
 There is a MFC (SVN rev 200729), and therefore I can't reproduce anymore
 this misbehaviour with RELENG_8 as of yesterday.
 
 Could you please confirm your software (RPL/2) work now as expected with
 latest RELENG_8 ?
 
 Thanks,
 
 -- 
 Bruno Ducrot
 
 --  Which is worse:  ignorance or apathy?
 --  Don't know.  Don't care.

From: BERTRAND Joel <joel.bertrand@systella.fr>
To: Bruno Ducrot <ducrot@echo.fr>
Cc: bug-followup@FreeBSD.org
Subject: Re: kern/141956: [libc] signal(3): siginfo-&gt;si_pid null in signal
 handler [regression]
Date: Fri, 29 Jan 2010 15:53:59 +0100

 Bruno Ducrot a crit :
 > Hi,
 >
 > With this test :
 > #include <stdio.h>
 > #include <stdlib.h>
 > #include <signal.h>
 > #include <unistd.h>
 >
 >
 > void
 > handler(int signal, siginfo_t *siginfo, void *context)
 > {
 > int i;
 > char *p = (char *)siginfo;
 >
 > printf("si_pid: %d (%d)\n", siginfo->si_pid, getpid());
 > printf("si_uid: %d\n", siginfo->si_uid);
 >
 > _exit(1);
 > }
 >
 > int
 > main(void)
 > {
 > struct sigaction sa;
 >
 > sa.sa_sigaction = handler;
 > sa.sa_flags = SA_SIGINFO;
 > sigemptyset(&sa.sa_mask);
 >
 > sigaction(SIGABRT, &sa, NULL);
 > abort();
 > return 0;
 > }
 >
 > I can indeed reproduce the same behaviour with RELENG_8_0 at least.
 >
 > But it seems this has been fixed by kid@ under CURRENT (SVN rev 199355).
 >
 > There is a MFC (SVN rev 200729), and therefore I can't reproduce anymore
 > this misbehaviour with RELENG_8 as of yesterday.
 >
 > Could you please confirm your software (RPL/2) work now as expected with
 > latest RELENG_8 ?
 
 	I can of course, but I have to upgrade my FreeBSD installation. I think 
 if shall be impossible until next week.
 
 	Regards,
 
 	JKB

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/141956: commit references a PR
Date: Mon,  1 Mar 2010 14:27:30 +0000 (UTC)

 Author: bruno
 Date: Mon Mar  1 14:27:16 2010
 New Revision: 204519
 URL: http://svn.freebsd.org/changeset/base/204519
 
 Log:
   Deliver siginfo when signal is generated by thr_kill(2) (SI_USER with properly
   filled si_uid and si_pid).
   
   Reported by:	Joel Bertrand <joel.bertrand systella fr>
   PR:		141956
   Reviewed by:	kib
   MFC after:	2 weeks
 
 Modified:
   head/sys/kern/kern_thr.c
 
 Modified: head/sys/kern/kern_thr.c
 ==============================================================================
 --- head/sys/kern/kern_thr.c	Mon Mar  1 13:56:15 2010	(r204518)
 +++ head/sys/kern/kern_thr.c	Mon Mar  1 14:27:16 2010	(r204519)
 @@ -303,12 +303,18 @@ int
  thr_kill(struct thread *td, struct thr_kill_args *uap)
      /* long id, int sig */
  {
 +	ksiginfo_t ksi;
  	struct thread *ttd;
  	struct proc *p;
  	int error;
  
  	p = td->td_proc;
  	error = 0;
 +	ksiginfo_init(&ksi);
 +	ksi.ksi_signo = uap->sig;
 +	ksi.ksi_code = SI_USER;
 +	ksi.ksi_pid = p->p_pid;
 +	ksi.ksi_uid = td->td_ucred->cr_ruid;
  	PROC_LOCK(p);
  	if (uap->id == -1) {
  		if (uap->sig != 0 && !_SIG_VALID(uap->sig)) {
 @@ -320,7 +326,7 @@ thr_kill(struct thread *td, struct thr_k
  					error = 0;
  					if (uap->sig == 0)
  						break;
 -					tdsignal(p, ttd, uap->sig, NULL);
 +					tdsignal(p, ttd, uap->sig, &ksi);
  				}
  			}
  		}
 @@ -336,7 +342,7 @@ thr_kill(struct thread *td, struct thr_k
  		else if (!_SIG_VALID(uap->sig))
  			error = EINVAL;
  		else
 -			tdsignal(p, ttd, uap->sig, NULL);
 +			tdsignal(p, ttd, uap->sig, &ksi);
  	}
  	PROC_UNLOCK(p);
  	return (error);
 @@ -346,6 +352,7 @@ int
  thr_kill2(struct thread *td, struct thr_kill2_args *uap)
      /* pid_t pid, long id, int sig */
  {
 +	ksiginfo_t ksi;
  	struct thread *ttd;
  	struct proc *p;
  	int error;
 @@ -362,6 +369,11 @@ thr_kill2(struct thread *td, struct thr_
  
  	error = p_cansignal(td, p, uap->sig);
  	if (error == 0) {
 +		ksiginfo_init(&ksi);
 +		ksi.ksi_signo = uap->sig;
 +		ksi.ksi_code = SI_USER;
 +		ksi.ksi_pid = td->td_proc->p_pid;
 +		ksi.ksi_uid = td->td_ucred->cr_ruid;
  		if (uap->id == -1) {
  			if (uap->sig != 0 && !_SIG_VALID(uap->sig)) {
  				error = EINVAL;
 @@ -372,7 +384,8 @@ thr_kill2(struct thread *td, struct thr_
  						error = 0;
  						if (uap->sig == 0)
  							break;
 -						tdsignal(p, ttd, uap->sig, NULL);
 +						tdsignal(p, ttd, uap->sig,
 +						    &ksi);
  					}
  				}
  			}
 @@ -388,7 +401,7 @@ thr_kill2(struct thread *td, struct thr_
  			else if (!_SIG_VALID(uap->sig))
  				error = EINVAL;
  			else
 -				tdsignal(p, ttd, uap->sig, NULL);
 +				tdsignal(p, ttd, uap->sig, &ksi);
  		}
  	}
  	PROC_UNLOCK(p);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: Bruno Ducrot <ducrot@echo.fr>
To: bug-followup@FreeBSD.org, joel.bertrand@systella.fr
Cc:  
Subject: Re: kern/141956: [libc] signal(3): siginfo-&gt;si_pid null in signal
 handler [regression]
Date: Mon, 01 Mar 2010 15:31:59 +0100

 Hi,
 
 Actually, the problem was with thr_kill(), and not kill(2).
 
 Just commited a fix for this, with kib review.
 
 Expect this problem being MFCd in 2 weeks if you stick with RELENG_8.
 
 Cheers,
 
 -- 
 Bruno Ducrot
 
 --  Which is worse:  ignorance or apathy?
 --  Don't know.  Don't care.
State-Changed-From-To: open->Patched 
State-Changed-By: bruno 
State-Changed-When: Mon Mar 1 17:45:43 UTC 2010 
State-Changed-Why:  
Has been fixed in HEAD.  Waiting MFC before closing this PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=141956 
State-Changed-From-To: Patched->Closed 
State-Changed-By: bruno 
State-Changed-When: Mon Mar 15 15:33:59 UTC 2010 
State-Changed-Why:  
Fixed in stable. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=141956 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/141956: commit references a PR
Date: Mon, 15 Mar 2010 15:33:42 +0000 (UTC)

 Author: bruno
 Date: Mon Mar 15 15:33:32 2010
 New Revision: 205168
 URL: http://svn.freebsd.org/changeset/base/205168
 
 Log:
   MFC r204519:
   Deliver siginfo when signal is generated by thr_kill(2) (SI_USER with properly
   filled si_uid and si_pid).
   
   PR:		141956
 
 Modified:
   stable/8/sys/kern/kern_thr.c
 
 Modified: stable/8/sys/kern/kern_thr.c
 ==============================================================================
 --- stable/8/sys/kern/kern_thr.c	Mon Mar 15 14:20:16 2010	(r205167)
 +++ stable/8/sys/kern/kern_thr.c	Mon Mar 15 15:33:32 2010	(r205168)
 @@ -303,12 +303,18 @@ int
  thr_kill(struct thread *td, struct thr_kill_args *uap)
      /* long id, int sig */
  {
 +	ksiginfo_t ksi;
  	struct thread *ttd;
  	struct proc *p;
  	int error;
  
  	p = td->td_proc;
  	error = 0;
 +	ksiginfo_init(&ksi);
 +	ksi.ksi_signo = uap->sig;
 +	ksi.ksi_code = SI_USER;
 +	ksi.ksi_pid = p->p_pid;
 +	ksi.ksi_uid = td->td_ucred->cr_ruid;
  	PROC_LOCK(p);
  	if (uap->id == -1) {
  		if (uap->sig != 0 && !_SIG_VALID(uap->sig)) {
 @@ -320,7 +326,7 @@ thr_kill(struct thread *td, struct thr_k
  					error = 0;
  					if (uap->sig == 0)
  						break;
 -					tdsignal(p, ttd, uap->sig, NULL);
 +					tdsignal(p, ttd, uap->sig, &ksi);
  				}
  			}
  		}
 @@ -336,7 +342,7 @@ thr_kill(struct thread *td, struct thr_k
  		else if (!_SIG_VALID(uap->sig))
  			error = EINVAL;
  		else
 -			tdsignal(p, ttd, uap->sig, NULL);
 +			tdsignal(p, ttd, uap->sig, &ksi);
  	}
  	PROC_UNLOCK(p);
  	return (error);
 @@ -346,6 +352,7 @@ int
  thr_kill2(struct thread *td, struct thr_kill2_args *uap)
      /* pid_t pid, long id, int sig */
  {
 +	ksiginfo_t ksi;
  	struct thread *ttd;
  	struct proc *p;
  	int error;
 @@ -362,6 +369,11 @@ thr_kill2(struct thread *td, struct thr_
  
  	error = p_cansignal(td, p, uap->sig);
  	if (error == 0) {
 +		ksiginfo_init(&ksi);
 +		ksi.ksi_signo = uap->sig;
 +		ksi.ksi_code = SI_USER;
 +		ksi.ksi_pid = td->td_proc->p_pid;
 +		ksi.ksi_uid = td->td_ucred->cr_ruid;
  		if (uap->id == -1) {
  			if (uap->sig != 0 && !_SIG_VALID(uap->sig)) {
  				error = EINVAL;
 @@ -372,7 +384,8 @@ thr_kill2(struct thread *td, struct thr_
  						error = 0;
  						if (uap->sig == 0)
  							break;
 -						tdsignal(p, ttd, uap->sig, NULL);
 +						tdsignal(p, ttd, uap->sig,
 +						    &ksi);
  					}
  				}
  			}
 @@ -388,7 +401,7 @@ thr_kill2(struct thread *td, struct thr_
  			else if (!_SIG_VALID(uap->sig))
  				error = EINVAL;
  			else
 -				tdsignal(p, ttd, uap->sig, NULL);
 +				tdsignal(p, ttd, uap->sig, &ksi);
  		}
  	}
  	PROC_UNLOCK(p);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: Closed->closed 
State-Changed-By: linimon 
State-Changed-When: Sat Apr 10 22:29:16 UTC 2010 
State-Changed-Why:  
properly spell state name. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=141956 
>Unformatted:
