~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/filesystems/fuse.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/filesystems/fuse.rst (Version linux-6.12-rc7) and /Documentation/filesystems/fuse.rst (Version linux-5.6.19)


  1 .. SPDX-License-Identifier: GPL-2.0                 1 .. SPDX-License-Identifier: GPL-2.0
  2                                                !!   2 ==============
  3 ====                                           << 
  4 FUSE                                                3 FUSE
  5 ====                                           !!   4 ==============
  6                                                     5 
  7 Definitions                                         6 Definitions
  8 ===========                                         7 ===========
  9                                                     8 
 10 Userspace filesystem:                               9 Userspace filesystem:
 11   A filesystem in which data and metadata are      10   A filesystem in which data and metadata are provided by an ordinary
 12   userspace process.  The filesystem can be ac     11   userspace process.  The filesystem can be accessed normally through
 13   the kernel interface.                            12   the kernel interface.
 14                                                    13 
 15 Filesystem daemon:                                 14 Filesystem daemon:
 16   The process(es) providing the data and metad     15   The process(es) providing the data and metadata of the filesystem.
 17                                                    16 
 18 Non-privileged mount (or user mount):              17 Non-privileged mount (or user mount):
 19   A userspace filesystem mounted by a non-priv     18   A userspace filesystem mounted by a non-privileged (non-root) user.
 20   The filesystem daemon is running with the pr     19   The filesystem daemon is running with the privileges of the mounting
 21   user.  NOTE: this is not the same as mounts      20   user.  NOTE: this is not the same as mounts allowed with the "user"
 22   option in /etc/fstab, which is not discussed     21   option in /etc/fstab, which is not discussed here.
 23                                                    22 
 24 Filesystem connection:                             23 Filesystem connection:
 25   A connection between the filesystem daemon a     24   A connection between the filesystem daemon and the kernel.  The
 26   connection exists until either the daemon di     25   connection exists until either the daemon dies, or the filesystem is
 27   umounted.  Note that detaching (or lazy umou     26   umounted.  Note that detaching (or lazy umounting) the filesystem
 28   does *not* break the connection, in this cas     27   does *not* break the connection, in this case it will exist until
 29   the last reference to the filesystem is rele     28   the last reference to the filesystem is released.
 30                                                    29 
 31 Mount owner:                                       30 Mount owner:
 32   The user who does the mounting.                  31   The user who does the mounting.
 33                                                    32 
 34 User:                                              33 User:
 35   The user who is performing filesystem operat     34   The user who is performing filesystem operations.
 36                                                    35 
 37 What is FUSE?                                      36 What is FUSE?
 38 =============                                      37 =============
 39                                                    38 
 40 FUSE is a userspace filesystem framework.  It      39 FUSE is a userspace filesystem framework.  It consists of a kernel
 41 module (fuse.ko), a userspace library (libfuse     40 module (fuse.ko), a userspace library (libfuse.*) and a mount utility
 42 (fusermount).                                      41 (fusermount).
 43                                                    42 
 44 One of the most important features of FUSE is      43 One of the most important features of FUSE is allowing secure,
 45 non-privileged mounts.  This opens up new poss     44 non-privileged mounts.  This opens up new possibilities for the use of
 46 filesystems.  A good example is sshfs: a secur     45 filesystems.  A good example is sshfs: a secure network filesystem
 47 using the sftp protocol.                           46 using the sftp protocol.
 48                                                    47 
 49 The userspace library and utilities are availa     48 The userspace library and utilities are available from the
 50 `FUSE homepage: <https://github.com/libfuse/>` !!  49 `FUSE homepage: <http://fuse.sourceforge.net/>`_
 51                                                    50 
 52 Filesystem type                                    51 Filesystem type
 53 ===============                                    52 ===============
 54                                                    53 
 55 The filesystem type given to mount(2) can be o     54 The filesystem type given to mount(2) can be one of the following:
 56                                                    55 
 57     fuse                                           56     fuse
 58       This is the usual way to mount a FUSE fi     57       This is the usual way to mount a FUSE filesystem.  The first
 59       argument of the mount system call may co     58       argument of the mount system call may contain an arbitrary string,
 60       which is not interpreted by the kernel.      59       which is not interpreted by the kernel.
 61                                                    60 
 62     fuseblk                                        61     fuseblk
 63       The filesystem is block device based.  T     62       The filesystem is block device based.  The first argument of the
 64       mount system call is interpreted as the      63       mount system call is interpreted as the name of the device.
 65                                                    64 
 66 Mount options                                      65 Mount options
 67 =============                                      66 =============
 68                                                    67 
 69 fd=N                                               68 fd=N
 70   The file descriptor to use for communication     69   The file descriptor to use for communication between the userspace
 71   filesystem and the kernel.  The file descrip     70   filesystem and the kernel.  The file descriptor must have been
 72   obtained by opening the FUSE device ('/dev/f     71   obtained by opening the FUSE device ('/dev/fuse').
 73                                                    72 
 74 rootmode=M                                         73 rootmode=M
 75   The file mode of the filesystem's root in oc     74   The file mode of the filesystem's root in octal representation.
 76                                                    75 
 77 user_id=N                                          76 user_id=N
 78   The numeric user id of the mount owner.          77   The numeric user id of the mount owner.
 79                                                    78 
 80 group_id=N                                         79 group_id=N
 81   The numeric group id of the mount owner.         80   The numeric group id of the mount owner.
 82                                                    81 
 83 default_permissions                                82 default_permissions
 84   By default FUSE doesn't check file access pe     83   By default FUSE doesn't check file access permissions, the
 85   filesystem is free to implement its access p     84   filesystem is free to implement its access policy or leave it to
 86   the underlying file access mechanism (e.g. i     85   the underlying file access mechanism (e.g. in case of network
 87   filesystems).  This option enables permissio     86   filesystems).  This option enables permission checking, restricting
 88   access based on file mode.  It is usually us     87   access based on file mode.  It is usually useful together with the
 89   'allow_other' mount option.                      88   'allow_other' mount option.
 90                                                    89 
 91 allow_other                                        90 allow_other
 92   This option overrides the security measure r     91   This option overrides the security measure restricting file access
 93   to the user mounting the filesystem.  This o     92   to the user mounting the filesystem.  This option is by default only
 94   allowed to root, but this restriction can be     93   allowed to root, but this restriction can be removed with a
 95   (userspace) configuration option.                94   (userspace) configuration option.
 96                                                    95 
 97 max_read=N                                         96 max_read=N
 98   With this option the maximum size of read op     97   With this option the maximum size of read operations can be set.
 99   The default is infinite.  Note that the size     98   The default is infinite.  Note that the size of read requests is
100   limited anyway to 32 pages (which is 128kbyt     99   limited anyway to 32 pages (which is 128kbyte on i386).
101                                                   100 
102 blksize=N                                         101 blksize=N
103   Set the block size for the filesystem.  The     102   Set the block size for the filesystem.  The default is 512.  This
104   option is only valid for 'fuseblk' type moun    103   option is only valid for 'fuseblk' type mounts.
105                                                   104 
106 Control filesystem                                105 Control filesystem
107 ==================                                106 ==================
108                                                   107 
109 There's a control filesystem for FUSE, which c    108 There's a control filesystem for FUSE, which can be mounted by::
110                                                   109 
111   mount -t fusectl none /sys/fs/fuse/connectio    110   mount -t fusectl none /sys/fs/fuse/connections
112                                                   111 
113 Mounting it under the '/sys/fs/fuse/connection    112 Mounting it under the '/sys/fs/fuse/connections' directory makes it
114 backwards compatible with earlier versions.       113 backwards compatible with earlier versions.
115                                                   114 
116 Under the fuse control filesystem each connect    115 Under the fuse control filesystem each connection has a directory
117 named by a unique number.                         116 named by a unique number.
118                                                   117 
119 For each connection the following files exist     118 For each connection the following files exist within this directory:
120                                                   119 
121         waiting                                   120         waiting
122           The number of requests which are wai    121           The number of requests which are waiting to be transferred to
123           userspace or being processed by the     122           userspace or being processed by the filesystem daemon.  If there is
124           no filesystem activity and 'waiting'    123           no filesystem activity and 'waiting' is non-zero, then the
125           filesystem is hung or deadlocked.       124           filesystem is hung or deadlocked.
126                                                   125 
127         abort                                     126         abort
128           Writing anything into this file will    127           Writing anything into this file will abort the filesystem
129           connection.  This means that all wai    128           connection.  This means that all waiting requests will be aborted an
130           error returned for all aborted and n    129           error returned for all aborted and new requests.
131                                                   130 
132 Only the owner of the mount may read or write     131 Only the owner of the mount may read or write these files.
133                                                   132 
134 Interrupting filesystem operations                133 Interrupting filesystem operations
135 ##################################                134 ##################################
136                                                   135 
137 If a process issuing a FUSE filesystem request    136 If a process issuing a FUSE filesystem request is interrupted, the
138 following will happen:                            137 following will happen:
139                                                   138 
140   -  If the request is not yet sent to userspa    139   -  If the request is not yet sent to userspace AND the signal is
141      fatal (SIGKILL or unhandled fatal signal)    140      fatal (SIGKILL or unhandled fatal signal), then the request is
142      dequeued and returns immediately.            141      dequeued and returns immediately.
143                                                   142 
144   -  If the request is not yet sent to userspa    143   -  If the request is not yet sent to userspace AND the signal is not
145      fatal, then an interrupted flag is set fo    144      fatal, then an interrupted flag is set for the request.  When
146      the request has been successfully transfe    145      the request has been successfully transferred to userspace and
147      this flag is set, an INTERRUPT request is    146      this flag is set, an INTERRUPT request is queued.
148                                                   147 
149   -  If the request is already sent to userspa    148   -  If the request is already sent to userspace, then an INTERRUPT
150      request is queued.                           149      request is queued.
151                                                   150 
152 INTERRUPT requests take precedence over other     151 INTERRUPT requests take precedence over other requests, so the
153 userspace filesystem will receive queued INTER    152 userspace filesystem will receive queued INTERRUPTs before any others.
154                                                   153 
155 The userspace filesystem may ignore the INTERR    154 The userspace filesystem may ignore the INTERRUPT requests entirely,
156 or may honor them by sending a reply to the *o    155 or may honor them by sending a reply to the *original* request, with
157 the error set to EINTR.                           156 the error set to EINTR.
158                                                   157 
159 It is also possible that there's a race betwee    158 It is also possible that there's a race between processing the
160 original request and its INTERRUPT request.  T    159 original request and its INTERRUPT request.  There are two possibilities:
161                                                   160 
162   1. The INTERRUPT request is processed before    161   1. The INTERRUPT request is processed before the original request is
163      processed                                    162      processed
164                                                   163 
165   2. The INTERRUPT request is processed after     164   2. The INTERRUPT request is processed after the original request has
166      been answered                                165      been answered
167                                                   166 
168 If the filesystem cannot find the original req    167 If the filesystem cannot find the original request, it should wait for
169 some timeout and/or a number of new requests t    168 some timeout and/or a number of new requests to arrive, after which it
170 should reply to the INTERRUPT request with an     169 should reply to the INTERRUPT request with an EAGAIN error.  In case
171 1) the INTERRUPT request will be requeued.  In    170 1) the INTERRUPT request will be requeued.  In case 2) the INTERRUPT
172 reply will be ignored.                            171 reply will be ignored.
173                                                   172 
174 Aborting a filesystem connection                  173 Aborting a filesystem connection
175 ================================                  174 ================================
176                                                   175 
177 It is possible to get into certain situations     176 It is possible to get into certain situations where the filesystem is
178 not responding.  Reasons for this may be:         177 not responding.  Reasons for this may be:
179                                                   178 
180   a) Broken userspace filesystem implementatio    179   a) Broken userspace filesystem implementation
181                                                   180 
182   b) Network connection down                      181   b) Network connection down
183                                                   182 
184   c) Accidental deadlock                          183   c) Accidental deadlock
185                                                   184 
186   d) Malicious deadlock                           185   d) Malicious deadlock
187                                                   186 
188 (For more on c) and d) see later sections)        187 (For more on c) and d) see later sections)
189                                                   188 
190 In either of these cases it may be useful to a    189 In either of these cases it may be useful to abort the connection to
191 the filesystem.  There are several ways to do     190 the filesystem.  There are several ways to do this:
192                                                   191 
193   - Kill the filesystem daemon.  Works in case    192   - Kill the filesystem daemon.  Works in case of a) and b)
194                                                   193 
195   - Kill the filesystem daemon and all users o    194   - Kill the filesystem daemon and all users of the filesystem.  Works
196     in all cases except some malicious deadloc    195     in all cases except some malicious deadlocks
197                                                   196 
198   - Use forced umount (umount -f).  Works in a    197   - Use forced umount (umount -f).  Works in all cases but only if
199     filesystem is still attached (it hasn't be    198     filesystem is still attached (it hasn't been lazy unmounted)
200                                                   199 
201   - Abort filesystem through the FUSE control     200   - Abort filesystem through the FUSE control filesystem.  Most
202     powerful method, always works.                201     powerful method, always works.
203                                                   202 
204 How do non-privileged mounts work?                203 How do non-privileged mounts work?
205 ==================================                204 ==================================
206                                                   205 
207 Since the mount() system call is a privileged     206 Since the mount() system call is a privileged operation, a helper
208 program (fusermount) is needed, which is insta    207 program (fusermount) is needed, which is installed setuid root.
209                                                   208 
210 The implication of providing non-privileged mo    209 The implication of providing non-privileged mounts is that the mount
211 owner must not be able to use this capability     210 owner must not be able to use this capability to compromise the
212 system.  Obvious requirements arising from thi    211 system.  Obvious requirements arising from this are:
213                                                   212 
214  A) mount owner should not be able to get elev    213  A) mount owner should not be able to get elevated privileges with the
215     help of the mounted filesystem                214     help of the mounted filesystem
216                                                   215 
217  B) mount owner should not get illegitimate ac    216  B) mount owner should not get illegitimate access to information from
218     other users' and the super user's processe    217     other users' and the super user's processes
219                                                   218 
220  C) mount owner should not be able to induce u    219  C) mount owner should not be able to induce undesired behavior in
221     other users' or the super user's processes    220     other users' or the super user's processes
222                                                   221 
223 How are requirements fulfilled?                   222 How are requirements fulfilled?
224 ===============================                   223 ===============================
225                                                   224 
226  A) The mount owner could gain elevated privil    225  A) The mount owner could gain elevated privileges by either:
227                                                   226 
228     1. creating a filesystem containing a devi    227     1. creating a filesystem containing a device file, then opening this device
229                                                   228 
230     2. creating a filesystem containing a suid    229     2. creating a filesystem containing a suid or sgid application, then executing this application
231                                                   230 
232     The solution is not to allow opening devic    231     The solution is not to allow opening device files and ignore
233     setuid and setgid bits when executing prog    232     setuid and setgid bits when executing programs.  To ensure this
234     fusermount always adds "nosuid" and "nodev    233     fusermount always adds "nosuid" and "nodev" to the mount options
235     for non-privileged mounts.                    234     for non-privileged mounts.
236                                                   235 
237  B) If another user is accessing files or dire    236  B) If another user is accessing files or directories in the
238     filesystem, the filesystem daemon serving     237     filesystem, the filesystem daemon serving requests can record the
239     exact sequence and timing of operations pe    238     exact sequence and timing of operations performed.  This
240     information is otherwise inaccessible to t    239     information is otherwise inaccessible to the mount owner, so this
241     counts as an information leak.                240     counts as an information leak.
242                                                   241 
243     The solution to this problem will be prese    242     The solution to this problem will be presented in point 2) of C).
244                                                   243 
245  C) There are several ways in which the mount     244  C) There are several ways in which the mount owner can induce
246     undesired behavior in other users' process    245     undesired behavior in other users' processes, such as:
247                                                   246 
248      1) mounting a filesystem over a file or d    247      1) mounting a filesystem over a file or directory which the mount
249         owner could otherwise not be able to m    248         owner could otherwise not be able to modify (or could only
250         make limited modifications).              249         make limited modifications).
251                                                   250 
252         This is solved in fusermount, by check    251         This is solved in fusermount, by checking the access
253         permissions on the mountpoint and only    252         permissions on the mountpoint and only allowing the mount if
254         the mount owner can do unlimited modif    253         the mount owner can do unlimited modification (has write
255         access to the mountpoint, and mountpoi    254         access to the mountpoint, and mountpoint is not a "sticky"
256         directory)                                255         directory)
257                                                   256 
258      2) Even if 1) is solved the mount owner c    257      2) Even if 1) is solved the mount owner can change the behavior
259         of other users' processes.                258         of other users' processes.
260                                                   259 
261          i) It can slow down or indefinitely d    260          i) It can slow down or indefinitely delay the execution of a
262             filesystem operation creating a Do    261             filesystem operation creating a DoS against the user or the
263             whole system.  For example a suid     262             whole system.  For example a suid application locking a
264             system file, and then accessing a     263             system file, and then accessing a file on the mount owner's
265             filesystem could be stopped, and t    264             filesystem could be stopped, and thus causing the system
266             file to be locked forever.            265             file to be locked forever.
267                                                   266 
268          ii) It can present files or directori    267          ii) It can present files or directories of unlimited length, or
269              directory structures of unlimited    268              directory structures of unlimited depth, possibly causing a
270              system process to eat up diskspac    269              system process to eat up diskspace, memory or other
271              resources, again causing *DoS*.      270              resources, again causing *DoS*.
272                                                   271 
273         The solution to this as well as B) is     272         The solution to this as well as B) is not to allow processes
274         to access the filesystem, which could     273         to access the filesystem, which could otherwise not be
275         monitored or manipulated by the mount     274         monitored or manipulated by the mount owner.  Since if the
276         mount owner can ptrace a process, it c    275         mount owner can ptrace a process, it can do all of the above
277         without using a FUSE mount, the same c    276         without using a FUSE mount, the same criteria as used in
278         ptrace can be used to check if a proce    277         ptrace can be used to check if a process is allowed to access
279         the filesystem or not.                    278         the filesystem or not.
280                                                   279 
281         Note that the *ptrace* check is not st    280         Note that the *ptrace* check is not strictly necessary to
282         prevent C/2/i, it is enough to check i !! 281         prevent B/2/i, it is enough to check if mount owner has enough
283         privilege to send signal to the proces    282         privilege to send signal to the process accessing the
284         filesystem, since *SIGSTOP* can be use    283         filesystem, since *SIGSTOP* can be used to get a similar effect.
285                                                   284 
286 I think these limitations are unacceptable?       285 I think these limitations are unacceptable?
287 ===========================================       286 ===========================================
288                                                   287 
289 If a sysadmin trusts the users enough, or can     288 If a sysadmin trusts the users enough, or can ensure through other
290 measures, that system processes will never ent    289 measures, that system processes will never enter non-privileged
291 mounts, it can relax the last limitation in se !! 290 mounts, it can relax the last limitation with a 'user_allow_other'
292                                                !! 291 config option.  If this config option is set, the mounting user can
293   - With the 'user_allow_other' config option. !! 292 add the 'allow_other' mount option which disables the check for other
294     set, the mounting user can add the 'allow_ !! 293 users' processes.
295     disables the check for other users' proces << 
296                                                << 
297     User namespaces have an unintuitive intera << 
298     an unprivileged user - normally restricted << 
299     'allow_other' - could do so in a user name << 
300     privileged. If any process could access su << 
301     this would give the mounting user the abil << 
302     processes in user namespaces where they're << 
303     reason 'allow_other' restricts access to u << 
304     or a descendant.                           << 
305                                                << 
306   - With the 'allow_sys_admin_access' module o << 
307     set, super user's processes have unrestric << 
308     irrespective of allow_other setting or use << 
309     mounting user.                             << 
310                                                << 
311 Note that both of these relaxations expose the << 
312 information leak or *DoS* as described in poin << 
313 preceding section.                             << 
314                                                   294 
315 Kernel - userspace interface                      295 Kernel - userspace interface
316 ============================                      296 ============================
317                                                   297 
318 The following diagram shows how a filesystem o    298 The following diagram shows how a filesystem operation (in this
319 example unlink) is performed in FUSE. ::          299 example unlink) is performed in FUSE. ::
320                                                   300 
321                                                   301 
322  |  "rm /mnt/fuse/file"               |  FUSE     302  |  "rm /mnt/fuse/file"               |  FUSE filesystem daemon
323  |                                    |           303  |                                    |
324  |                                    |  >sys_    304  |                                    |  >sys_read()
325  |                                    |    >fu    305  |                                    |    >fuse_dev_read()
326  |                                    |      >    306  |                                    |      >request_wait()
327  |                                    |           307  |                                    |        [sleep on fc->waitq]
328  |                                    |           308  |                                    |
329  |  >sys_unlink()                     |           309  |  >sys_unlink()                     |
330  |    >fuse_unlink()                  |           310  |    >fuse_unlink()                  |
331  |      [get request from             |           311  |      [get request from             |
332  |       fc->unused_list]             |           312  |       fc->unused_list]             |
333  |      >request_send()               |           313  |      >request_send()               |
334  |        [queue req on fc->pending]  |           314  |        [queue req on fc->pending]  |
335  |        [wake up fc->waitq]         |           315  |        [wake up fc->waitq]         |        [woken up]
336  |        >request_wait_answer()      |           316  |        >request_wait_answer()      |
337  |          [sleep on req->waitq]     |           317  |          [sleep on req->waitq]     |
338  |                                    |      <    318  |                                    |      <request_wait()
339  |                                    |      [    319  |                                    |      [remove req from fc->pending]
340  |                                    |      [    320  |                                    |      [copy req to read buffer]
341  |                                    |      [    321  |                                    |      [add req to fc->processing]
342  |                                    |    <fu    322  |                                    |    <fuse_dev_read()
343  |                                    |  <sys_    323  |                                    |  <sys_read()
344  |                                    |           324  |                                    |
345  |                                    |  [perf    325  |                                    |  [perform unlink]
346  |                                    |           326  |                                    |
347  |                                    |  >sys_    327  |                                    |  >sys_write()
348  |                                    |    >fu    328  |                                    |    >fuse_dev_write()
349  |                                    |      [    329  |                                    |      [look up req in fc->processing]
350  |                                    |      [    330  |                                    |      [remove from fc->processing]
351  |                                    |      [    331  |                                    |      [copy write buffer to req]
352  |          [woken up]                |      [    332  |          [woken up]                |      [wake up req->waitq]
353  |                                    |    <fu    333  |                                    |    <fuse_dev_write()
354  |                                    |  <sys_    334  |                                    |  <sys_write()
355  |        <request_wait_answer()      |           335  |        <request_wait_answer()      |
356  |      <request_send()               |           336  |      <request_send()               |
357  |      [add request to               |           337  |      [add request to               |
358  |       fc->unused_list]             |           338  |       fc->unused_list]             |
359  |    <fuse_unlink()                  |           339  |    <fuse_unlink()                  |
360  |  <sys_unlink()                     |           340  |  <sys_unlink()                     |
361                                                   341 
362 .. note:: Everything in the description above     342 .. note:: Everything in the description above is greatly simplified
363                                                   343 
364 There are a couple of ways in which to deadloc    344 There are a couple of ways in which to deadlock a FUSE filesystem.
365 Since we are talking about unprivileged usersp    345 Since we are talking about unprivileged userspace programs,
366 something must be done about these.               346 something must be done about these.
367                                                   347 
368 **Scenario 1 -  Simple deadlock**::               348 **Scenario 1 -  Simple deadlock**::
369                                                   349 
370  |  "rm /mnt/fuse/file"               |  FUSE     350  |  "rm /mnt/fuse/file"               |  FUSE filesystem daemon
371  |                                    |           351  |                                    |
372  |  >sys_unlink("/mnt/fuse/file")     |           352  |  >sys_unlink("/mnt/fuse/file")     |
373  |    [acquire inode semaphore        |           353  |    [acquire inode semaphore        |
374  |     for "file"]                    |           354  |     for "file"]                    |
375  |    >fuse_unlink()                  |           355  |    >fuse_unlink()                  |
376  |      [sleep on req->waitq]         |           356  |      [sleep on req->waitq]         |
377  |                                    |  <sys_    357  |                                    |  <sys_read()
378  |                                    |  >sys_    358  |                                    |  >sys_unlink("/mnt/fuse/file")
379  |                                    |    [ac    359  |                                    |    [acquire inode semaphore
380  |                                    |     fo    360  |                                    |     for "file"]
381  |                                    |    *DE    361  |                                    |    *DEADLOCK*
382                                                   362 
383 The solution for this is to allow the filesyst    363 The solution for this is to allow the filesystem to be aborted.
384                                                   364 
385 **Scenario 2 - Tricky deadlock**                  365 **Scenario 2 - Tricky deadlock**
386                                                   366 
387                                                   367 
388 This one needs a carefully crafted filesystem.    368 This one needs a carefully crafted filesystem.  It's a variation on
389 the above, only the call back to the filesyste    369 the above, only the call back to the filesystem is not explicit,
390 but is caused by a pagefault. ::                  370 but is caused by a pagefault. ::
391                                                   371 
392  |  Kamikaze filesystem thread 1      |  Kamik    372  |  Kamikaze filesystem thread 1      |  Kamikaze filesystem thread 2
393  |                                    |           373  |                                    |
394  |  [fd = open("/mnt/fuse/file")]     |  [requ    374  |  [fd = open("/mnt/fuse/file")]     |  [request served normally]
395  |  [mmap fd to 'addr']               |           375  |  [mmap fd to 'addr']               |
396  |  [close fd]                        |  [FLUS    376  |  [close fd]                        |  [FLUSH triggers 'magic' flag]
397  |  [read a byte from addr]           |           377  |  [read a byte from addr]           |
398  |    >do_page_fault()                |           378  |    >do_page_fault()                |
399  |      [find or create page]         |           379  |      [find or create page]         |
400  |      [lock page]                   |           380  |      [lock page]                   |
401  |      >fuse_readpage()              |           381  |      >fuse_readpage()              |
402  |         [queue READ request]       |           382  |         [queue READ request]       |
403  |         [sleep on req->waitq]      |           383  |         [sleep on req->waitq]      |
404  |                                    |  [read    384  |                                    |  [read request to buffer]
405  |                                    |  [crea    385  |                                    |  [create reply header before addr]
406  |                                    |  >sys_    386  |                                    |  >sys_write(addr - headerlength)
407  |                                    |    >fu    387  |                                    |    >fuse_dev_write()
408  |                                    |      [    388  |                                    |      [look up req in fc->processing]
409  |                                    |      [    389  |                                    |      [remove from fc->processing]
410  |                                    |      [    390  |                                    |      [copy write buffer to req]
411  |                                    |           391  |                                    |        >do_page_fault()
412  |                                    |           392  |                                    |           [find or create page]
413  |                                    |           393  |                                    |           [lock page]
414  |                                    |           394  |                                    |           * DEADLOCK *
415                                                   395 
416 The solution is basically the same as above.      396 The solution is basically the same as above.
417                                                   397 
418 An additional problem is that while the write     398 An additional problem is that while the write buffer is being copied
419 to the request, the request must not be interr    399 to the request, the request must not be interrupted/aborted.  This is
420 because the destination address of the copy ma    400 because the destination address of the copy may not be valid after the
421 request has returned.                             401 request has returned.
422                                                   402 
423 This is solved with doing the copy atomically,    403 This is solved with doing the copy atomically, and allowing abort
424 while the page(s) belonging to the write buffe    404 while the page(s) belonging to the write buffer are faulted with
425 get_user_pages().  The 'req->locked' flag indi    405 get_user_pages().  The 'req->locked' flag indicates when the copy is
426 taking place, and abort is delayed until this     406 taking place, and abort is delayed until this flag is unset.
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php