Skip to content

chmod -R: "cannot access … Permission denied" for files below the operand that the user doesn't own #15934

Closed

Description

@eylulseyit

With chmod -R, files below the operand get an EACCES-style error even when the real error is EPERM. The file is accessible; the user just isn't allowed to change its mode. uutils reports it as if it couldn't be accessed.

The operand itself is reported correctly; only entries found while recursing are wrong.

# as a normal user; /etc/skel and its files are owned by root
LC_ALL=C chmod -R -v u+w /etc/skel

uutils:

failed to change mode of file '/etc/skel' from 0755 (rwxr-xr-x) to 0755 (rwxr-xr-x)
chmod: changing permissions of '/etc/skel': Operation not permitted
failed to change mode of '/etc/skel/.bashrc' to 644
chmod: cannot access '/etc/skel/.bashrc': Permission denied

GNU 9.10:

chmod: changing permissions of '/etc/skel': Operation not permitted
failed to change mode of '/etc/skel' from 0755 (rwxr-xr-x) to 0755 (rwxr-xr-x)
chmod: changing permissions of '/etc/skel/.bashrc': Operation not permitted
failed to change mode of '/etc/skel/.bashrc' from 0644 (rw-r--r--) to 0644 (rw-r--r--)

The -v line below the operand is also different: it leaves out the old mode and the symbolic form. And uutils prints the -v line before the error, while GNU prints it after; this one affects the operand too.

Where: safe_chmod_file() in src/uu/chmod/src/chmod.rs keeps the real error only for ReadOnlyFilesystem (#12200) and turns every other error into PermissionDenied. The operand goes through change_file(), which always reports the real error.

uutils main c21b7ad, GNU coreutils 9.10, Fedora (Linux x86_64).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions