WSL: permission denied reading /mnt/c/Users//Cookies

On bash when i try to do the command ls i get the following message:

ls: cannot read symbolic link '<Folder Name>': Permission denied

Im on version 10.0.16299.125

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 49
  • Comments: 29

Most upvoted comments

@therealkenc I get the same issue as @ricardojrgpimentel . The only steps I take are:

  • cd /mnt/c/Users/<my username>
  • ls

This gives me the following output:

ls: cannot read symbolic link 'Application Data': Permission denied
ls: cannot read symbolic link 'Cookies': Permission denied
ls: cannot read symbolic link 'Local Settings': Permission denied
ls: cannot read symbolic link 'My Documents': Permission denied
ls: cannot read symbolic link 'NetHood': Permission denied
ls: cannot read symbolic link 'PrintHood': Permission denied
ls: cannot read symbolic link 'Recent': Permission denied
ls: cannot read symbolic link 'SendTo': Permission denied
ls: cannot read symbolic link 'Start Menu': Permission denied
ls: cannot read symbolic link 'Templates': Permission denied

I am running a fresh install of Windows 10, and Ubuntu is the Linux distro I am using.

The EPERM on those legacy (if that is the word) Windows symlinks such as /User/<username>/Cookies has been addressed in 18980. Works in both WSL1 and WSL2. Very awesome 💯.

image

I am using my windows home folder as my WSL home, I made this ls function for ~/.bashrc if anyone is interested:

ls() {
    ls_opts="-h --color=auto"

    if [ $# -eq 0 ]; then
        if [ "$PWD" = "$HOME" ]; then
            ls_opts="$ls_opts --hide='ntuser.*' --hide='NTUSER.*'"
        fi

        eval command ls "$ls_opts" '"$@"' 2>/dev/null
        return 0
    fi

    eval command ls "$ls_opts" '"$@"'
}

this makes this behavior more pleasant to deal with.

@therealkenc I actually find a way to do that, by alias ls=‘ls 2>/dev/null’. I’m leaving it here in case someone searches for a workaround. Thank you anyway.

It’s worth noting that this bug indirectly breaks Jupyter Notebook when run from a user’s home directory. Documented workarounds can found in the issue thread, but unlike this issue as it manifests with the ls command, it is causing a “hard fail” with Jupyter. Combined with @cwebster2’s comment, this issue is clearly a bug and if Microsoft is serious about WSL, it needs to be fixed.

Provisionally because you do technically have Windows permissions to resolve the link. You get reasonable behavior in Cygwin for example. There is no particular reason why the link shouldn’t resolve in WSL as well. No identity system is “broken” by doing so. And, since this Permission denied error is the first thing people see in cd /mnt/c/Users/<my username>, and that is where folks land by default in Windows Store WSL Ubuntu, the present situation is less than ideal. There are no cases (or common cases that I can think of) in Real Linux where a you’d get a cannot read symbolic link error out of ls. At worst, if you don’t have permission to the followed path, then the pathname is helpfully displayed in red with ls -l --color. That WSL does not behave the same one could argue is a bug/diverge. I haven’t looked at the source, but I suspect that error message comes from a defensive “huh, how’d that happen” error path in ls.

[The “provisionally” caveat is because one can call anything as-designed by fiat. This issue isn’t tagged one way or another.]

image

On ~/.bashrc you can just make an alias for output:

Firstly create the file: touch /var/log/.ls-error In a second time make you privilege on this file : sudo chown $USER:$USER /var/log/.ls-error

In ~/.bashrc:

# ls alias redirect output to /var/log/.ls-error
alias ls='ls $@ 2> /var/log/.ls-error --color=auto'

Alternatively, the permissions for these files should be presented as 000, l--------- to indicate the user has no permission to the file.

I was going to suggest that but I think I lost by train of thought at the time I wrote my post. Thanks for framing the behavioral change request in concrete terms. I think abstracting it further might run into separation of concerns problems. For now it would be enough if WSL didn’t cause ls to crap the bed. Someone will probably open a bug eventually asking why the perms on Cookies is “wrong”, but that’s a bridge that can be crossed another day.

To add to the issue here is an excerpt from strace output from running ls -l My\ Documents:

lstat("My Documents", {st_mode=S_IFLNK|0777, st_size=0, ...}) = 0
lgetxattr("My Documents", "security.selinux", 0x7fffda5797f0, 255) = -1 EOPNOTSUPP (Operation not supported)
readlink("My Documents", 0x7fffda5790b0, 1) = -1 EACCES (Permission denied)

the return value from lstat() is 0, indicating success. ls then looks for selinux attributes and finally calls readlink() , which should resolve the path My Documents is pointing at but instead returns EACCESS indicating “search permission is denied for a component of the path prefix”. The man page path_resolution(7) details how this works.

I believe the behavior here to be incorrect. The readlink() implementation by WSL should be able to resolve the path, then walk it to determine if EACCESS is warranted (e.g. the link truly resolves to somewhere you don’t have access to read), but in the general case where C:\Users\user\My Documents points to C:\Users\user\Documents, there is no access issues walking that path.

The detail that the My Documents is not truly a symbolic link and has underlying dependency on registry keys for resolving its destination is something that should be abstracted away in the readlink call.

Alternatively, the permissions for these files should be presented as 000, l--------- to indicate the user has no permission to the file.

Interesting.

cygwin bash:

$ pwd
/cygdrive/c

$ ls -la Documents\ and\ Settings
lrwxrwxrwx 1 SYSTEM SYSTEM 17 Jul 10  2015 'Documents and Settings' -> /cygdrive/c/Users

Powershell:

PS C:\> pwd

Path
----
C:\


PS C:\> Get-ChildItem  -Attributes Hidden '.\Documents and Settings\' | Format-List
Get-ChildItem : Access to the path 'C:\Documents and Settings' is denied.
At line:1 char:1
+ Get-ChildItem  -Attributes Hidden '.\Documents and Settings\' | Forma ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Documents and Settings\:String) [Get-ChildItem], UnauthorizedAcces
   sException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

I am my normal user self in both cases.

Ever?

image

Just 'sayin.

Practical work-around for now remains redirect 2>/dev/null. Someone motivated might also consider an upstream patch to Ubuntu’s coreutils to make ls(1) more tolerant of ~the bug~ WSL’s alternative filesystem semantics.

You might want this too:

# remove background colors from dircolors
eval "$(dircolors -p | \
    sed 's/ 4[0-9];/ 01;/; s/;4[0-9];/;01;/g; s/;4[0-9] /;01 /' | \
    dircolors /dev/stdin)"

It’s a bug. If its attached to my files system (in my case, a cryptomator mounted folder on the Windows side) and they are in all ways mine, I should be able to list it.