From nobody Fri Jan 06 09:46:34 2023 X-Original-To: dev-commits-src-branches@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 4NpJQ262dLz2pD7T; Fri, 6 Jan 2023 09:46: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 4NpJQ24HQLz3wLH; Fri, 6 Jan 2023 09:46:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1672998394; 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=E9C+79ucKG1GuTNJFcEXl2Z7OGn4rcIj5eJE2C6nCDI=; b=kXYwDO5nGPEysWlJvldP6Bbbns/GdKvQZHWdxfA72jmhfUwlNmgmbdtrTc7YujJely8Sss 3HyMOiFgwpzHAtg8kA2bC1Z6TxuOK8NwDkMkIbUIsrU8Vol5Ev+BAY/tQTksb0sqHw+ee7 gV8VmZFRzU+I1mdEjjTIjZuKp7t/DLU+QpyN/3WmSXDZN5Qxf8Zdq+uT6NAwr0G5n5IV+n M8Fn1g6cZu2v5T5fMhdYfvmUfjjYyfzTt2wiELGHdFkEVDTGJAlZH7QsH1B6RF47S29Kif V2w7c1jpICYaEnKFQfqRlZN4dNEkyOqCZ+tefn+oj+FoGGduUAJau+CNVZibyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1672998394; 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=E9C+79ucKG1GuTNJFcEXl2Z7OGn4rcIj5eJE2C6nCDI=; b=a6QW1f6hfzjfXBmxSj6FuJTaaWMmnh0BICkO8uE+4IjxmE3rCLQhiMQV9ApF+qlpi+x2yv 8FoPNbcDXR4iKgF+V0NCfggVkc0q7Vi9u99EcBjTfq9rTlRsCH/pxp7MfSz5ZUh9R9TaQf n11EmcC9YO3mquLSpVAmiCgs3ZAJa/zPb49FXLQ9UZzBewhe9piKfbbiJzhpKUXoug+mrJ TR1Fe4buEbE5us4Pqd/t4Bvg6gJuU5UhERTEMrVOpe32lYhcOQRFDB1Cl3ZrdsXttC4y+0 uoljnOiYJ0m/NJY6gOjWbrU0OqaEcvHw8CrvmO6pjn6lX7CgnbGtogIMorfbNg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1672998394; a=rsa-sha256; cv=none; b=XFioL5nwTymbFyZYUNOvJkT6NqPt5IsUt+ZdRjenPwmqVqT+pmPJWRDqoV8zDyHyZJOzx+ MVCefjrqujCquyTofqDXxxO9EyWxs49E9Xbvt6yMZy/X1P/wVBPZQi0ccuGEwmeO53i9cU rldz1073P8qNHQ6eQJaPkm/g0tT8iPHTtO8MuASrx/VTQuPorC6PPrQ8A35P81JMB+kHsd RmmU3HtM5Xe9IYrL0ZVn9pG3X4gqbmlPjXrXBuVmFaHxk5MaJL3dzWi0+VjL9WiNnpXLgd zkBohj4qZI+M61KRvc0M2ZM2jxmxJ9FVY6nUZBrAY8ouGjPHBQDiQKkxtEwXdA== 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 4NpJQ23P7wzQms; Fri, 6 Jan 2023 09:46: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 3069kYeA090486; Fri, 6 Jan 2023 09:46:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 3069kYJA090485; Fri, 6 Jan 2023 09:46:34 GMT (envelope-from git) Date: Fri, 6 Jan 2023 09:46:34 GMT Message-Id: <202301060946.3069kYJA090485@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Doug Rabson Subject: git: 9d9a2ccb9761 - stable/13 - Allow realpath to work for file mounts List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 9d9a2ccb976157dfbf1bc9d18ec3c522e0fb65f5 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dfr: URL: https://cgit.FreeBSD.org/src/commit/?id=9d9a2ccb976157dfbf1bc9d18ec3c522e0fb65f5 commit 9d9a2ccb976157dfbf1bc9d18ec3c522e0fb65f5 Author: Doug Rabson AuthorDate: 2022-12-04 15:53:07 +0000 Commit: Doug Rabson CommitDate: 2023-01-06 07:57:57 +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 (cherry picked from commit a1d74b2dab78d56582126b4944b435d00747f601) --- 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 b422b30da3e2..e87f4a6cda1a 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -3133,12 +3133,36 @@ kern___realpathat(struct thread *td, int fd, const char *path, char *buf, pathseg, path, fd, &cap_fstat_rights, td); 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: NDFREE(&nd, 0); return (error); } diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 038ace288729..e6bb6036a5a0 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -965,6 +965,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;