From nobody@FreeBSD.org  Wed Apr 20 07:30:10 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 8A90016A4CE
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Apr 2005 07:30:10 +0000 (GMT)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 5940443D39
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Apr 2005 07:30:10 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j3K7U7Sx020056
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Apr 2005 07:30:07 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j3K7U7OU020055;
	Wed, 20 Apr 2005 07:30:07 GMT
	(envelope-from nobody)
Message-Id: <200504200730.j3K7U7OU020055@www.freebsd.org>
Date: Wed, 20 Apr 2005 07:30:07 GMT
From: Kostik Belousov <konstantin.belousov@zoral.com.ua>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] sigprocmask erronously cleared on fork (5-STABLE and later)
X-Send-Pr-Version: www-2.3

>Number:         80130
>Category:       kern
>Synopsis:       [patch] sigprocmask erronously cleared on fork (5-STABLE and later)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 20 07:40:02 GMT 2005
>Closed-Date:    Fri Apr 29 11:17:00 GMT 2005
>Last-Modified:  Fri Apr 29 11:17:00 GMT 2005
>Originator:     Kostik Belousov
>Release:        5-STABLE
>Organization:
>Environment:
FreeBSD deviant.zoral.local 5.4-STABLE FreeBSD 5.4-STABLE #16: Tue Apr 12 11:06:01 EEST 2005 root@deviant.zoral.local:/usr/obj/usr/src/sys/DEVIANT  i386
>Description:
      After fork(), the 5-STABLE system sets the child process                        
blocked signal mask to 0 (let us account single-threaded processes only). I was under impression that signal mask                                            shall be inherited by the child process (according to SUSv3 and man fork). Inheritance _was_ the behaviour of 4-STABLE (there, p_sigmask belongs to struct proc and placed in the copied-on-fork part of the structure) and also seen on other UNIXes (e.g. Solaris).

It seems that needs of thread_schedule_upcall() to zero sigmask interfere with the needs of the fork1().                                                    I propose the trivial patch (against 5-STABLE) to fix the problems. It handles td_sigmask in the way similar to td_sigstk, that is also zeroed on _upcall(), as was done by davidxu at kern/kern_fork.c:1.209 rev.
>How-To-Repeat:
I send the letter to the freebsd-hackers at Apr 12, 2005 with the program that shows the problem, see

http://lists.freebsd.org/pipermail/freebsd-hackers/2005-April/011513.html


>Fix:
Index: kern/kern_fork.c
===================================================================
RCS file: /usr/local/arch/ncvs/src/sys/kern/kern_fork.c,v
retrieving revision 1.234.2.8
diff -U3 -r1.234.2.8 kern_fork.c
--- kern/kern_fork.c    27 Feb 2005 02:36:39 -0000      1.234.2.8
+++ kern/kern_fork.c    20 Apr 2005 07:27:00 -0000
@@ -472,6 +472,7 @@
            __rangeof(struct ksegrp, kg_startcopy, kg_endcopy));
 
        td2->td_sigstk = td->td_sigstk;
+       td2->td_sigmask = td->td_sigmask;
 
        /*
         * Duplicate sub-structures as needed.

>Release-Note:
>Audit-Trail:

From: David Xu <davidxu@freebsd.org>
To: Kostik Belousov <konstantin.belousov@zoral.com.ua>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: kern/80130: [patch] sigprocmask erronously cleared on fork	(5-STABLE
 and later)
Date: Wed, 20 Apr 2005 16:32:58 +0800

 Kostik Belousov wrote:
 
 >>Number:         80130
 >>Category:       kern
 >>Synopsis:       [patch] sigprocmask erronously cleared on fork (5-STABLE and later)
 >>Confidential:   no
 >>Severity:       serious
 >>Priority:       medium
 >>Responsible:    freebsd-bugs
 >>State:          open
 >>Quarter:        
 >>Keywords:       
 >>Date-Required:
 >>Class:          sw-bug
 >>Submitter-Id:   current-users
 >>Arrival-Date:   Wed Apr 20 07:40:02 GMT 2005
 >>Closed-Date:
 >>Last-Modified:
 >>Originator:     Kostik Belousov
 >>Release:        5-STABLE
 >>Organization:
 >>Environment:
 >>    
 >>
 >FreeBSD deviant.zoral.local 5.4-STABLE FreeBSD 5.4-STABLE #16: Tue Apr 12 11:06:01 EEST 2005 root@deviant.zoral.local:/usr/obj/usr/src/sys/DEVIANT  i386
 >  
 >
 >>Description:
 >>    
 >>
 >      After fork(), the 5-STABLE system sets the child process                        
 >blocked signal mask to 0 (let us account single-threaded processes only). I was under impression that signal mask                                            shall be inherited by the child process (according to SUSv3 and man fork). Inheritance _was_ the behaviour of 4-STABLE (there, p_sigmask belongs to struct proc and placed in the copied-on-fork part of the structure) and also seen on other UNIXes (e.g. Solaris).
 >
 >It seems that needs of thread_schedule_upcall() to zero sigmask interfere with the needs of the fork1().                                                    I propose the trivial patch (against 5-STABLE) to fix the problems. It handles td_sigmask in the way similar to td_sigstk, that is also zeroed on _upcall(), as was done by davidxu at kern/kern_fork.c:1.209 rev.
 >  
 >
 >>How-To-Repeat:
 >>    
 >>
 >I send the letter to the freebsd-hackers at Apr 12, 2005 with the program that shows the problem, see
 >
 >http://lists.freebsd.org/pipermail/freebsd-hackers/2005-April/011513.html
 >
 >
 >  
 >
 >>Fix:
 >>    
 >>
 >Index: kern/kern_fork.c
 >===================================================================
 >RCS file: /usr/local/arch/ncvs/src/sys/kern/kern_fork.c,v
 >retrieving revision 1.234.2.8
 >diff -U3 -r1.234.2.8 kern_fork.c
 >--- kern/kern_fork.c    27 Feb 2005 02:36:39 -0000      1.234.2.8
 >+++ kern/kern_fork.c    20 Apr 2005 07:27:00 -0000
 >@@ -472,6 +472,7 @@
 >            __rangeof(struct ksegrp, kg_startcopy, kg_endcopy));
 > 
 >        td2->td_sigstk = td->td_sigstk;
 >+       td2->td_sigmask = td->td_sigmask;
 > 
 >        /*
 >         * Duplicate sub-structures as needed.
 >
 >  
 >
 >>Release-Note:
 >>Audit-Trail:
 >>Unformatted:
 >>    
 >>
 The bug is also in -CURRENT. :(
 
 David Xu
 
State-Changed-From-To: open->closed 
State-Changed-By: davidxu 
State-Changed-When: Fri Apr 29 11:15:42 GMT 2005 
State-Changed-Why:  
Fixed on -CURRENT,RELENG_5_4 and RELENG_5. 

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