6 A filesystem in which data and metadata are provided by an ordinary
7 userspace process. The filesystem can be accessed normally through
12 The process(es) providing the data and metadata of the filesystem.
14 Non-privileged mount (or user mount):
16 A userspace filesystem mounted by a non-privileged (non-root) user.
17 The filesystem daemon is running with the privileges of the mounting
18 user. NOTE: this is not the same as mounts allowed with the "user"
19 option in /etc/fstab, which is not discussed here.
23 The user who does the mounting.
27 The user who is performing filesystem operations.
32 FUSE is a userspace filesystem framework. It consists of a kernel
33 module (fuse.ko), a userspace library (libfuse.*) and a mount utility
36 One of the most important features of FUSE is allowing secure,
37 non-privileged mounts. This opens up new possibilities for the use of
38 filesystems. A good example is sshfs: a secure network filesystem
39 using the sftp protocol.
41 The userspace library and utilities are available from the FUSE
44 http://fuse.sourceforge.net/
51 The file descriptor to use for communication between the userspace
52 filesystem and the kernel. The file descriptor must have been
53 obtained by opening the FUSE device ('/dev/fuse').
57 The file mode of the filesystem's root in octal representation.
61 The numeric user id of the mount owner.
65 The numeric group id of the mount owner.
69 By default FUSE doesn't check file access permissions, the
70 filesystem is free to implement it's access policy or leave it to
71 the underlying file access mechanism (e.g. in case of network
72 filesystems). This option enables permission checking, restricting
73 access based on file mode. This is option is usually useful
74 together with the 'allow_other' mount option.
78 This option overrides the security measure restricting file access
79 to the user mounting the filesystem. This option is by default only
80 allowed to root, but this restriction can be removed with a
81 (userspace) configuration option.
85 With this option the maximum size of read operations can be set.
86 The default is infinite. Note that the size of read requests is
87 limited anyway to 32 pages (which is 128kbyte on i386).
92 FUSE sets up the following hierarchy in sysfs:
94 /sys/fs/fuse/connections/N/
96 where N is an increasing number allocated to each new connection.
98 For each connection the following attributes are defined:
102 The number of requests which are waiting to be transfered to
103 userspace or being processed by the filesystem daemon. If there is
104 no filesystem activity and 'waiting' is non-zero, then the
105 filesystem is hung or deadlocked.
109 Writing anything into this file will abort the filesystem
110 connection. This means that all waiting requests will be aborted an
111 error returned for all aborted and new requests.
113 Only a privileged user may read or write these attributes.
115 Aborting a filesystem connection
116 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118 It is possible to get into certain situations where the filesystem is
119 not responding. Reasons for this may be:
121 a) Broken userspace filesystem implementation
123 b) Network connection down
125 c) Accidental deadlock
127 d) Malicious deadlock
129 (For more on c) and d) see later sections)
131 In either of these cases it may be useful to abort the connection to
132 the filesystem. There are several ways to do this:
134 - Kill the filesystem daemon. Works in case of a) and b)
136 - Kill the filesystem daemon and all users of the filesystem. Works
137 in all cases except some malicious deadlocks
139 - Use forced umount (umount -f). Works in all cases but only if
140 filesystem is still attached (it hasn't been lazy unmounted)
142 - Abort filesystem through the sysfs interface. Most powerful
143 method, always works.
145 How do non-privileged mounts work?
146 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
148 Since the mount() system call is a privileged operation, a helper
149 program (fusermount) is needed, which is installed setuid root.
151 The implication of providing non-privileged mounts is that the mount
152 owner must not be able to use this capability to compromise the
153 system. Obvious requirements arising from this are:
155 A) mount owner should not be able to get elevated privileges with the
156 help of the mounted filesystem
158 B) mount owner should not get illegitimate access to information from
159 other users' and the super user's processes
161 C) mount owner should not be able to induce undesired behavior in
162 other users' or the super user's processes
164 How are requirements fulfilled?
165 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
167 A) The mount owner could gain elevated privileges by either:
169 1) creating a filesystem containing a device file, then opening
172 2) creating a filesystem containing a suid or sgid application,
173 then executing this application
175 The solution is not to allow opening device files and ignore
176 setuid and setgid bits when executing programs. To ensure this
177 fusermount always adds "nosuid" and "nodev" to the mount options
178 for non-privileged mounts.
180 B) If another user is accessing files or directories in the
181 filesystem, the filesystem daemon serving requests can record the
182 exact sequence and timing of operations performed. This
183 information is otherwise inaccessible to the mount owner, so this
184 counts as an information leak.
186 The solution to this problem will be presented in point 2) of C).
188 C) There are several ways in which the mount owner can induce
189 undesired behavior in other users' processes, such as:
191 1) mounting a filesystem over a file or directory which the mount
192 owner could otherwise not be able to modify (or could only
193 make limited modifications).
195 This is solved in fusermount, by checking the access
196 permissions on the mountpoint and only allowing the mount if
197 the mount owner can do unlimited modification (has write
198 access to the mountpoint, and mountpoint is not a "sticky"
201 2) Even if 1) is solved the mount owner can change the behavior
202 of other users' processes.
204 i) It can slow down or indefinitely delay the execution of a
205 filesystem operation creating a DoS against the user or the
206 whole system. For example a suid application locking a
207 system file, and then accessing a file on the mount owner's
208 filesystem could be stopped, and thus causing the system
209 file to be locked forever.
211 ii) It can present files or directories of unlimited length, or
212 directory structures of unlimited depth, possibly causing a
213 system process to eat up diskspace, memory or other
214 resources, again causing DoS.
216 The solution to this as well as B) is not to allow processes
217 to access the filesystem, which could otherwise not be
218 monitored or manipulated by the mount owner. Since if the
219 mount owner can ptrace a process, it can do all of the above
220 without using a FUSE mount, the same criteria as used in
221 ptrace can be used to check if a process is allowed to access
222 the filesystem or not.
224 Note that the ptrace check is not strictly necessary to
225 prevent B/2/i, it is enough to check if mount owner has enough
226 privilege to send signal to the process accessing the
227 filesystem, since SIGSTOP can be used to get a similar effect.
229 I think these limitations are unacceptable?
230 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
232 If a sysadmin trusts the users enough, or can ensure through other
233 measures, that system processes will never enter non-privileged
234 mounts, it can relax the last limitation with a "user_allow_other"
235 config option. If this config option is set, the mounting user can
236 add the "allow_other" mount option which disables the check for other
239 Kernel - userspace interface
240 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
242 The following diagram shows how a filesystem operation (in this
243 example unlink) is performed in FUSE.
245 NOTE: everything in this description is greatly simplified
247 | "rm /mnt/fuse/file" | FUSE filesystem daemon
252 | | [sleep on fc->waitq]
256 | [get request from |
259 | [queue req on fc->pending] |
260 | [wake up fc->waitq] | [woken up]
261 | >request_wait_answer() |
262 | [sleep on req->waitq] |
264 | | [remove req from fc->pending]
265 | | [copy req to read buffer]
266 | | [add req to fc->processing]
273 | | >fuse_dev_write()
274 | | [look up req in fc->processing]
275 | | [remove from fc->processing]
276 | | [copy write buffer to req]
277 | [woken up] | [wake up req->waitq]
278 | | <fuse_dev_write()
280 | <request_wait_answer() |
287 There are a couple of ways in which to deadlock a FUSE filesystem.
288 Since we are talking about unprivileged userspace programs,
289 something must be done about these.
291 Scenario 1 - Simple deadlock
292 -----------------------------
294 | "rm /mnt/fuse/file" | FUSE filesystem daemon
296 | >sys_unlink("/mnt/fuse/file") |
297 | [acquire inode semaphore |
300 | [sleep on req->waitq] |
302 | | >sys_unlink("/mnt/fuse/file")
303 | | [acquire inode semaphore
307 The solution for this is to allow requests to be interrupted while
308 they are in userspace:
310 | [interrupted by signal] |
312 | [release semaphore] | [semaphore acquired]
315 | | [queue req on fc->pending]
316 | | [wake up fc->waitq]
317 | | [sleep on req->waitq]
319 If the filesystem daemon was single threaded, this will stop here,
320 since there's no other thread to dequeue and execute the request.
321 In this case the solution is to kill the FUSE daemon as well. If
322 there are multiple serving threads, you just have to kill them as
325 Moral: a filesystem which deadlocks, can soon find itself dead.
327 Scenario 2 - Tricky deadlock
328 ----------------------------
330 This one needs a carefully crafted filesystem. It's a variation on
331 the above, only the call back to the filesystem is not explicit,
332 but is caused by a pagefault.
334 | Kamikaze filesystem thread 1 | Kamikaze filesystem thread 2
336 | [fd = open("/mnt/fuse/file")] | [request served normally]
337 | [mmap fd to 'addr'] |
338 | [close fd] | [FLUSH triggers 'magic' flag]
339 | [read a byte from addr] |
341 | [find or create page] |
344 | [queue READ request] |
345 | [sleep on req->waitq] |
346 | | [read request to buffer]
347 | | [create reply header before addr]
348 | | >sys_write(addr - headerlength)
349 | | >fuse_dev_write()
350 | | [look up req in fc->processing]
351 | | [remove from fc->processing]
352 | | [copy write buffer to req]
354 | | [find or create page]
358 Solution is again to let the the request be interrupted (not
361 An additional problem is that while the write buffer is being
362 copied to the request, the request must not be interrupted. This
363 is because the destination address of the copy may not be valid
364 after the request is interrupted.
366 This is solved with doing the copy atomically, and allowing
367 interruption while the page(s) belonging to the write buffer are
368 faulted with get_user_pages(). The 'req->locked' flag indicates
369 when the copy is taking place, and interruption is delayed until
372 Scenario 3 - Tricky deadlock with asynchronous read
373 ---------------------------------------------------
375 The same situation as above, except thread-1 will wait on page lock
376 and hence it will be uninterruptible as well. The solution is to
377 abort the connection with forced umount (if mount is attached) or
378 through the abort attribute in sysfs.