From nobody Sat Oct 14 01:08:48 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4S6lcw3BcPz4x4Jw; Sat, 14 Oct 2023 01:08:48 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4S6lcw2hskz3XTZ; Sat, 14 Oct 2023 01:08:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697245728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3MVaPc64WWnfjZ2S6W33abKNAGC+3YUoX5x+vLoxSAc=; b=wD7FF4T/JvB8VtmBOyPjK+b5w7P24xnXfizIi0UQn9QUnt9E+y/ahkR8pu5M7iebeCRhPb VBP5zu0Yrgk8/Ji9N0aCCcj1RXBPpRno392a0/LdHwWnJbbfRnofDgPFoqTNnUTFnwprj9 Z/lnkWFkQocGxLapGIGseODVIERwmCeigxh9ycbLxqme8sRDnOvSaYpw1Fzuxo6aY5RDKB XsGGPXoD9ms9KzN+CQfJ3niRE9wGKFu2uEvwqp/7NWX9GLCqn+x/rxz+POm7iODsSo3j61 fEvjEuxo6awvEgeKuZJulepZXYIk5aczcTQA+fQMf/87etRFHzYy5QHvCfMriQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697245728; a=rsa-sha256; cv=none; b=G6DC1B/kkrnwQgrDCTk14Q2kLiHw738OzJM0XkWwqy7msJBnIJAvyruHUsQywbsnGQx9Oq z8xypXQMI4c8mjd1nVJ8X1qPeO7NP13fEOXXUJ4y2dk++tu5Mhp4F7fVC9KOhXOA61c8LI 5M1fT83u+Cz5KDLjjgPPC2MxT0eZ57z/s1nd2qgeiicJiLpjN4y6SizsIUPdr1iYhbXPXz NHrNiqmfj4gxSCegjA1ddPKwolX7mGk5N7H16Uk9e9Jt6TiD1vJEYmGStvg4nAZtt1nKSx Fg8bAfmh//zUSMjNEOqvZdfl5wFuVOaIhJih5zeS+OwJK0MU89H8dB1u+0Gqtw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697245728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3MVaPc64WWnfjZ2S6W33abKNAGC+3YUoX5x+vLoxSAc=; b=gkrjR9pIKy/gr7eSzyaLp0vOPdW2he+CsFi0t9VE3XDUKx6QRGxmaGAfjuFCHjr5jpf80v JQBrnZlQOyeZI+zWN/ZR4PPghf5cfQG8M5bcTAup6vQU245rqFkLYhmnEvewc4k4QVJdD1 P6YOzoTW/edSnvBsAYsX3RRqHbFeL0iUH6WtmaC2kNmuE34WiNn4PGkcDfXWBl4EeOLLaN S2TchBTdkjy6wBLydGH7GKvE9Ih/+77haqoY0HuBicqIQK1GsVFeX+nEqaR+394aRZRqec uz7LpRDe7iFB7ICDm5G5cxk4T03LI5/QYilJeXuQdt/6pfXeNs1phNacekuRwg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4S6lcw1f51z19BW; Sat, 14 Oct 2023 01:08:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39E18m1b052192; Sat, 14 Oct 2023 01:08:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39E18mql052189; Sat, 14 Oct 2023 01:08:48 GMT (envelope-from git) Date: Sat, 14 Oct 2023 01:08:48 GMT Message-Id: <202310140108.39E18mql052189@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 4404bad2cd1f - releng/14.0 - vfs cache: plug a hypothetical corner case when freeing List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.0 X-Git-Reftype: branch X-Git-Commit: 4404bad2cd1f179fe384883bd9286d5953327343 Auto-Submitted: auto-generated The branch releng/14.0 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=4404bad2cd1f179fe384883bd9286d5953327343 commit 4404bad2cd1f179fe384883bd9286d5953327343 Author: Mateusz Guzik AuthorDate: 2023-09-23 02:04:06 +0000 Commit: Mateusz Guzik CommitDate: 2023-10-14 01:06:38 +0000 vfs cache: plug a hypothetical corner case when freeing cache_zap_unlocked_bucket is called with a bunch of addresses and without any locks held, forcing it to revalidate everything from scratch. It did not account for a case where the entry is reallocated with everything the same except for the target vnode. Should the target use a different lock than the one expected, freeing would proceed without being properly synchronized. Note this is almost impossible to happen in practice. (cherry picked from commit 0f15054f7990f9c772bea34778a8838aa05ebed8) (cherry picked from commit b206bfb92c1f522c85ef1db44d42431e6c0d9334) Approved by: re (gjb) --- sys/kern/vfs_cache.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index d6ff7af97435..0467619fe5d5 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -1645,6 +1645,7 @@ cache_zap_unlocked_bucket(struct namecache *ncp, struct componentname *cnp, struct mtx *blp) { struct namecache *rncp; + struct mtx *rvlp; cache_assert_bucket_unlocked(ncp); @@ -1657,14 +1658,24 @@ cache_zap_unlocked_bucket(struct namecache *ncp, struct componentname *cnp, !bcmp(rncp->nc_name, cnp->cn_nameptr, rncp->nc_nlen)) break; } - if (rncp != NULL) { - cache_zap_locked(rncp); - mtx_unlock(blp); - cache_unlock_vnodes(dvlp, vlp); - atomic_add_long(&zap_bucket_relock_success, 1); - return (0); - } + if (rncp == NULL) + goto out_mismatch; + + if (!(ncp->nc_flag & NCF_NEGATIVE)) + rvlp = VP2VNODELOCK(rncp->nc_vp); + else + rvlp = NULL; + if (rvlp != vlp) + goto out_mismatch; + + cache_zap_locked(rncp); + mtx_unlock(blp); + cache_unlock_vnodes(dvlp, vlp); + atomic_add_long(&zap_bucket_relock_success, 1); + return (0); + +out_mismatch: mtx_unlock(blp); cache_unlock_vnodes(dvlp, vlp); return (EAGAIN);