From nobody Fri Dec 12 06:32:56 2025 X-Original-To: dev-commits-src-main@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 4dSKQK1pvPz6KP8Q for ; Fri, 12 Dec 2025 06:32:57 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dSKQJ3xldz3ZV3 for ; Fri, 12 Dec 2025 06:32:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765521176; 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=A8inPCT4m705Fg6illFUTSbh2Pa/7uRyXTIz3+PWrnQ=; b=DLpSwf7IFTkLhj/99uJanyZYbl62u+M4hqAF/G+zJbv8lGw4/LMI6Xs3QlDlUzdS1yNEDq r0WhDMm+7MBDfot1b+5sfgB9ERb0A5aPoIDOWRdEUA8sUciFs5m+lYJEym5zqPc6F/vkFx 2RjZ2MZUdundCTKurK2uyZqRFgYu90HJTMeeIfx2XqfZcL5+XvDYNmJRRNfUlrOTsFdh9t GnJA7W5VowUL2hBwJUMF4VoKh6gGaqv/KNZGeaaZeXfoLuXde+xhxccFxTzyBb0ipH5zdR F0GlFt7NxY22pPDh96oYXECaS0uAOLziQPkO/VNREkes1smVcKRgwEhN+V/Llg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765521176; 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=A8inPCT4m705Fg6illFUTSbh2Pa/7uRyXTIz3+PWrnQ=; b=YlyJ/kGSKebV0Y7sxsgaACTdZU0JJDX9YoUyN/AvPEoVV443m/UWBClH+0ZYawBaswa3ng 30BGFN40BG4XMDtF7s7plR9Y3DkPVMFHy1uKX8vclJwnF4HNa8ryiMZDdxLeKQ4YksQ54q c4XHFIao+5Co90s9WPLlB12YMAg0NG4SXGqjDx5nGrfKPHAfcF6sTXfKhEPk9CF6hGld5T pgAXZCUYgMhy6oLimPPNirUTWtaFM9WczHDBEExZUwFn6MTscnNUKnPTXWYkrz6A+xHPj2 U8vNAzU3RWhxDyHmwbRug4tkx9JI2kRvMDYs4c+AxxUaUoF27eyD6ktibLizWQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765521176; a=rsa-sha256; cv=none; b=ZjFD2jhHB7Y9bQgrkKc9USxmQSmDIt05hzNwGhe4+0/xgOgFmQTnYfd8jt1djY/1veXd7Z gt4qMtdmCtUNWuKig7sPPgM1HD0EgUtY8+LVE9SRw52Be2IzYRplX/iZW8bQbiznMSqJf9 qci9nD+jg004yzHgT/wNbxXWM55950asEdnIKO1pn4luK7vPN8pAqNjGC+juAtQw92dBac zf3sOsEDpk0PXtuMZiCwsZgJ/P2NYsY/coZd3mysyeQBsVnlfCWAyyXMTVRJDnXK1ZfXJS 1hcIXgOUVG1iIvSy3QgjT/tJ/nY3ABFE6ujlxC5dfR0YuiMib6+Uvor2UHM+Aw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dSKQJ3VcPz15d0 for ; Fri, 12 Dec 2025 06:32:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 24577 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 12 Dec 2025 06:32:56 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jason A. Harmening Subject: git: 0247b4018de2 - main - unionfs: detect common deadlock-producing mount misconfigurations List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jah X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0247b4018de2c341ac59a585362c10044cea86ad Auto-Submitted: auto-generated Date: Fri, 12 Dec 2025 06:32:56 +0000 Message-Id: <693bb718.24577.5dcb7e3d@gitrepo.freebsd.org> The branch main has been updated by jah: URL: https://cgit.FreeBSD.org/src/commit/?id=0247b4018de2c341ac59a585362c10044cea86ad commit 0247b4018de2c341ac59a585362c10044cea86ad Author: Jason A. Harmening AuthorDate: 2025-11-29 07:53:16 +0000 Commit: Jason A. Harmening CommitDate: 2025-12-12 06:32:05 +0000 unionfs: detect common deadlock-producing mount misconfigurations When creating a unionfs mount, it's fairly easy to shoot oneself in the foot by specifying upper and lower file hierarchies that resolve back to the same vnodes. This is fairly easy to do if the sameness is not obvious due to aliasing through nullfs or other unionfs mounts (as in the associated PR), and will produce either deadlock or failed locking assertions on any attempt to use the resulting unionfs mount. Leverage VOP_GETLOWVNODE() to detect the most common cases of foot-shooting at mount time and fail the mount with EDEADLK. This is not meant to be an exhaustive check for all possible deadlock-producing scenarios, but it is an extremely cheap and simple approach that, unlike previous proposed fixes, also works in the presence of nullfs aliases. PR: 172334 Reported by: ngie, Karlo Miličević Reviewed by: kib, olce Tested by: pho MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D53988 --- sys/fs/unionfs/union_vfsops.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/sys/fs/unionfs/union_vfsops.c b/sys/fs/unionfs/union_vfsops.c index 284b24a604f4..3eb67221ec0e 100644 --- a/sys/fs/unionfs/union_vfsops.c +++ b/sys/fs/unionfs/union_vfsops.c @@ -73,6 +73,8 @@ unionfs_domount(struct mount *mp) { struct vnode *lowerrootvp; struct vnode *upperrootvp; + struct vnode *lvp1; + struct vnode *lvp2; struct unionfs_mount *ump; char *target; char *tmp; @@ -276,11 +278,32 @@ unionfs_domount(struct mount *mp) */ VOP_UNLOCK(ump->um_uppervp); + /* + * Detect common cases in which constructing a unionfs hierarchy + * would produce deadlock (or failed locking assertions) upon + * use of the resulting unionfs vnodes. This typically happens + * when the requested upper and lower filesytems (which themselves + * may be unionfs instances and/or nullfs aliases) end up resolving + * to the same base-layer files. Note that this is not meant to be + * an exhaustive check of all possible deadlock-producing scenarios. + */ + lvp1 = lvp2 = NULL; + VOP_GETLOWVNODE(ump->um_lowervp, &lvp1, FREAD); + VOP_GETLOWVNODE(ump->um_uppervp, &lvp2, FREAD); + if (lvp1 != NULL && lvp1 == lvp2) + error = EDEADLK; + if (lvp1 != NULL) + vrele(lvp1); + if (lvp2 != NULL) + vrele(lvp2); + /* * Get the unionfs root vnode. */ - error = unionfs_nodeget(mp, ump->um_uppervp, ump->um_lowervp, - NULL, &(ump->um_rootvp), NULL); + if (error == 0) { + error = unionfs_nodeget(mp, ump->um_uppervp, ump->um_lowervp, + NULL, &(ump->um_rootvp), NULL); + } if (error != 0) { vrele(upperrootvp); free(ump, M_UNIONFSMNT);