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