[PATCH 0/3] Fix the O_PATH support for FIFOs

Ken Brown kbrown@cornell.edu
Thu Jan 23 17:13:00 GMT 2020

On 1/23/2020 11:31 AM, Ken Brown wrote:
> Commit aa55d22c, "Cygwin: honor the O_PATH flag when opening a FIFO",
> fixed a hang but otherwise didn't accomplish the purpose of the O_PATH
> flag as stated in the Linux man page for open(2):
>      Obtain a file descriptor that can be used for two purposes: to
>      indicate a location in the filesystem tree and to perform
>      operations that act purely at the file descriptor level.  The
>      file itself is not opened, and other file operations (e.g.,
>      read(2), write(2), fchmod(2), fchown(2), fgetxattr(2),
>      ioctl(2), mmap(2)) fail with the error EBADF.
>      [The man page goes on to describe operations that *can* be
>      performed: close(2), fchdir(2), fstat(2),....]
>      Opening a file or directory with the O_PATH flag requires no
>      permissions on the object itself (but does require execute
>      permission on the directories in the path prefix).
> The first problem in the current implementation is that if open(2) is
> called on a FIFO, fhandler_base::device_access_denied is called and
> tries to open the FIFO with read access, which isn't supposed to be
> required.  This is fixed by the first patch in this series.
> The second patch makes fhandler_fifo::open call fhandler_base::open_fs
> if O_PATH is set, so that we actually obtain a handle that can be used
> for the purposes stated above.
> The third page tweaks fhandler_fifo::fcntl and fhandler_fifo::dup so
> that they work with O_PATH.
> In a followup email I'll provide the program I used to test this
> implementation.

Test program attached.

$ gcc -o o_path_fifo_test o_path_fifo_test.c

$ ./o_path_fifo_test.exe
The following calls should fail with EBADF:
read: OK
write: OK
fchmod: OK
fchown: OK
ioctl: OK
fgetxattr: OK
mmap: OK

The following calls should succeed:
fstat: OK
fstatfs: OK
fcntl_dup: OK
fcntl_getfl: OK
fcntl_setfl: OK
fcntl_getfd: OK
fcntl_setfd: OK
close: OK
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: o_path_fifo_test.c
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20200123/af007d6f/attachment.c>

More information about the Cygwin-patches mailing list