Bug 245974 - fileargs_fopen() does not work properly with fifos
Summary: fileargs_fopen() does not work properly with fifos
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
Depends on:
Reported: 2020-04-27 15:19 UTC by Mark Johnston
Modified: 2020-04-28 06:27 UTC (History)
2 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Mark Johnston freebsd_committer 2020-04-27 15:19:41 UTC
The fileargs service maintains a cache of open fds, presumably so that fileargs_open() does not have to make multiple round-trips if the sandboxed program opens the same file multiple times.  However, when opening a file for the first time, cap_fileargs will attempt to open the file twice: once in order to respond to the open request, and a second time when adding the file to a "cache" nvlist.  If we are opening a fifo for reading this can cause the service to unexpectedly block twice:

reader: opens fifo and blocks
writer: opens fifo, writes some data, closes the fifo
reader: opens the fifo a second time, blocks again

I suspect we should just avoid reopening the file, though I don't quite understand the whole caching mechanism yet.

This can be demonstrated using tail -f:

$ mkfifo /tmp/test.fifo
$ tail -f /tmp/test.fifo

from another shell

$ echo a > /tmp/test.fifo