From owner-svn-src-all@FreeBSD.ORG Wed Oct 23 12:53:06 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 8A29116E; Wed, 23 Oct 2013 12:53:06 +0000 (UTC) (envelope-from mav@FreeBSD.org) 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)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 774E72C3E; Wed, 23 Oct 2013 12:53:06 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9NCr6NQ073686; Wed, 23 Oct 2013 12:53:06 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9NCr6sw073685; Wed, 23 Oct 2013 12:53:06 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <201310231253.r9NCr6sw073685@svn.freebsd.org> From: Alexander Motin Date: Wed, 23 Oct 2013 12:53:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r256960 - head/sys/cam 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.14 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: Wed, 23 Oct 2013 12:53:06 -0000 Author: mav Date: Wed Oct 23 12:53:05 2013 New Revision: 256960 URL: http://svnweb.freebsd.org/changeset/base/256960 Log: Move CAM_UNQUEUED_INDEX setting to the last moment and under the periph lock. This fixes race condition with cam_periph_ccbwait(), causing use-after-free. Modified: head/sys/cam/cam_xpt.c Modified: head/sys/cam/cam_xpt.c ============================================================================== --- head/sys/cam/cam_xpt.c Wed Oct 23 12:29:39 2013 (r256959) +++ head/sys/cam/cam_xpt.c Wed Oct 23 12:53:05 2013 (r256960) @@ -5239,6 +5239,7 @@ xpt_done_process(struct ccb_hdr *ccb_h) } /* Call the peripheral driver's callback */ + ccb_h->pinfo.index = CAM_UNQUEUED_INDEX; (*ccb_h->cbfcnp)(ccb_h->path->periph, (union ccb *)ccb_h); if (mtx != NULL) mtx_unlock(mtx); @@ -5270,7 +5271,6 @@ xpt_done_td(void *arg) THREAD_NO_SLEEPING(); while ((ccb_h = STAILQ_FIRST(&doneq)) != NULL) { STAILQ_REMOVE_HEAD(&doneq, sim_links.stqe); - ccb_h->pinfo.index = CAM_UNQUEUED_INDEX; xpt_done_process(ccb_h); } THREAD_SLEEPING_OK();