From owner-svn-src-stable@freebsd.org Mon Sep 4 08:41:52 2017 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 B92CBE1C603; Mon, 4 Sep 2017 08:41:52 +0000 (UTC) (envelope-from kib@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 87EF26B363; Mon, 4 Sep 2017 08:41:52 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v848fpeK071653; Mon, 4 Sep 2017 08:41:51 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v848fpm9071652; Mon, 4 Sep 2017 08:41:51 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201709040841.v848fpm9071652@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 4 Sep 2017 08:41:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r323153 - stable/11/sys/ufs/ffs X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/sys/ufs/ffs X-SVN-Commit-Revision: 323153 X-SVN-Commit-Repository: base 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.23 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: Mon, 04 Sep 2017 08:41:52 -0000 Author: kib Date: Mon Sep 4 08:41:51 2017 New Revision: 323153 URL: https://svnweb.freebsd.org/changeset/base/323153 Log: MFC r322757, r322883: Avoid dereferencing potentially freed workitem in softdep_count_dependencies(). Modified: stable/11/sys/ufs/ffs/ffs_softdep.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/ufs/ffs/ffs_softdep.c ============================================================================== --- stable/11/sys/ufs/ffs/ffs_softdep.c Mon Sep 4 08:38:34 2017 (r323152) +++ stable/11/sys/ufs/ffs/ffs_softdep.c Mon Sep 4 08:41:51 2017 (r323153) @@ -13911,12 +13911,36 @@ softdep_count_dependencies(bp, wantcount) struct newblk *newblk; struct mkdir *mkdir; struct diradd *dap; + struct vnode *vp; + struct mount *mp; int i, retval; retval = 0; - if ((wk = LIST_FIRST(&bp->b_dep)) == NULL) + if (LIST_EMPTY(&bp->b_dep)) return (0); - ump = VFSTOUFS(wk->wk_mp); + vp = bp->b_vp; + + /* + * The ump mount point is stable after we get a correct + * pointer, since bp is locked and this prevents unmount from + * proceed. But to get to it, we cannot dereference bp->b_dep + * head wk_mp, because we do not yet own SU ump lock and + * workitem might be freed while dereferenced. + */ +retry: + if (vp->v_type == VCHR) { + VI_LOCK(vp); + mp = vp->v_type == VCHR ? vp->v_rdev->si_mountpt : NULL; + VI_UNLOCK(vp); + if (mp == NULL) + goto retry; + } else if (vp->v_type == VREG) { + mp = vp->v_mount; + } else { + return (0); + } + ump = VFSTOUFS(mp); + ACQUIRE_LOCK(ump); LIST_FOREACH(wk, &bp->b_dep, wk_list) { switch (wk->wk_type) {