From owner-svn-src-all@freebsd.org Thu Nov 12 08:47:12 2015 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 55263A2C680; Thu, 12 Nov 2015 08:47:12 +0000 (UTC) (envelope-from hselasky@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 1E57713DD; Thu, 12 Nov 2015 08:47:12 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tAC8lBcR049830; Thu, 12 Nov 2015 08:47:11 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tAC8lBZw049829; Thu, 12 Nov 2015 08:47:11 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201511120847.tAC8lBZw049829@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 12 Nov 2015 08:47:11 +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: r290705 - 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-all@freebsd.org X-Mailman-Version: 2.1.20 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: Thu, 12 Nov 2015 08:47:12 -0000 Author: hselasky Date: Thu Nov 12 08:47:10 2015 New Revision: 290705 URL: https://svnweb.freebsd.org/changeset/base/290705 Log: MFC r290140: Add missing NULL check in physio(). When destroying a character device the si_devsw field is set to NULL before all references are gone, to indicate the character device is going away. This can cause a NULL-dereference fault inside physio(). The callers of physio() should own a thread reference on the cdev and if si_devsw is seen as non-NULL, it is usable during the execution of the function. Else an ENXIO error code is returned. Reviewed by: kib Modified: stable/10/sys/kern/kern_physio.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/kern/kern_physio.c ============================================================================== --- stable/10/sys/kern/kern_physio.c Thu Nov 12 05:53:32 2015 (r290704) +++ stable/10/sys/kern/kern_physio.c Thu Nov 12 08:47:10 2015 (r290705) @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); int physio(struct cdev *dev, struct uio *uio, int ioflag) { + struct cdevsw *csw; struct buf *pbuf; struct bio *bp; struct vm_page **pages; @@ -46,6 +47,11 @@ physio(struct cdev *dev, struct uio *uio int error, i, npages, maxpages; vm_prot_t prot; + csw = dev->si_devsw; + /* check if character device is being destroyed */ + if (csw == NULL) + return (ENXIO); + /* XXX: sanity check */ if(dev->si_iosize_max < PAGE_SIZE) { printf("WARNING: %s si_iosize_max=%d, using DFLTPHYS.\n", @@ -165,7 +171,7 @@ physio(struct cdev *dev, struct uio *uio } } - dev->si_devsw->d_strategy(bp); + csw->d_strategy(bp); if (uio->uio_rw == UIO_READ) biowait(bp, "physrd"); else