X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FA193858418
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1638785827;
	bh=cAxvJvYaZsFvrRwyInoNvXXfxWWa+AJn8EzZDa7upEo=;
	h=Date:From:To:Subject:References:In-Reply-To:List-Id:
	 List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe:
	 Reply-To:From;
	b=XcQo7ihp/yMaWefuYVOdO4ufRoba8vGO3f2bYbiOJFh4Pvlz4HDBvw5LdKylMlBJH
	 H3mBLNcNZC85TlPYnFBtNkfJi0mQVQT1TBJoXJ2OL4OYJzrICBuPUjN7mkQ0I7pqUd
	 Ub/limyUpXsvz8QFtPchuu41x60+oZ6BQuZBOwNk=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 350053858D28
Authentication-Results: sourceware.org;
 dmarc=fail (p=none dis=none) header.from=cygwin.com
Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=cygwin.com
Date: Mon, 6 Dec 2021 11:16:30 +0100
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: vboxsharedfs - Too many levels of symbolic links
Message-ID: <Ya3i/sfWB2avaJ9F@calimero.vinschen.de>
Mail-Followup-To: cygwin@cygwin.com
References: <d6470ffe-8e49-3eb7-4d21-3212e0ad4f31@oskog97.com>
 <20211205115411.1619911cb3e2d23f671912ce@nifty.ne.jp>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <20211205115411.1619911cb3e2d23f671912ce@nifty.ne.jp>
X-Provags-ID: V03:K1:j/2JTFUeSbhPn4FFdnwU7Pwz4KQ1MohyXptbD/iAq7+iBWim+iE
 neUd8kdJgIAL+Mis3KEqkW9GuX99bvtwBq8G62vPm+3FeOdHPNi2zM12eX3CQOS15TDozUX
 zstmvH+ug4qbd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PF_HELO_NONE, SPF_NEUTRAL,
 TXREP autolearn=ham autolearn_force=no version=3.4.4
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
Reply-To: cygwin@cygwin.com
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces+archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

On Dec  5 11:54, Takashi Yano wrote:
> On Tue, 30 Nov 2021 19:04:57 +0200
> Oskar Skog wrote:
> > vboxsharedfs file systems no longer work. Any attempt to access will
> > result in "too many levels of symbolic links".
> > 
> > This only affects the VirtualBox shared folder, the Samba share works
> > just fine.
> > 
> > Last time I updated (before today) was sometime before the 10th of
> > September.
> > 
> > MSYS2 has the same problem, but no one seems to have reported it to
> > Cygwin:
> > https://github.com/msys2/msys2-runtime/issues/58
> > 
> > 
> > user@DESKTOP-******* ~$ ls /cygdrive/z
> > ls: cannot access '/cygdrive/z': Too many levels of symbolic links
> > user@DESKTOP-******* ~$ mount
> > C:/Cygwin/bin on /usr/bin type ntfs (binary,auto)
> > C:/Cygwin/lib on /usr/lib type ntfs (binary,auto)
> > C:/Cygwin on / type ntfs (binary,auto)
> > C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)
> > D: on /cygdrive/d type iso9660 (binary,posix=0,user,noumount,auto)
> > Y: on /cygdrive/y type smbfs (binary,posix=0,user,noumount,auto)
> > Z: on /cygdrive/z type vboxsharedfolderfs 
> > (binary,posix=0,user,noumount,auto)
> > user@DESKTOP-******* ~$ uname -a
> > CYGWIN_NT-10.0 DESKTOP-* 3.3.2(0.341/5/3) 2021-11-08 16:55 x86_64 Cygwin
> 
> Thanks for the report.
> It seems that this happens only in 64bit Windoes10/11.
> [...]
> I tested with VirtualBox version 6.1.30.

Thanks for testing, Takashi!

> In 64bit Windows10, for vbox shared path, GetFinalPathNameByHandleW()
> returns path with trailing '\'. As a result, RtlEqualUnicodeString()
> fails and tries to resolve symlink repeatedly.

That sounds like a bug in VirtualBox, but yeah, we should workaround it.

> For example, RtlEqualUnicodeString() compares \??\UNC\VBoxSrv\tmp and
> \??\UNC\VBoxSrv\tmp\, then it fails.
> [...]
> +	      if (wcsstr (fpbuf, L"\\\\?\\UNC\\") == fpbuf)
> +		goto file_not_symlink;
> +

Isn't that a bit intrusive?  Wouldn't it also fix the issue if we
just overwrite a trailing '\\' with '\0', like this?

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index baf04ce89a08..b76e5b0466cf 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -3492,8 +3492,14 @@ restart:
 	    {
 	      UNICODE_STRING fpath;
 
-	      RtlInitCountedUnicodeString (&fpath, fpbuf, ret * sizeof (WCHAR));
+	      /* If incoming path has no trailing backslash, but final path
+	         has one, drop trailing backslash from final path so the
+		 below string comparison has a chance to succeed. */
+	      if (upath.Buffer[(upath.Length - 1) / sizeof (WCHAR)] != L'\\'
+		  && fpbuf[ret - 1] == L'\\')
+		fpbuf[--ret] = L'\0';
 	      fpbuf[1] = L'?';	/* \\?\ --> \??\ */
+	      RtlInitCountedUnicodeString (&fpath, fpbuf, ret * sizeof (WCHAR));
 	      if (!RtlEqualUnicodeString (&upath, &fpath, !!ci_flag))
 	        {
 		  issymlink = true;


Thanks,
Corinna

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
