Public bug reported:

On Linux, when chown is invoked on a directory without --recursive (-R),
and the internal open() of that directory fails (e.g. due to a
permission error), the command exits with status 0 and prints no error.

Expected behaviour:
chown should exit with a non-zero status and print an error message when it 
cannot open the target directory.

Steps to reproduce:

root@ace-12:~# mkdir /tmp/testdir
root@ace-12:~# chmod 600 /tmp/testdir
root@ace-12:~# stat /tmp/testdir
  File: /tmp/testdir
  size: 40              Blocks: 0          IO Block: 4096   directory
Device: 0,45    Inode: 747132      Links: 2
Access: (0600/drw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2026-10-05 23:48:08.227391341 +0200
Modify: 2026-10-05 23:46:42.211882716 +0200
Change: 2026-10-05 23:48:46.260373821 +0200
 Birth: 2026-10-05 23:48:46.259058378 +0200

root@ace-12:~# su user1
$ id
uid=1003(user1) gid=1003(user1) groups=1003(user1)
$ stat /tmp/testdir
  File: /tmp/testdir
  size: 40              Blocks: 0          IO Block: 4096   directory
Device: 0,45    Inode: 747132      Links: 2
Access: (0600/drw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2026-10-05 23:48:08.227391341 +0200
Modify: 2026-10-05 23:46:42.211882716 +0200
Change: 2026-10-05 23:48:46.260373821 +0200
 Birth: 2026-10-05 23:48:46.259058378 +0200
$ chown user1 /tmp/testdir
$ echo $?
0

With -R provided, the return code is 1 and the error message is output as 
expected.
$ id
uid=1003(user1) gid=1003(user1) groups=1003(user1)
$ chown -R user1 /tmp/testdir
chown: cannot access '/tmp/testdir': Permission denied
$ echo $?
1

Environment info:
root@ace-12:~# chown --version
chown (uutils coreutils) 0.8.0

root@ace-12:~# lsb_release -rd
Description:    Ubuntu 26.04 LTS
Release:        26.04

root@ace-12:~# apt-cache policy coreutils
coreutils:
  Installed: 9.5-1ubuntu2+0.0.0~ubuntu25
  Candidate: 9.5-1ubuntu2+0.0.0~ubuntu25
  Version table:
 *** 9.5-1ubuntu2+0.0.0~ubuntu25 500
        500 http://x86-64.clouds.archive.ubuntu.com/ubuntu resolute/main amd64 
Packages
        500 http://x86-64.clouds.archive.ubuntu.com/ubuntu resolute/main i386 
Packages
        100 /var/lib/dpkg/status

** Affects: rust-coreutils (Ubuntu)
     Importance: Undecided
         Status: New

** Attachment added: "strace output of the erronous chown without the expected 
error message"
   
https://bugs.launchpad.net/bugs/2169640/+attachment/6006053/+files/chown_strace_output.txt

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2169640

Title:
  chown: silent success when open() fails on a directory (Linux, non-
  recursive)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/rust-coreutils/+bug/2169640/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to