Skip to content

readlink: Behaviour differs from GNU Coreutils when path exists but cannot be read #6688

Open

Description

@aidanharris

Running as a non-root user that does not have permission to read /proc/1/exe (since the init process is started as root):

Expected:

$ readlink -f /proc/1/exe /etc/hosts
/etc/hosts

Actual:

$ readlink -f /proc/1/exe /etc/hosts
/proc/1/exe
/etc/hosts

We do see the error raised correctly when Uutils doesn't canonicalize the path:

$ readlink -v /proc/1/exe /etc/hosts
readlink: /proc/1/exe: Permission denied

But it's returning early instead of processing the rest of the files:

GNU Coreutils

$ readlink -v -e /proc/1/exe /etc/hosts
readlink: /proc/1/exe: Permission denied
/etc/hosts

Running

Activity

  1. samueltardieu commented on Sep 14, 2024

    @samueltardieu
    Contributor

    I wonder whether GNU readlink -f /proc/1/exe /etc/hosts displaying only /etc/hosts is right. The description for -f on https://www.gnu.org/software/coreutils/manual/html_node/readlink-invocation.html#readlink-invocation is:

    Activate canonicalize mode. If any component of the file name except the last one is missing or unavailable, readlink produces no output and exits with a nonzero exit code. A trailing slash is ignored.

    Aren't all the components of the file name /proc/1/exe except the last one present and available?

  2. zgzhong commented on Nov 24, 2024

    @zgzhong

    Aren't all the components of the file name /proc/1/exe except the last one present and available?

    @samueltardieu Yes, I tried to show /proc and proc/1 on my machine, both permission of /proc and /proc/1 are 555.

    $ ls -ld /proc 
    dr-xr-xr-x 200 root root 0 Nov 24 13:40 /proc
    $ ls -ld /proc/1
    dr-xr-xr-x 9 root root 0 Nov 24 13:40 /proc/1
    

    Even though I tried to read a non-exist file along with /etc/hosts, GNU readlink also only displaying /etc/hosts.

    $ readlink -f /tmp/not_exist/file /etc/hostname
    /etc/hostname
    

    I think that GNU won't exit immediately when it encounter an error on processing the filename. Instead, it will try to process the next filename. Finally, GNU may exit with nonzero code if any of the previous processing is failed.

    If you think my idea is correct, I think I can help you fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions