From owner-svn-src-all@freebsd.org Tue Dec 6 17:13:18 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5BDADC692AD; Tue, 6 Dec 2016 17:13:18 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 2B86E15B8; Tue, 6 Dec 2016 17:13:18 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uB6HDHJr080582; Tue, 6 Dec 2016 17:13:17 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uB6HDH0g080581; Tue, 6 Dec 2016 17:13:17 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201612061713.uB6HDH0g080581@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 6 Dec 2016 17:13:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r309630 - head/lib/libthr/thread X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Dec 2016 17:13:18 -0000 Author: kib Date: Tue Dec 6 17:13:17 2016 New Revision: 309630 URL: https://svnweb.freebsd.org/changeset/base/309630 Log: Do not leak curthread->inact_mtx when cancelling in pthread_cond_wait(3). Leave robust-protected region before checking for cancellation by calling _thr_testcancel(). Otherwise, if cancelling request was pending, the cancel handler is called with the dandling inact_mtx, which triggers an assert if any mutex operation is performed by the handler. Reported and tested by: Dimitri Staessens Sponsored by: The FreeBSD Foundation MFC after: 1 week Modified: head/lib/libthr/thread/thr_cond.c Modified: head/lib/libthr/thread/thr_cond.c ============================================================================== --- head/lib/libthr/thread/thr_cond.c Tue Dec 6 17:10:17 2016 (r309629) +++ head/lib/libthr/thread/thr_cond.c Tue Dec 6 17:13:17 2016 (r309630) @@ -224,16 +224,26 @@ cond_wait_kernel(struct pthread_cond *cv * state and unlock the mutex without making the state * consistent and the state will be unrecoverable. */ - if (error2 == 0 && cancel) + if (error2 == 0 && cancel) { + if (robust) { + _mutex_leave_robust(curthread, mp); + robust = false; + } _thr_testcancel(curthread); + } if (error == EINTR) error = 0; } else { /* We know that it didn't unlock the mutex. */ _mutex_cv_attach(mp, recurse); - if (cancel) + if (cancel) { + if (robust) { + _mutex_leave_robust(curthread, mp); + robust = false; + } _thr_testcancel(curthread); + } error2 = 0; } if (robust)