1VIRTIOFSD(1) QEMU VIRTIOFSD(1)
2
3
4
6 virtiofsd - QEMU virtio-fs shared file system daemon
7
9 virtiofsd [OPTIONS]
10
12 Share a host directory tree with a guest through a virtio-fs device.
13 This program is a vhost-user backend that implements the virtio-fs de‐
14 vice. Each virtio-fs device instance requires its own virtiofsd
15 process.
16
17 This program is designed to work with QEMU's --device vhost-user-fs-pci
18 but should work with any virtual machine monitor (VMM) that supports
19 vhost-user. See the Examples section below.
20
21 This program must be run as the root user. The program drops privi‐
22 leges where possible during startup although it must be able to create
23 and access files with any uid/gid:
24
25 • The ability to invoke syscalls is limited using seccomp(2).
26
27 • Linux capabilities(7) are dropped.
28
29 In "namespace" sandbox mode the program switches into a new file system
30 namespace and invokes pivot_root(2) to make the shared directory tree
31 its root. A new pid and net namespace is also created to isolate the
32 process.
33
34 In "chroot" sandbox mode the program invokes chroot(2) to make the
35 shared directory tree its root. This mode is intended for container en‐
36 vironments where the container runtime has already set up the name‐
37 spaces and the program does not have permission to create namespaces
38 itself.
39
40 Both sandbox modes prevent "file system escapes" due to symlinks and
41 other file system objects that might lead to files outside the shared
42 directory.
43
45 -h, --help
46 Print help.
47
48 -V, --version
49 Print version.
50
51 -d Enable debug output.
52
53 --syslog
54 Print log messages to syslog instead of stderr.
55
56 -o OPTION
57
58 • debug - Enable debug output.
59
60 • flock|no_flock - Enable/disable flock. The default is
61 no_flock.
62
63 • modcaps=CAPLIST Modify the list of capabilities allowed;
64 CAPLIST is a colon separated list of capabilities, each pre‐
65 ceded by either + or -, e.g. ''+sys_admin:-chown''.
66
67 • log_level=LEVEL - Print only log messages matching LEVEL or
68 more severe. LEVEL is one of err, warn, info, or debug. The
69 default is info.
70
71 • posix_lock|no_posix_lock - Enable/disable remote POSIX locks.
72 The default is no_posix_lock.
73
74 • readdirplus|no_readdirplus - Enable/disable readdirplus. The
75 default is readdirplus.
76
77 • sandbox=namespace|chroot - Sandbox mode: - namespace: Create
78 mount, pid, and net namespaces and pivot_root(2) into the
79 shared directory. - chroot: chroot(2) into shared directory
80 (use in containers). The default is "namespace".
81
82 • source=PATH - Share host directory tree located at PATH. This
83 option is required.
84
85 • timeout=TIMEOUT - I/O timeout in seconds. The default depends
86 on cache= option.
87
88 • writeback|no_writeback - Enable/disable writeback cache. The
89 cache allows the FUSE client to buffer and merge write re‐
90 quests. The default is no_writeback.
91
92 • xattr|no_xattr - Enable/disable extended attributes (xattr) on
93 files and directories. The default is no_xattr.
94
95 • posix_acl|no_posix_acl - Enable/disable posix acl support.
96 Posix ACLs are disabled by default.
97
98 --socket-path=PATH
99 Listen on vhost-user UNIX domain socket at PATH.
100
101 --socket-group=GROUP
102 Set the vhost-user UNIX domain socket gid to GROUP.
103
104 --fd=FDNUM
105 Accept connections from vhost-user UNIX domain socket file de‐
106 scriptor FDNUM. The file descriptor must already be listening
107 for connections.
108
109 --thread-pool-size=NUM
110 Restrict the number of worker threads per request queue to NUM.
111 The default is 64.
112
113 --cache=none|auto|always
114 Select the desired trade-off between coherency and performance.
115 none forbids the FUSE client from caching to achieve best co‐
116 herency at the cost of performance. auto acts similar to NFS
117 with a 1 second metadata cache timeout. always sets a long
118 cache lifetime at the expense of coherency. The default is
119 auto.
120
122 By default the name of xattr's used by the client are passed through to
123 the server file system. This can be a problem where either those xattr
124 names are used by something on the server (e.g. selinux client/server
125 confusion) or if the virtiofsd is running in a container with re‐
126 stricted privileges where it cannot access some attributes.
127
128 Mapping syntax
129 A mapping of xattr names can be made using -o xattrmap=mapping where
130 the mapping string consists of a series of rules.
131
132 The first matching rule terminates the mapping. The set of rules must
133 include a terminating rule to match any remaining attributes at the
134 end.
135
136 Each rule consists of a number of fields separated with a separator
137 that is the first non-white space character in the rule. This separa‐
138 tor must then be used for the whole rule. White space may be added be‐
139 fore and after each rule.
140
141 Using ':' as the separator a rule is of the form:
142
143 :type:scope:key:prepend:
144
145 scope is:
146
147 •
148
149 'client' - match 'key' against a xattr name from the client for
150 setxattr/getxattr/removexattr
151
152 •
153
154 'server' - match 'prepend' against a xattr name from the server
155 for listxattr
156
157 •
158
159 'all' - can be used to make a single rule where both the server
160 and client matches are triggered.
161
162 type is one of:
163
164 • 'prefix' - is designed to prepend and strip a prefix; the modified
165 attributes then being passed on to the client/server.
166
167 • 'ok' - Causes the rule set to be terminated when a match is found
168 while allowing matching xattr's through unchanged. It is intended
169 both as a way of explicitly terminating the list of rules, and to al‐
170 low some xattr's to skip following rules.
171
172 • 'bad' - If a client tries to use a name matching 'key' it's denied
173 using EPERM; when the server passes an attribute name matching
174 'prepend' it's hidden. In many ways it's use is very like 'ok' as
175 either an explicit terminator or for special handling of certain pat‐
176 terns.
177
178 key is a string tested as a prefix on an attribute name originating on
179 the client. It maybe empty in which case a 'client' rule will always
180 match on client names.
181
182 prepend is a string tested as a prefix on an attribute name originating
183 on the server, and used as a new prefix. It may be empty in which case
184 a 'server' rule will always match on all names from the server.
185
186 e.g.:
187 :prefix:client:trusted.:user.virtiofs.:
188
189 will match 'trusted.' attributes in client calls and prefix them be‐
190 fore passing them to the server.
191
192 :prefix:server::user.virtiofs.:
193
194 will strip 'user.virtiofs.' from all server replies.
195
196 :prefix:all:trusted.:user.virtiofs.:
197
198 combines the previous two cases into a single rule.
199
200 :ok:client:user.::
201
202 will allow get/set xattr for 'user.' xattr's and ignore following
203 rules.
204
205 :ok:server::security.:
206
207 will pass 'securty.' xattr's in listxattr from the server and ignore
208 following rules.
209
210 :ok:all:::
211
212 will terminate the rule search passing any remaining attributes in
213 both directions.
214
215 :bad:server::security.:
216
217 would hide 'security.' xattr's in listxattr from the server.
218
219 A simpler 'map' type provides a shorter syntax for the common case:
220
221 :map:key:prepend:
222
223 The 'map' type adds a number of separate rules to add prepend as a pre‐
224 fix to the matched key (or all attributes if key is empty). There may
225 be at most one 'map' rule and it must be the last rule in the set.
226
227 Note: When the 'security.capability' xattr is remapped, the daemon has
228 to do extra work to remove it during many operations, which the host
229 kernel normally does itself.
230
231 Security considerations
232 Operating systems typically partition the xattr namespace using well
233 defined name prefixes. Each partition may have different access con‐
234 trols applied. For example, on Linux there are multiple partitions
235
236 • system.* - access varies depending on attribute & filesystem
237
238 • security.* - only processes with CAP_SYS_ADMIN
239
240 • trusted.* - only processes with CAP_SYS_ADMIN
241
242 • user.* - any process granted by file permissions / ownership
243
244 While other OS such as FreeBSD have different name prefixes and access
245 control rules.
246
247 When remapping attributes on the host, it is important to ensure that
248 the remapping does not allow a guest user to evade the guest access
249 control rules.
250
251 Consider if trusted.* from the guest was remapped to user.vir‐
252 tiofs.trusted* in the host. An unprivileged user in a Linux guest has
253 the ability to write to xattrs under user.*. Thus the user can evade
254 the access control restriction on trusted.* by instead writing to
255 user.virtiofs.trusted.*.
256
257 As noted above, the partitions used and access controls applied, will
258 vary across guest OS, so it is not wise to try to predict what the
259 guest OS will use.
260
261 The simplest way to avoid an insecure configuration is to remap all
262 xattrs at once, to a given fixed prefix. This is shown in example (1)
263 below.
264
265 If selectively mapping only a subset of xattr prefixes, then rules must
266 be added to explicitly block direct access to the target of the remap‐
267 ping. This is shown in example (2) below.
268
269 Mapping examples
270 1. Prefix all attributes with 'user.virtiofs.'
271
272 -o xattrmap=":prefix:all::user.virtiofs.::bad:all:::"
273
274 This uses two rules, using : as the field separator; the first rule
275 prefixes and strips 'user.virtiofs.', the second rule hides any
276 non-prefixed attributes that the host set.
277
278 This is equivalent to the 'map' rule:
279
280 -o xattrmap=":map::user.virtiofs.:"
281
282 2. Prefix 'trusted.' attributes, allow others through
283
284 "/prefix/all/trusted./user.virtiofs./
285 /bad/server//trusted./
286 /bad/client/user.virtiofs.//
287 /ok/all///"
288
289 Here there are four rules, using / as the field separator, and also
290 demonstrating that new lines can be included between rules. The first
291 rule is the prefixing of 'trusted.' and stripping of 'user.virtiofs.'.
292 The second rule hides unprefixed 'trusted.' attributes on the host.
293 The third rule stops a guest from explicitly setting the 'user.vir‐
294 tiofs.' path directly to prevent access control bypass on the target of
295 the earlier prefix remapping. Finally, the fourth rule lets all re‐
296 maining attributes through.
297
298 This is equivalent to the 'map' rule:
299
300 -o xattrmap="/map/trusted./user.virtiofs./"
301
302 3. Hide 'security.' attributes, and allow everything else
303
304 "/bad/all/security./security./
305 /ok/all///'
306
307 The first rule combines what could be separate client and server rules
308 into a single 'all' rule, matching 'security.' in either client argu‐
309 ments or lists returned from the host. This stops the client seeing
310 any 'security.' attributes on the server and stops it setting any.
311
313 Export /var/lib/fs/vm001/ on vhost-user UNIX domain socket
314 /var/run/vm001-vhost-fs.sock:
315
316 host# virtiofsd --socket-path=/var/run/vm001-vhost-fs.sock -o source=/var/lib/fs/vm001
317 host# qemu-system-x86_64 \
318 -chardev socket,id=char0,path=/var/run/vm001-vhost-fs.sock \
319 -device vhost-user-fs-pci,chardev=char0,tag=myfs \
320 -object memory-backend-memfd,id=mem,size=4G,share=on \
321 -numa node,memdev=mem \
322 ...
323 guest# mount -t virtiofs myfs /mnt
324
326 Stefan Hajnoczi <stefanha@redhat.com>, Masayoshi Mizuma
327 <m.mizuma@jp.fujitsu.com>
328
330 2021, The QEMU Project Developers
331
332
333
334
3356.1.0 Nov 08, 2021 VIRTIOFSD(1)