Bug 236379

Summary: [FUSEFS] fuse(4) writes from aio(4) don't set the fuse_out_header.pid field correctly
Product: Base System Reporter: Alan Somers <asomers>
Component: kernAssignee: Alan Somers <asomers>
Status: New ---    
Severity: Affects Many People CC: emaste
Priority: ---    
Version: CURRENT   
Hardware: Any   
OS: Any   

Description Alan Somers freebsd_committer 2019-03-07 23:38:03 UTC
Every FUSE operation includes the pid of the process that issued the request.  However, when an aiod kernel process writes to a fuse-backed file on behalf of a regular user process, fuse(4) only sees aiod's pid_t, not the user process's.  This can cause a fuse filesystem daemon to incorrectly authenticate write commands

There are three possible solutions:
1) Set the pid field correctly.  The aio daemon already keeps track of it,
   but doesn't send that information to fuse(4).  It's not obvious how.
   a) Perhaps stuff it into a spare field in struct ucred?
   b) Define custom fileops for fuse and store the pid that opened a file in
      struct file.f_data?  But this would cause problems when sending a file
      descriptor from one process to another with sendmsg.
2) Set FUSE_WRITE_CACHE, just like writes from the pager.  Currently, however,
   fuse(4) isn't aware of which operations come from aiod.
3) Alternatively, since FUSE_WRITE is an asynchronous operation, aio(4)
   could learn to bypass VOP_WRITE and use a threadless direct dispatch like
   it currently does for disks.  That would improve performance, too.

This bug probably applies to aio reads as well, but I haven't checked yet.
Comment 1 Alan Somers freebsd_committer 2019-03-08 14:46:10 UTC
Oops, I missed self-assigning this one.  Sorry linimon.
Comment 2 commit-hook freebsd_committer 2019-03-11 18:29:03 UTC
A commit references this bug:

Author: asomers
Date: Mon Mar 11 18:28:21 UTC 2019
New revision: 345017
URL: https://svnweb.freebsd.org/changeset/base/345017

Log:
  fuse(4): add tests for FUSE_READ

  PR:		236379
  PR:		236466
  PR:		236472
  Sponsored by:	The FreeBSD Foundation

Changes:
  projects/fuse2/tests/sys/fs/fuse/Makefile
  projects/fuse2/tests/sys/fs/fuse/mockfs.cc
  projects/fuse2/tests/sys/fs/fuse/mockfs.hh
  projects/fuse2/tests/sys/fs/fuse/read.cc
  projects/fuse2/tests/sys/fs/fuse/utils.cc
  projects/fuse2/tests/sys/fs/fuse/utils.hh
  projects/fuse2/tests/sys/fs/fuse/write.cc
Comment 3 commit-hook freebsd_committer 2019-03-11 22:30:33 UTC
A commit references this bug:

Author: asomers
Date: Mon Mar 11 22:29:58 UTC 2019
New revision: 345035
URL: https://svnweb.freebsd.org/changeset/base/345035

Log:
  fuse(4): add tests for FUSE_OPENDIR, FUSE_FSYNC, and FUSE_FSYNCDIR

  And one more for FUSE_WRITE, too.

  PR:		236379
  PR:		236473
  PR:		236474
  Sponsored by:	The FreeBSD Foundation

Changes:
  projects/fuse2/tests/sys/fs/fuse/Makefile
  projects/fuse2/tests/sys/fs/fuse/fsync.cc
  projects/fuse2/tests/sys/fs/fuse/fsyncdir.cc
  projects/fuse2/tests/sys/fs/fuse/mockfs.cc
  projects/fuse2/tests/sys/fs/fuse/mockfs.hh
  projects/fuse2/tests/sys/fs/fuse/opendir.cc
  projects/fuse2/tests/sys/fs/fuse/write.cc