From owner-svn-src-head@freebsd.org Sun Sep 1 14:01:10 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4CC92DB07E; Sun, 1 Sep 2019 14:01:10 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46LvyG1D1fz4LnM; Sun, 1 Sep 2019 14:01:10 +0000 (UTC) (envelope-from mjg@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0D869264B; Sun, 1 Sep 2019 14:01:10 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x81E19nV013636; Sun, 1 Sep 2019 14:01:09 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x81E192l013635; Sun, 1 Sep 2019 14:01:09 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201909011401.x81E192l013635@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Sun, 1 Sep 2019 14:01:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351656 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 351656 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 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: Sun, 01 Sep 2019 14:01:10 -0000 Author: mjg Date: Sun Sep 1 14:01:09 2019 New Revision: 351656 URL: https://svnweb.freebsd.org/changeset/base/351656 Log: vfs: stop refing freed mount points in vop_stdgetwritemount The code used blindly ref based on an unsafely red address and then would backpedal if necessary. This was safe in terms of memory access since mounts are type-stable, but made for a potential a bug where the mount was reused and had the count reset to 0 before this code decreased it. Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D21411 Modified: head/sys/kern/vfs_default.c Modified: head/sys/kern/vfs_default.c ============================================================================== --- head/sys/kern/vfs_default.c Sun Sep 1 10:39:16 2019 (r351655) +++ head/sys/kern/vfs_default.c Sun Sep 1 14:01:09 2019 (r351656) @@ -588,22 +588,28 @@ vop_stdgetwritemount(ap) } */ *ap; { struct mount *mp; + struct vnode *vp; /* - * XXX Since this is called unlocked we may be recycled while - * attempting to ref the mount. If this is the case or mountpoint - * will be set to NULL. We only have to prevent this call from - * returning with a ref to an incorrect mountpoint. It is not - * harmful to return with a ref to our previous mountpoint. + * Note that having a reference does not prevent forced unmount from + * setting ->v_mount to NULL after the lock gets released. This is of + * no consequence for typical consumers (most notably vn_start_write) + * since in this case the vnode is VI_DOOMED. Unmount might have + * progressed far enough that its completion is only delayed by the + * reference obtained here. The consumer only needs to concern itself + * with releasing it. */ - mp = ap->a_vp->v_mount; - if (mp != NULL) { - vfs_ref(mp); - if (mp != ap->a_vp->v_mount) { - vfs_rel(mp); - mp = NULL; - } + vp = ap->a_vp; + mp = vp->v_mount; + MNT_ILOCK(mp); + if (mp != vp->v_mount) { + MNT_IUNLOCK(mp); + mp = NULL; + goto out; } + MNT_REF(mp); + MNT_IUNLOCK(mp); +out: *(ap->a_mpp) = mp; return (0); }