Bug 245974

Summary: fileargs_fopen() does not work properly with fifos
Product: Base System Reporter: Mark Johnston <markj>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: New ---    
Severity: Affects Only Me CC: cem, emaste
Priority: ---    
Version: CURRENT   
Hardware: Any   
OS: Any   

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