From owner-svn-src-user@FreeBSD.ORG  Wed Jan 14 22:05:29 2015
Return-Path: <owner-svn-src-user@FreeBSD.ORG>
Delivered-To: svn-src-user@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by hub.freebsd.org (Postfix) with ESMTPS id A94CDD35;
 Wed, 14 Jan 2015 22:05:29 +0000 (UTC)
Received: from svn.freebsd.org (svn.freebsd.org
 [IPv6:2001:1900:2254:2068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 94EAC3FE;
 Wed, 14 Jan 2015 22:05:29 +0000 (UTC)
Received: from svn.freebsd.org ([127.0.1.70])
 by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t0EM5TDU041217;
 Wed, 14 Jan 2015 22:05:29 GMT (envelope-from dchagin@FreeBSD.org)
Received: (from dchagin@localhost)
 by svn.freebsd.org (8.14.9/8.14.9/Submit) id t0EM5Tem041216;
 Wed, 14 Jan 2015 22:05:29 GMT (envelope-from dchagin@FreeBSD.org)
Message-Id: <201501142205.t0EM5Tem041216@svn.freebsd.org>
X-Authentication-Warning: svn.freebsd.org: dchagin set sender to
 dchagin@FreeBSD.org using -f
From: Dmitry Chagin <dchagin@FreeBSD.org>
Date: Wed, 14 Jan 2015 22:05:29 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-user@freebsd.org
Subject: svn commit: r277197 - user/dchagin/lemul/sys/compat/linux
X-SVN-Group: user
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-user@freebsd.org
X-Mailman-Version: 2.1.18-1
Precedence: list
List-Id: "SVN commit messages for the experimental &quot; user&quot;
 src tree" <svn-src-user.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-user/>
List-Post: <mailto:svn-src-user@freebsd.org>
List-Help: <mailto:svn-src-user-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-user>,
 <mailto:svn-src-user-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Wed, 14 Jan 2015 22:05:29 -0000

Author: dchagin
Date: Wed Jan 14 22:05:28 2015
New Revision: 277197
URL: https://svnweb.freebsd.org/changeset/base/277197

Log:
  In the case of an "that ugly way" when we try to find Linux thread by
  pfind() check that the returned process is a Linux process. Otherwise,
  below we dereference em pointer expecting it points to a Linux thread.
  
  Reported by:    trinity

Modified:
  user/dchagin/lemul/sys/compat/linux/linux_misc.c

Modified: user/dchagin/lemul/sys/compat/linux/linux_misc.c
==============================================================================
--- user/dchagin/lemul/sys/compat/linux/linux_misc.c	Wed Jan 14 21:39:31 2015	(r277196)
+++ user/dchagin/lemul/sys/compat/linux/linux_misc.c	Wed Jan 14 22:05:28 2015	(r277197)
@@ -2004,6 +2004,7 @@ linux_sched_rr_get_interval(struct threa
 struct thread *
 linux_tdfind(struct thread *td, lwpid_t tid, pid_t pid)
 {
+	struct linux_pemuldata *pem;
 	struct linux_emuldata *em;
 	struct thread *tdt;
 	struct proc *p;
@@ -2020,6 +2021,14 @@ linux_tdfind(struct thread *td, lwpid_t 
 		 */
 		p = pfind(tid);
 		if (p) {
+			pem = pem_find(p);
+			if (pem == NULL) {
+				/*
+				 * p is not a Linuxulator process.
+				 */
+				PROC_UNLOCK(p);
+				return (NULL);
+			}
 			FOREACH_THREAD_IN_PROC(p, tdt) {
 				em = em_find(tdt);
 				if (tid == em->em_tid)