From nobody Mon Dec 19 16:50:34 2022 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 4NbQgZ3S13z1GB1X; Mon, 19 Dec 2022 16:50:34 +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 4NbQgZ32Rfz3ht8; Mon, 19 Dec 2022 16:50:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671468634; 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=Q3gOMR7ULV0CFs8X23zGkTePua/fjP5tBjiBc5VkZQU=; b=BT9j1DP/ZtdkwAaZm0Rh8Gszy+dNAz/5nv0nSVWfUpBE486swWjUkn5Zk71F3jF61xDeJn mrL/niKMkJvD3Q/XVCuxi1Y53aU1315awdc+/PmLh/gxsP1Hto1pEj39gXfPk1dvC2K1/v 0Cd2gbuy/85yBi7Nw1U70f3ZbrglHV6eZyMTRV5TKBlTxL4rgqp/OSlTtyWnhbiu5u/Hmc sE9yDQISfveg+mskr2Y0eAWEV60OqK3F14P1Q2FhIk0ybdoqGILcLsbUbqSxWGzgXcOJa6 n8ualqDb2YxxnGMtWObxw2npQ7N7UnbudsNQhumIns0R/IZINXeriJe1LcOWDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671468634; 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=Q3gOMR7ULV0CFs8X23zGkTePua/fjP5tBjiBc5VkZQU=; b=svaLKfqOiKGQ7UtHtOA2ofiNHepWf0M+kozB5sXPBzqhLik1aHpjBrmoG6od03KGPVn4tQ 6zQwcLUMQKYhWwHs0KgPkibxMMM98GtbtcUEe2zBviq+6DBq5622UKsMi1vccRUt6wH85k HSoyeP4pUPslnK7voOPknmFNDLBZYQceiOsr0H2e4oOX0fBZPlppwXEsko6UchfamIDshk arYj0ufwmBa94pkREzivE8ccelg7uKZhhggeYDnB2tFVoeiNwf7+9ajy3hC30VScEWITVk P1LnjbnjxCr4tiKJmZbe3mfxtl9CtI92lGs8aVz64nljzYj+140BC6yTVG7uEA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1671468634; a=rsa-sha256; cv=none; b=ZDiNkmHkmZM2TwbUREysA8tseGII8bL/StzmfRtMom3Ri1pZNjCcQxK326jjMiDevQ/OWL atotqtfLSClq+W4TQ4y387Z5ExKNhQzJisoxOdcOQRpOjOg40WlXZDaXmV0zSoK80N8m9D /FeCFLJl261yLwRMdbuzuATfMUNdVIbkUIwT0gMs6n2UJ7vyOzUqGfGT48cYJiS3NumNYs l9WIa7Ex86wCngkjgGVzs4/76XhwLFr7ynpkmFbWxrI+GoFBeZlYZVmDlAEoaf9Fqj8WyV mPIzpKJa8PyxOoWz41WytCqxkDz5wAcnPfi0uULiyaDFQwRD9NdBaBDpTj0N2Q== 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 4NbQgZ1sJhz12r1; Mon, 19 Dec 2022 16:50:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2BJGoYrb094542; Mon, 19 Dec 2022 16:50:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BJGoY0Q094541; Mon, 19 Dec 2022 16:50:34 GMT (envelope-from git) Date: Mon, 19 Dec 2022 16:50:34 GMT Message-Id: <202212191650.2BJGoY0Q094541@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Rabson Subject: git: a1d74b2dab78 - main - Allow realpath to work for file mounts 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: dfr X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a1d74b2dab78d56582126b4944b435d00747f601 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dfr: URL: https://cgit.FreeBSD.org/src/commit/?id=a1d74b2dab78d56582126b4944b435d00747f601 commit a1d74b2dab78d56582126b4944b435d00747f601 Author: Doug Rabson AuthorDate: 2022-12-04 15:53:07 +0000 Commit: Doug Rabson CommitDate: 2022-12-19 16:46:27 +0000 Allow realpath to work for file mounts For file mounts, the directory vnode is not available from namei and this prevents the use of vn_fullpath_hardlink. In this case, we can use the vnode which was covered by the file mount with vn_fullpath. This also disallows file mounts over files with link counts greater than one to ensure a deterministic path to the mount point. Reviewed by: mjg, kib Tested by: pho --- sys/kern/vfs_cache.c | 28 ++++++++++++++++++++++++++-- sys/kern/vfs_mount.c | 5 +++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index f2dd8328278d..47065cf85bb5 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -3147,12 +3147,36 @@ kern___realpathat(struct thread *td, int fd, const char *path, char *buf, pathseg, path, fd, &cap_fstat_rights); if ((error = namei(&nd)) != 0) return (error); - error = vn_fullpath_hardlink(nd.ni_vp, nd.ni_dvp, nd.ni_cnd.cn_nameptr, - nd.ni_cnd.cn_namelen, &retbuf, &freebuf, &size); + + if (nd.ni_vp->v_type == VREG && nd.ni_dvp->v_type != VDIR && + (nd.ni_vp->v_vflag & VV_ROOT) != 0) { + /* + * This happens if vp is a file mount. The call to + * vn_fullpath_hardlink can panic if path resolution can't be + * handled without the directory. + * + * To resolve this, we find the vnode which was mounted on - + * this should have a unique global path since we disallow + * mounting on linked files. + */ + struct vnode *covered_vp; + error = vn_lock(nd.ni_vp, LK_SHARED); + if (error != 0) + goto out; + covered_vp = nd.ni_vp->v_mount->mnt_vnodecovered; + vref(covered_vp); + VOP_UNLOCK(nd.ni_vp); + error = vn_fullpath(covered_vp, &retbuf, &freebuf); + vrele(covered_vp); + } else { + error = vn_fullpath_hardlink(nd.ni_vp, nd.ni_dvp, nd.ni_cnd.cn_nameptr, + nd.ni_cnd.cn_namelen, &retbuf, &freebuf, &size); + } if (error == 0) { error = copyout(retbuf, buf, size); free(freebuf, M_TEMP); } +out: vrele(nd.ni_vp); vrele(nd.ni_dvp); NDFREE_PNBUF(&nd); diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 8001604d2855..8de9d3c4fff8 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -1108,6 +1108,11 @@ vfs_domount_first( if (vfsp->vfc_flags & VFCF_FILEMOUNT) { if (error == 0 && vp->v_type != VDIR && vp->v_type != VREG) error = EINVAL; + /* + * For file mounts, ensure that there is only one hardlink to the file. + */ + if (error == 0 && vp->v_type == VREG && va.va_nlink != 1) + error = EINVAL; } else { if (error == 0 && vp->v_type != VDIR) error = ENOTDIR;