1 .. SPDX-License-Identifier: GPL-2.0
10 A filesystem in which data and metadata are provided by an ordinary
11 userspace process. The filesystem can be accessed normally through
15 The process(es) providing the data and metadata of the filesystem.
17 Non-privileged mount (or user mount):
18 A userspace filesystem mounted by a non-privileged (non-root) user.
19 The filesystem daemon is running with the privileges of the mounting
20 user. NOTE: this is not the same as mounts allowed with the "user"
21 option in /etc/fstab, which is not discussed here.
23 Filesystem connection:
24 A connection between the filesystem daemon and the kernel. The
25 connection exists until either the daemon dies, or the filesystem is
26 umounted. Note that detaching (or lazy umounting) the filesystem
27 does *not* break the connection, in this case it will exist until
28 the last reference to the filesystem is released.
31 The user who does the mounting.
34 The user who is performing filesystem operations.
39 FUSE is a userspace filesystem framework. It consists of a kernel
40 module (fuse.ko), a userspace library (libfuse.*) and a mount utility
43 One of the most important features of FUSE is allowing secure,
44 non-privileged mounts. This opens up new possibilities for the use of
45 filesystems. A good example is sshfs: a secure network filesystem
46 using the sftp protocol.
48 The userspace library and utilities are available from the
49 `FUSE homepage: <http://fuse.sourceforge.net/>`_
54 The filesystem type given to mount(2) can be one of the following:
57 This is the usual way to mount a FUSE filesystem. The first
58 argument of the mount system call may contain an arbitrary string,
59 which is not interpreted by the kernel.
62 The filesystem is block device based. The first argument of the
63 mount system call is interpreted as the name of the device.
69 The file descriptor to use for communication between the userspace
70 filesystem and the kernel. The file descriptor must have been
71 obtained by opening the FUSE device ('/dev/fuse').
74 The file mode of the filesystem's root in octal representation.
77 The numeric user id of the mount owner.
80 The numeric group id of the mount owner.
83 By default FUSE doesn't check file access permissions, the
84 filesystem is free to implement its access policy or leave it to
85 the underlying file access mechanism (e.g. in case of network
86 filesystems). This option enables permission checking, restricting
87 access based on file mode. It is usually useful together with the
88 'allow_other' mount option.
91 This option overrides the security measure restricting file access
92 to the user mounting the filesystem. This option is by default only
93 allowed to root, but this restriction can be removed with a
94 (userspace) configuration option.
97 With this option the maximum size of read operations can be set.
98 The default is infinite. Note that the size of read requests is
99 limited anyway to 32 pages (which is 128kbyte on i386).
102 Set the block size for the filesystem. The default is 512. This
103 option is only valid for 'fuseblk' type mounts.
108 There's a control filesystem for FUSE, which can be mounted by::
110 mount -t fusectl none /sys/fs/fuse/connections
112 Mounting it under the '/sys/fs/fuse/connections' directory makes it
113 backwards compatible with earlier versions.
115 Under the fuse control filesystem each connection has a directory
116 named by a unique number.
118 For each connection the following files exist within this directory:
121 The number of requests which are waiting to be transferred to
122 userspace or being processed by the filesystem daemon. If there is
123 no filesystem activity and 'waiting' is non-zero, then the
124 filesystem is hung or deadlocked.
127 Writing anything into this file will abort the filesystem
128 connection. This means that all waiting requests will be aborted an
129 error returned for all aborted and new requests.
131 Only the owner of the mount may read or write these files.
133 Interrupting filesystem operations
134 ##################################
136 If a process issuing a FUSE filesystem request is interrupted, the
137 following will happen:
139 - If the request is not yet sent to userspace AND the signal is
140 fatal (SIGKILL or unhandled fatal signal), then the request is
141 dequeued and returns immediately.
143 - If the request is not yet sent to userspace AND the signal is not
144 fatal, then an interrupted flag is set for the request. When
145 the request has been successfully transferred to userspace and
146 this flag is set, an INTERRUPT request is queued.
148 - If the request is already sent to userspace, then an INTERRUPT
151 INTERRUPT requests take precedence over other requests, so the
152 userspace filesystem will receive queued INTERRUPTs before any others.
154 The userspace filesystem may ignore the INTERRUPT requests entirely,
155 or may honor them by sending a reply to the *original* request, with
156 the error set to EINTR.
158 It is also possible that there's a race between processing the
159 original request and its INTERRUPT request. There are two possibilities:
161 1. The INTERRUPT request is processed before the original request is
164 2. The INTERRUPT request is processed after the original request has
167 If the filesystem cannot find the original request, it should wait for
168 some timeout and/or a number of new requests to arrive, after which it
169 should reply to the INTERRUPT request with an EAGAIN error. In case
170 1) the INTERRUPT request will be requeued. In case 2) the INTERRUPT
171 reply will be ignored.
173 Aborting a filesystem connection
174 ================================
176 It is possible to get into certain situations where the filesystem is
177 not responding. Reasons for this may be:
179 a) Broken userspace filesystem implementation
181 b) Network connection down
183 c) Accidental deadlock
185 d) Malicious deadlock
187 (For more on c) and d) see later sections)
189 In either of these cases it may be useful to abort the connection to
190 the filesystem. There are several ways to do this:
192 - Kill the filesystem daemon. Works in case of a) and b)
194 - Kill the filesystem daemon and all users of the filesystem. Works
195 in all cases except some malicious deadlocks
197 - Use forced umount (umount -f). Works in all cases but only if
198 filesystem is still attached (it hasn't been lazy unmounted)
200 - Abort filesystem through the FUSE control filesystem. Most
201 powerful method, always works.
203 How do non-privileged mounts work?
204 ==================================
206 Since the mount() system call is a privileged operation, a helper
207 program (fusermount) is needed, which is installed setuid root.
209 The implication of providing non-privileged mounts is that the mount
210 owner must not be able to use this capability to compromise the
211 system. Obvious requirements arising from this are:
213 A) mount owner should not be able to get elevated privileges with the
214 help of the mounted filesystem
216 B) mount owner should not get illegitimate access to information from
217 other users' and the super user's processes
219 C) mount owner should not be able to induce undesired behavior in
220 other users' or the super user's processes
222 How are requirements fulfilled?
223 ===============================
225 A) The mount owner could gain elevated privileges by either:
227 1. creating a filesystem containing a device file, then opening this device
229 2. creating a filesystem containing a suid or sgid application, then executing this application
231 The solution is not to allow opening device files and ignore
232 setuid and setgid bits when executing programs. To ensure this
233 fusermount always adds "nosuid" and "nodev" to the mount options
234 for non-privileged mounts.
236 B) If another user is accessing files or directories in the
237 filesystem, the filesystem daemon serving requests can record the
238 exact sequence and timing of operations performed. This
239 information is otherwise inaccessible to the mount owner, so this
240 counts as an information leak.
242 The solution to this problem will be presented in point 2) of C).
244 C) There are several ways in which the mount owner can induce
245 undesired behavior in other users' processes, such as:
247 1) mounting a filesystem over a file or directory which the mount
248 owner could otherwise not be able to modify (or could only
249 make limited modifications).
251 This is solved in fusermount, by checking the access
252 permissions on the mountpoint and only allowing the mount if
253 the mount owner can do unlimited modification (has write
254 access to the mountpoint, and mountpoint is not a "sticky"
257 2) Even if 1) is solved the mount owner can change the behavior
258 of other users' processes.
260 i) It can slow down or indefinitely delay the execution of a
261 filesystem operation creating a DoS against the user or the
262 whole system. For example a suid application locking a
263 system file, and then accessing a file on the mount owner's
264 filesystem could be stopped, and thus causing the system
265 file to be locked forever.
267 ii) It can present files or directories of unlimited length, or
268 directory structures of unlimited depth, possibly causing a
269 system process to eat up diskspace, memory or other
270 resources, again causing *DoS*.
272 The solution to this as well as B) is not to allow processes
273 to access the filesystem, which could otherwise not be
274 monitored or manipulated by the mount owner. Since if the
275 mount owner can ptrace a process, it can do all of the above
276 without using a FUSE mount, the same criteria as used in
277 ptrace can be used to check if a process is allowed to access
278 the filesystem or not.
280 Note that the *ptrace* check is not strictly necessary to
281 prevent B/2/i, it is enough to check if mount owner has enough
282 privilege to send signal to the process accessing the
283 filesystem, since *SIGSTOP* can be used to get a similar effect.
285 I think these limitations are unacceptable?
286 ===========================================
288 If a sysadmin trusts the users enough, or can ensure through other
289 measures, that system processes will never enter non-privileged
290 mounts, it can relax the last limitation with a 'user_allow_other'
291 config option. If this config option is set, the mounting user can
292 add the 'allow_other' mount option which disables the check for other
295 Kernel - userspace interface
296 ============================
298 The following diagram shows how a filesystem operation (in this
299 example unlink) is performed in FUSE. ::
302 | "rm /mnt/fuse/file" | FUSE filesystem daemon
307 | | [sleep on fc->waitq]
311 | [get request from |
314 | [queue req on fc->pending] |
315 | [wake up fc->waitq] | [woken up]
316 | >request_wait_answer() |
317 | [sleep on req->waitq] |
319 | | [remove req from fc->pending]
320 | | [copy req to read buffer]
321 | | [add req to fc->processing]
328 | | >fuse_dev_write()
329 | | [look up req in fc->processing]
330 | | [remove from fc->processing]
331 | | [copy write buffer to req]
332 | [woken up] | [wake up req->waitq]
333 | | <fuse_dev_write()
335 | <request_wait_answer() |
342 .. note:: Everything in the description above is greatly simplified
344 There are a couple of ways in which to deadlock a FUSE filesystem.
345 Since we are talking about unprivileged userspace programs,
346 something must be done about these.
348 **Scenario 1 - Simple deadlock**::
350 | "rm /mnt/fuse/file" | FUSE filesystem daemon
352 | >sys_unlink("/mnt/fuse/file") |
353 | [acquire inode semaphore |
356 | [sleep on req->waitq] |
358 | | >sys_unlink("/mnt/fuse/file")
359 | | [acquire inode semaphore
363 The solution for this is to allow the filesystem to be aborted.
365 **Scenario 2 - Tricky deadlock**
368 This one needs a carefully crafted filesystem. It's a variation on
369 the above, only the call back to the filesystem is not explicit,
370 but is caused by a pagefault. ::
372 | Kamikaze filesystem thread 1 | Kamikaze filesystem thread 2
374 | [fd = open("/mnt/fuse/file")] | [request served normally]
375 | [mmap fd to 'addr'] |
376 | [close fd] | [FLUSH triggers 'magic' flag]
377 | [read a byte from addr] |
379 | [find or create page] |
382 | [queue READ request] |
383 | [sleep on req->waitq] |
384 | | [read request to buffer]
385 | | [create reply header before addr]
386 | | >sys_write(addr - headerlength)
387 | | >fuse_dev_write()
388 | | [look up req in fc->processing]
389 | | [remove from fc->processing]
390 | | [copy write buffer to req]
392 | | [find or create page]
396 The solution is basically the same as above.
398 An additional problem is that while the write buffer is being copied
399 to the request, the request must not be interrupted/aborted. This is
400 because the destination address of the copy may not be valid after the
401 request has returned.
403 This is solved with doing the copy atomically, and allowing abort
404 while the page(s) belonging to the write buffer are faulted with
405 get_user_pages(). The 'req->locked' flag indicates when the copy is
406 taking place, and abort is delayed until this flag is unset.