WSL icon indicating copy to clipboard operation
WSL copied to clipboard

Some <Junction>s handled by WSL/devfs, some NOT

Open jamesdavidhoward opened this issue 7 years ago • 2 comments

<Junction>s seen as similar by CMD.EXE "dir /a", can be handled differently by WSL/devfs. For example: 1.) In Windows CMD.EXE shell do:

cd %HOMEDRIVE%%HOMEPATH% dir /a ... above identifies dir entries that are JUNCTIONS, SYMLINKD or SYMLINK (file) 2.) Choose one: "Recent" dir /a | find "Recent" ... <JUNCTION> Recent [C:\Users\jhowa\AppData\Roaming\Microsoft\Windows\Recent] 3.) What does bash say? $ cd /mnt/C/Users/jhowa # Equiv location, as seen thru drvfs $ ls -l Recent ls: cannot read symbolic link 'Recent': Permission denied lrwxrwxrwx 1 jdhoward jdhoward 59 Sep 22 19:41 Recent 4.) Delete and re-make <JUNCTION> (within CMD.EXE) rmdir Recent mklink /J /D Recent ".\AppData\Roaming\Microsoft\Windows\Recent" 5.) Verify present & usable dir /a | find "Recent" ... <JUNCTION> Recent [C:\Users\jhowa\AppData\Roaming\Microsoft\Windows\Recent] REM Interesting: relative pathname has become an absolute path? dir Recent ... long listing of content of ### ### %APPDATA%\Microsoft\Windows\Recent REM Recreated JUNCTION working (in Windows / NTFS / CMD.EXE 6.) It is NOW different when viewed by WSL/bash/drvfs $ sync # Just in case? $ ls -l Recent ... ... ... Recent -> /mnt/c/Users/jhowa/AppData/Roaming/Microsoft/Windows/Recent $ ls Recent ... long listing of content of %APPDATA%\Microsoft\Windows\Recent

Why the difference?

Please fill out the below information:

  • Your Windows build number: [Version 10.0.17763.292]
  • What you're doing and what's happening: see sequence above
  • What's wrong / what should be happening instead: Wrong: 2 directory entries identified by Windows/NTFS/CMD.EXE as s are interpreted differently by WSL/drvfs/bash Expected: Any should be interpreted the same by WSL/drvfs/bash

jamesdavidhoward avatar Feb 01 '19 22:02 jamesdavidhoward

This probably has to do with the fact that those junctions have special ACLs which try to prevent people from using them (also, they are hidden+system for the same reason), while still allowing access to files inside those "folders" to be transparently accessible.

These are the ACLs of Recent:

Z:\>icacls Recent
Recent Everyone:(DENY)(S,RD)
       NT-AUTHORITY\SYSTEM:(I)(OI)(CI)(F)
       BUILTIN\Administrators:(I)(OI)(CI)(F)
       CHE-X1\david:(I)(OI)(CI)(F)

What stands out is that RD (ReadData) is explicitely denied to Everyone.

...while these are the ACLs of a test junction I manually created:

Z:\>icacls testjnc
testjnc NT-AUTHORITY\SYSTEM:(OI)(CI)(F)
        BUILTIN\Administrators:(OI)(CI)(F)
        CHE-X1\david:(OI)(CI)(F)

Probably, the way WSL accesses it causes the action to be denied.

When you look at how cmd.exe accesses the junction point, you see this:

image

This is ls in comparison:

image

Looking at this from Linux-land:

lstat("Recent", {st_mode=S_IFLNK|0777, st_size=59, ...}) = 0
lgetxattr("Recent", "security.selinux", 0x74f1f0, 255) = -1 ENODATA (No data available)
readlink("Recent", 0x74f1f0, 60)        = -1 EACCES (Permission denied)

It seems that the WSL implementation of the readlink syscall does not handle this case correctly and fails on an access denied error in the attempt to read some data about the directory entry even though the target value of the reparse point was already read at that point.

CherryDT avatar Feb 02 '19 21:02 CherryDT

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!