From owner-svn-src-stable@freebsd.org Wed Jun 15 01:56:21 2016 Return-Path: Delivered-To: svn-src-stable@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 63435B72C3E; Wed, 15 Jun 2016 01:56:21 +0000 (UTC) (envelope-from jamie@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 17EFD29CC; Wed, 15 Jun 2016 01:56:21 +0000 (UTC) (envelope-from jamie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5F1uKQ2022431; Wed, 15 Jun 2016 01:56:20 GMT (envelope-from jamie@FreeBSD.org) Received: (from jamie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5F1uKEq022430; Wed, 15 Jun 2016 01:56:20 GMT (envelope-from jamie@FreeBSD.org) Message-Id: <201606150156.u5F1uKEq022430@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jamie set sender to jamie@FreeBSD.org using -f From: Jamie Gritton Date: Wed, 15 Jun 2016 01:56:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r301907 - stable/10/sys/kern X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jun 2016 01:56:21 -0000 Author: jamie Date: Wed Jun 15 01:56:20 2016 New Revision: 301907 URL: https://svnweb.freebsd.org/changeset/base/301907 Log: MFC r301745: Make sure the OSD methods for jail set and remove can't run concurrently, by holding allprison_lock exclusively (even if only for a moment before downgrading) on all paths that call PR_METHOD_REMOVE. Since they may run on a downgraded lock, it's still possible for them to run concurrently with PR_METHOD_GET, which will need to use the prison lock. Modified: stable/10/sys/kern/kern_jail.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/kern/kern_jail.c ============================================================================== --- stable/10/sys/kern/kern_jail.c Wed Jun 15 01:54:17 2016 (r301906) +++ stable/10/sys/kern/kern_jail.c Wed Jun 15 01:56:20 2016 (r301907) @@ -2400,7 +2400,14 @@ sys_jail_attach(struct thread *td, struc if (error) return (error); - sx_slock(&allprison_lock); + /* + * Start with exclusive hold on allprison_lock to ensure that a possible + * PR_METHOD_REMOVE call isn't concurrent with jail_set or jail_remove. + * But then immediately downgrade it since we don't need to stop + * readers. + */ + sx_xlock(&allprison_lock); + sx_downgrade(&allprison_lock); pr = prison_find_child(td->td_ucred->cr_prison, uap->jid); if (pr == NULL) { sx_sunlock(&allprison_lock); @@ -2618,9 +2625,11 @@ prison_complete(void *context, int pendi { struct prison *pr = context; + sx_xlock(&allprison_lock); mtx_lock(&pr->pr_mtx); prison_deref(pr, pr->pr_uref - ? PD_DEREF | PD_DEUREF | PD_LOCKED : PD_LOCKED); + ? PD_DEREF | PD_DEUREF | PD_LOCKED | PD_LIST_XLOCKED + : PD_LOCKED | PD_LIST_XLOCKED); } /* @@ -2664,13 +2673,8 @@ prison_deref(struct prison *pr, int flag */ if (lasturef) { if (!(flags & (PD_LIST_SLOCKED | PD_LIST_XLOCKED))) { - if (ref > 1) { - sx_slock(&allprison_lock); - flags |= PD_LIST_SLOCKED; - } else { - sx_xlock(&allprison_lock); - flags |= PD_LIST_XLOCKED; - } + sx_xlock(&allprison_lock); + flags |= PD_LIST_XLOCKED; } (void)osd_jail_call(pr, PR_METHOD_REMOVE, NULL); mtx_lock(&pr->pr_mtx);