From owner-svn-src-stable-7@FreeBSD.ORG  Thu Nov 13 15:00:41 2008
Return-Path: <owner-svn-src-stable-7@FreeBSD.ORG>
Delivered-To: svn-src-stable-7@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 896E71065752;
	Thu, 13 Nov 2008 15:00:40 +0000 (UTC) (envelope-from kib@FreeBSD.org)
Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c])
	by mx1.freebsd.org (Postfix) with ESMTP id 6B0538FC0A;
	Thu, 13 Nov 2008 15:00:40 +0000 (UTC) (envelope-from kib@FreeBSD.org)
Received: from svn.freebsd.org (localhost [127.0.0.1])
	by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mADF0eSH061784;
	Thu, 13 Nov 2008 15:00:40 GMT (envelope-from kib@svn.freebsd.org)
Received: (from kib@localhost)
	by svn.freebsd.org (8.14.3/8.14.3/Submit) id mADF0esO061783;
	Thu, 13 Nov 2008 15:00:40 GMT (envelope-from kib@svn.freebsd.org)
Message-Id: <200811131500.mADF0esO061783@svn.freebsd.org>
From: Konstantin Belousov <kib@FreeBSD.org>
Date: Thu, 13 Nov 2008 15:00:40 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
	svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
X-SVN-Group: stable-7
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Cc: 
Subject: svn commit: r184924 - in stable/7/sys: . compat/linux modules/cxgb
X-BeenThere: svn-src-stable-7@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: SVN commit messages for only the 7-stable src tree
	<svn-src-stable-7.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-stable-7>, 
	<mailto:svn-src-stable-7-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-stable-7>
List-Post: <mailto:svn-src-stable-7@freebsd.org>
List-Help: <mailto:svn-src-stable-7-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-stable-7>, 
	<mailto:svn-src-stable-7-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 13 Nov 2008 15:00:41 -0000

Author: kib
Date: Thu Nov 13 15:00:40 2008
New Revision: 184924
URL: http://svn.freebsd.org/changeset/base/184924

Log:
  MFC r184501:
  The code in linux_proc_exit() contains a race when multiple linux based
  processes exits at the same time. The linux_emuldata structure is freed
  but p->p_emuldata is left as a dangling pointer to the just freed
  memory.
  
  The check for W_EXIT in the loop scanning the child processes isn't safe
  since the state of the child process can change right afterwards. Lock
  the process and check the W_EXIT before delivering signal.
  
  Approved by:	re (kensmith)

Modified:
  stable/7/sys/   (props changed)
  stable/7/sys/compat/linux/linux_emul.c
  stable/7/sys/modules/cxgb/   (props changed)

Modified: stable/7/sys/compat/linux/linux_emul.c
==============================================================================
--- stable/7/sys/compat/linux/linux_emul.c	Thu Nov 13 15:00:34 2008	(r184923)
+++ stable/7/sys/compat/linux/linux_emul.c	Thu Nov 13 15:00:40 2008	(r184924)
@@ -232,11 +232,11 @@ linux_proc_exit(void *arg __unused, stru
 			continue;
 		em = em_find(q, EMUL_DOLOCK);
 		KASSERT(em != NULL, ("linux_reparent: emuldata not found: %i\n", q->p_pid));
-		if (em->pdeath_signal != 0) {
-			PROC_LOCK(q);
+		PROC_LOCK(q);
+		if ((q->p_flag & P_WEXIT) == 0 && em->pdeath_signal != 0) {
 			psignal(q, em->pdeath_signal);
-			PROC_UNLOCK(q);
 		}
+		PROC_UNLOCK(q);
 		EMUL_UNLOCK(&emul_lock);
 	}
 	sx_xunlock(&proctree_lock);