Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aidanharris opened this issue Sep 8, 2024 · 2 comments

Comments

@aidanharris
Copy link

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

@samueltardieu
Copy link
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?

@zgzhong
Copy link

zgzhong commented Nov 24, 2024

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
Projects
None yet
Development

No branches or pull requests

4 participants