From owner-svn-src-head@freebsd.org Fri Oct 9 19:10:01 2020 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 2B177429912; Fri, 9 Oct 2020 19:10:01 +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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 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 4C7Hh902qRz4kpv; Fri, 9 Oct 2020 19:10:01 +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 C02FE1E421; Fri, 9 Oct 2020 19:10:00 +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 099JA0Yd087373; Fri, 9 Oct 2020 19:10:00 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 099JA08f087371; Fri, 9 Oct 2020 19:10:00 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202010091910.099JA08f087371@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Fri, 9 Oct 2020 19:10:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r366582 - in head/sys: fs/deadfs kern X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: in head/sys: fs/deadfs kern X-SVN-Commit-Revision: 366582 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.33 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: Fri, 09 Oct 2020 19:10:01 -0000 Author: mjg Date: Fri Oct 9 19:10:00 2020 New Revision: 366582 URL: https://svnweb.freebsd.org/changeset/base/366582 Log: cache: fix vexec panic when racing against vgone Use of dead_vnodeops would result in a panic instead of returning the intended EOPNOTSUPP error. While here make sure to abort, not just try to return a partial result. The former allows the regular lookup to restart from scratch, while the latter makes it stuck with an unusable vnode. Reported by: kevans Modified: head/sys/fs/deadfs/dead_vnops.c head/sys/kern/vfs_cache.c Modified: head/sys/fs/deadfs/dead_vnops.c ============================================================================== --- head/sys/fs/deadfs/dead_vnops.c Fri Oct 9 18:30:49 2020 (r366581) +++ head/sys/fs/deadfs/dead_vnops.c Fri Oct 9 19:10:00 2020 (r366582) @@ -79,6 +79,7 @@ struct vop_vector dead_vnodeops = { .vop_vptocnp = VOP_EBADF, .vop_unset_text = dead_unset_text, .vop_write = dead_write, + .vop_fplookup_vexec = VOP_EOPNOTSUPP, }; VFS_VOP_VECTOR_REGISTER(dead_vnodeops); Modified: head/sys/kern/vfs_cache.c ============================================================================== --- head/sys/kern/vfs_cache.c Fri Oct 9 18:30:49 2020 (r366581) +++ head/sys/kern/vfs_cache.c Fri Oct 9 19:10:00 2020 (r366582) @@ -4040,32 +4040,46 @@ cache_fplookup_parse_advance(struct cache_fpl *fpl) } } +/* + * See the API contract for VOP_FPLOOKUP_VEXEC. + */ static int __noinline cache_fplookup_failed_vexec(struct cache_fpl *fpl, int error) { + struct vnode *dvp; + seqc_t dvp_seqc; + dvp = fpl->dvp; + dvp_seqc = fpl->dvp_seqc; + /* * Hack: they may be looking up foo/bar, where foo is a * regular file. In such a case we need to turn ENOTDIR, * but we may happen to get here with a different error. */ - if (fpl->dvp->v_type != VDIR) { + if (dvp->v_type != VDIR) { + /* + * The check here is predominantly to catch + * EOPNOTSUPP from dead_vnodeops. If the vnode + * gets doomed past this point it is going to + * fail seqc verification. + */ + if (VN_IS_DOOMED(dvp)) { + return (cache_fpl_aborted(fpl)); + } error = ENOTDIR; } switch (error) { case EAGAIN: - /* - * Can happen when racing against vgone. - * */ - case EOPNOTSUPP: - cache_fpl_partial(fpl); + if (!vn_seqc_consistent(dvp, dvp_seqc)) { + error = cache_fpl_aborted(fpl); + } else { + cache_fpl_partial(fpl); + } break; default: - /* - * See the API contract for VOP_FPLOOKUP_VEXEC. - */ - if (!vn_seqc_consistent(fpl->dvp, fpl->dvp_seqc)) { + if (!vn_seqc_consistent(dvp, dvp_seqc)) { error = cache_fpl_aborted(fpl); } else { cache_fpl_smr_exit(fpl);