From owner-svn-src-head@FreeBSD.ORG Mon Jun 8 13:34:46 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 13BF71065670; Mon, 8 Jun 2009 13:34:46 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 024FD8FC1E; Mon, 8 Jun 2009 13:34:46 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n58DYjtg030727; Mon, 8 Jun 2009 13:34:45 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n58DYjKs030726; Mon, 8 Jun 2009 13:34:45 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <200906081334.n58DYjKs030726@svn.freebsd.org> From: Konstantin Belousov Date: Mon, 8 Jun 2009 13:34:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r193714 - head/sys/kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jun 2009 13:34:46 -0000 Author: kib Date: Mon Jun 8 13:34:45 2009 New Revision: 193714 URL: http://svn.freebsd.org/changeset/base/193714 Log: Do not dereference vp->v_rdev without holding any of dev_mtx or vnode lock. Use code similar to devfs_fp_check(), but inlined to feet other checks performed by ttyhook_register(). Reviewed by: ed Modified: head/sys/kern/tty.c Modified: head/sys/kern/tty.c ============================================================================== --- head/sys/kern/tty.c Mon Jun 8 13:31:27 2009 (r193713) +++ head/sys/kern/tty.c Mon Jun 8 13:34:45 2009 (r193714) @@ -1742,19 +1742,31 @@ ttyhook_register(struct tty **rtp, struc goto done1; } - /* Make sure the vnode is bound to a character device. */ - error = EINVAL; - if (fp->f_type != DTYPE_VNODE || fp->f_vnode->v_type != VCHR || - fp->f_vnode->v_rdev == NULL) + /* + * Make sure the vnode is bound to a character device. + * Unlocked check for the vnode type is ok there, because we + * only shall prevent calling devvn_refthread on the file that + * never has been opened over a character device. + */ + if (fp->f_type != DTYPE_VNODE || fp->f_vnode->v_type != VCHR) { + error = EINVAL; goto done1; - dev = fp->f_vnode->v_rdev; + } /* Make sure it is a TTY. */ - cdp = dev_refthread(dev); - if (cdp == NULL) + cdp = devvn_refthread(fp->f_vnode, &dev); + if (cdp == NULL) { + error = ENXIO; goto done1; - if (cdp != &ttydev_cdevsw) + } + if (dev != fp->f_data) { + error = ENXIO; goto done2; + } + if (cdp != &ttydev_cdevsw) { + error = ENOTTY; + goto done2; + } tp = dev->si_drv1; /* Try to attach the hook to the TTY. */