Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Nov 2023 06:19:57 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 275099] cat(1) can't read directories
Message-ID:  <bug-275099-227@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D275099

            Bug ID: 275099
           Summary: cat(1) can't read directories
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: msl0000023508@gmail.com
 Attachment #246324 text/plain
         mime type:

Created attachment 246324
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D246324&action=
=3Dedit
helloworld-dir.c

While it is not common to read(2) a directory directly, this is still suppo=
rted
in FreeBSD (with security.bsd.allow_read_dir=3D1); and it could be actually
useful in FUSE as an user space file system implementation may provide some
data in a directory itself.

The followings demonstrate the issue with a FUSE-based file system:


# sysctl security.bsd.allow_read_dir=3D1
security.bsd.allow_read_dir: 0 -> 1
# helloworld-dir /mnt/3/
# ls -al /mnt/3/
total 0
drwxr-xr-x  2 root wheel 27 Jan  1  1970 .
drwxr-xr-x  2 root wheel 13 Jan  1  1970 hello
# ls -al /mnt/3/hello/
total 0
drwxr-xr-x  2 root wheel 13 Jan  1  1970 .
drwxr-xr-x  2 root wheel 27 Jan  1  1970 ..
-rw-r--r--  1 root wheel 12 Jan  1  1970 world
# cat /mnt/3/hello/world=20
Hello world
# cat /mnt/3/hello
cat: stdout: Is a directory
# dd status=3Dnone if=3D/mnt/3/hello
Hello world!
# cat /mnt/3/
cat: stdout: Is a directory
# dd status=3Dnone if=3D/mnt/3/
This is the root directory
# umount /mnt/3/


It shows that cat(1) failed to read the directories but dd(1) works without
problem.

The cause is that cat(1) tries to use copy_file_range(2) to copy input file=
 to
stdout but this system call dosen't work on directories as documented, and
cat(1) didn't fallback to read(2) and write(2) on copy_file_range(2) fail w=
ith
EISDIR.

The FUSE program for demonstration is attached.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-275099-227>