user_mode_linux_howto_v2.rst 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. .. SPDX-License-Identifier: GPL-2.0
  2. #########
  3. UML HowTo
  4. #########
  5. .. contents:: :local:
  6. ************
  7. Introduction
  8. ************
  9. Welcome to User Mode Linux
  10. User Mode Linux is the first Open Source virtualization platform (first
  11. release date 1991) and second virtualization platform for an x86 PC.
  12. How is UML Different from a VM using Virtualization package X?
  13. ==============================================================
  14. We have come to assume that virtualization also means some level of
  15. hardware emulation. In fact, it does not. As long as a virtualization
  16. package provides the OS with devices which the OS can recognize and
  17. has a driver for, the devices do not need to emulate real hardware.
  18. Most OSes today have built-in support for a number of "fake"
  19. devices used only under virtualization.
  20. User Mode Linux takes this concept to the ultimate extreme - there
  21. is not a single real device in sight. It is 100% artificial or if
  22. we use the correct term 100% paravirtual. All UML devices are abstract
  23. concepts which map onto something provided by the host - files, sockets,
  24. pipes, etc.
  25. The other major difference between UML and various virtualization
  26. packages is that there is a distinct difference between the way the UML
  27. kernel and the UML programs operate.
  28. The UML kernel is just a process running on Linux - same as any other
  29. program. It can be run by an unprivileged user and it does not require
  30. anything in terms of special CPU features.
  31. The UML userspace, however, is a bit different. The Linux kernel on the
  32. host machine assists UML in intercepting everything the program running
  33. on a UML instance is trying to do and making the UML kernel handle all
  34. of its requests.
  35. This is different from other virtualization packages which do not make any
  36. difference between the guest kernel and guest programs. This difference
  37. results in a number of advantages and disadvantages of UML over let's say
  38. QEMU which we will cover later in this document.
  39. Why Would I Want User Mode Linux?
  40. =================================
  41. * If User Mode Linux kernel crashes, your host kernel is still fine. It
  42. is not accelerated in any way (vhost, kvm, etc) and it is not trying to
  43. access any devices directly. It is, in fact, a process like any other.
  44. * You can run a usermode kernel as a non-root user (you may need to
  45. arrange appropriate permissions for some devices).
  46. * You can run a very small VM with a minimal footprint for a specific
  47. task (for example 32M or less).
  48. * You can get extremely high performance for anything which is a "kernel
  49. specific task" such as forwarding, firewalling, etc while still being
  50. isolated from the host kernel.
  51. * You can play with kernel concepts without breaking things.
  52. * You are not bound by "emulating" hardware, so you can try weird and
  53. wonderful concepts which are very difficult to support when emulating
  54. real hardware such as time travel and making your system clock
  55. dependent on what UML does (very useful for things like tests).
  56. * It's fun.
  57. Why not to run UML
  58. ==================
  59. * The syscall interception technique used by UML makes it inherently
  60. slower for any userspace applications. While it can do kernel tasks
  61. on par with most other virtualization packages, its userspace is
  62. **slow**. The root cause is that UML has a very high cost of creating
  63. new processes and threads (something most Unix/Linux applications
  64. take for granted).
  65. * UML is strictly uniprocessor at present. If you want to run an
  66. application which needs many CPUs to function, it is clearly the
  67. wrong choice.
  68. ***********************
  69. Building a UML instance
  70. ***********************
  71. There is no UML installer in any distribution. While you can use off
  72. the shelf install media to install into a blank VM using a virtualization
  73. package, there is no UML equivalent. You have to use appropriate tools on
  74. your host to build a viable filesystem image.
  75. This is extremely easy on Debian - you can do it using debootstrap. It is
  76. also easy on OpenWRT - the build process can build UML images. All other
  77. distros - YMMV.
  78. Creating an image
  79. =================
  80. Create a sparse raw disk image::
  81. # dd if=/dev/zero of=disk_image_name bs=1 count=1 seek=16G
  82. This will create a 16G disk image. The OS will initially allocate only one
  83. block and will allocate more as they are written by UML. As of kernel
  84. version 4.19 UML fully supports TRIM (as usually used by flash drives).
  85. Using TRIM inside the UML image by specifying discard as a mount option
  86. or by running ``tune2fs -o discard /dev/ubdXX`` will request UML to
  87. return any unused blocks to the OS.
  88. Create a filesystem on the disk image and mount it::
  89. # mkfs.ext4 ./disk_image_name && mount ./disk_image_name /mnt
  90. This example uses ext4, any other filesystem such as ext3, btrfs, xfs,
  91. jfs, etc will work too.
  92. Create a minimal OS installation on the mounted filesystem::
  93. # debootstrap buster /mnt http://deb.debian.org/debian
  94. debootstrap does not set up the root password, fstab, hostname or
  95. anything related to networking. It is up to the user to do that.
  96. Set the root password - the easiest way to do that is to chroot into the
  97. mounted image::
  98. # chroot /mnt
  99. # passwd
  100. # exit
  101. Edit key system files
  102. =====================
  103. UML block devices are called ubds. The fstab created by debootstrap
  104. will be empty and it needs an entry for the root file system::
  105. /dev/ubd0 ext4 discard,errors=remount-ro 0 1
  106. The image hostname will be set to the same as the host on which you
  107. are creating its image. It is a good idea to change that to avoid
  108. "Oh, bummer, I rebooted the wrong machine".
  109. UML supports two classes of network devices - the older uml_net ones
  110. which are scheduled for obsoletion. These are called ethX. It also
  111. supports the newer vector IO devices which are significantly faster
  112. and have support for some standard virtual network encapsulations like
  113. Ethernet over GRE and Ethernet over L2TPv3. These are called vec0.
  114. Depending on which one is in use, ``/etc/network/interfaces`` will
  115. need entries like::
  116. # legacy UML network devices
  117. auto eth0
  118. iface eth0 inet dhcp
  119. # vector UML network devices
  120. auto vec0
  121. iface vec0 inet dhcp
  122. We now have a UML image which is nearly ready to run, all we need is a
  123. UML kernel and modules for it.
  124. Most distributions have a UML package. Even if you intend to use your own
  125. kernel, testing the image with a stock one is always a good start. These
  126. packages come with a set of modules which should be copied to the target
  127. filesystem. The location is distribution dependent. For Debian these
  128. reside under /usr/lib/uml/modules. Copy recursively the content of this
  129. directory to the mounted UML filesystem::
  130. # cp -rax /usr/lib/uml/modules /mnt/lib/modules
  131. If you have compiled your own kernel, you need to use the usual "install
  132. modules to a location" procedure by running::
  133. # make INSTALL_MOD_PATH=/mnt/lib/modules modules_install
  134. This will install modules into /mnt/lib/modules/$(KERNELRELEASE).
  135. To specify the full module installation path, use::
  136. # make MODLIB=/mnt/lib/modules modules_install
  137. At this point the image is ready to be brought up.
  138. *************************
  139. Setting Up UML Networking
  140. *************************
  141. UML networking is designed to emulate an Ethernet connection. This
  142. connection may be either point-to-point (similar to a connection
  143. between machines using a back-to-back cable) or a connection to a
  144. switch. UML supports a wide variety of means to build these
  145. connections to all of: local machine, remote machine(s), local and
  146. remote UML and other VM instances.
  147. +-----------+--------+------------------------------------+------------+
  148. | Transport | Type | Capabilities | Throughput |
  149. +===========+========+====================================+============+
  150. | tap | vector | checksum, tso | > 8Gbit |
  151. +-----------+--------+------------------------------------+------------+
  152. | hybrid | vector | checksum, tso, multipacket rx | > 6GBit |
  153. +-----------+--------+------------------------------------+------------+
  154. | raw | vector | checksum, tso, multipacket rx, tx" | > 6GBit |
  155. +-----------+--------+------------------------------------+------------+
  156. | EoGRE | vector | multipacket rx, tx | > 3Gbit |
  157. +-----------+--------+------------------------------------+------------+
  158. | Eol2tpv3 | vector | multipacket rx, tx | > 3Gbit |
  159. +-----------+--------+------------------------------------+------------+
  160. | bess | vector | multipacket rx, tx | > 3Gbit |
  161. +-----------+--------+------------------------------------+------------+
  162. | fd | vector | dependent on fd type | varies |
  163. +-----------+--------+------------------------------------+------------+
  164. | vde | vector | dep. on VDE VPN: Virt.Net Locator | varies |
  165. +-----------+--------+------------------------------------+------------+
  166. | tuntap | legacy | none | ~ 500Mbit |
  167. +-----------+--------+------------------------------------+------------+
  168. | daemon | legacy | none | ~ 450Mbit |
  169. +-----------+--------+------------------------------------+------------+
  170. | socket | legacy | none | ~ 450Mbit |
  171. +-----------+--------+------------------------------------+------------+
  172. | ethertap | legacy | obsolete | ~ 500Mbit |
  173. +-----------+--------+------------------------------------+------------+
  174. | vde | legacy | obsolete | ~ 500Mbit |
  175. +-----------+--------+------------------------------------+------------+
  176. * All transports which have tso and checksum offloads can deliver speeds
  177. approaching 10G on TCP streams.
  178. * All transports which have multi-packet rx and/or tx can deliver pps
  179. rates of up to 1Mps or more.
  180. * All legacy transports are generally limited to ~600-700MBit and 0.05Mps.
  181. * GRE and L2TPv3 allow connections to all of: local machine, remote
  182. machines, remote network devices and remote UML instances.
  183. * Socket allows connections only between UML instances.
  184. * Daemon and bess require running a local switch. This switch may be
  185. connected to the host as well.
  186. Network configuration privileges
  187. ================================
  188. The majority of the supported networking modes need ``root`` privileges.
  189. For example, in the legacy tuntap networking mode, users were required
  190. to be part of the group associated with the tunnel device.
  191. For newer network drivers like the vector transports, ``root`` privilege
  192. is required to fire an ioctl to setup the tun interface and/or use
  193. raw sockets where needed.
  194. This can be achieved by granting the user a particular capability instead
  195. of running UML as root. In case of vector transport, a user can add the
  196. capability ``CAP_NET_ADMIN`` or ``CAP_NET_RAW`` to the uml binary.
  197. Thenceforth, UML can be run with normal user privilges, along with
  198. full networking.
  199. For example::
  200. # sudo setcap cap_net_raw,cap_net_admin+ep linux
  201. Configuring vector transports
  202. ===============================
  203. All vector transports support a similar syntax:
  204. If X is the interface number as in vec0, vec1, vec2, etc, the general
  205. syntax for options is::
  206. vecX:transport="Transport Name",option=value,option=value,...,option=value
  207. Common options
  208. --------------
  209. These options are common for all transports:
  210. * ``depth=int`` - sets the queue depth for vector IO. This is the
  211. amount of packets UML will attempt to read or write in a single
  212. system call. The default number is 64 and is generally sufficient
  213. for most applications that need throughput in the 2-4 Gbit range.
  214. Higher speeds may require larger values.
  215. * ``mac=XX:XX:XX:XX:XX`` - sets the interface MAC address value.
  216. * ``gro=[0,1]`` - sets GRO off or on. Enables receive/transmit offloads.
  217. The effect of this option depends on the host side support in the transport
  218. which is being configured. In most cases it will enable TCP segmentation and
  219. RX/TX checksumming offloads. The setting must be identical on the host side
  220. and the UML side. The UML kernel will produce warnings if it is not.
  221. For example, GRO is enabled by default on local machine interfaces
  222. (e.g. veth pairs, bridge, etc), so it should be enabled in UML in the
  223. corresponding UML transports (raw, tap, hybrid) in order for networking to
  224. operate correctly.
  225. * ``mtu=int`` - sets the interface MTU
  226. * ``headroom=int`` - adjusts the default headroom (32 bytes) reserved
  227. if a packet will need to be re-encapsulated into for instance VXLAN.
  228. * ``vec=0`` - disable multipacket IO and fall back to packet at a
  229. time mode
  230. Shared Options
  231. --------------
  232. * ``ifname=str`` Transports which bind to a local network interface
  233. have a shared option - the name of the interface to bind to.
  234. * ``src, dst, src_port, dst_port`` - all transports which use sockets
  235. which have the notion of source and destination and/or source port
  236. and destination port use these to specify them.
  237. * ``v6=[0,1]`` to specify if a v6 connection is desired for all
  238. transports which operate over IP. Additionally, for transports that
  239. have some differences in the way they operate over v4 and v6 (for example
  240. EoL2TPv3), sets the correct mode of operation. In the absence of this
  241. option, the socket type is determined based on what do the src and dst
  242. arguments resolve/parse to.
  243. tap transport
  244. -------------
  245. Example::
  246. vecX:transport=tap,ifname=tap0,depth=128,gro=1
  247. This will connect vec0 to tap0 on the host. Tap0 must already exist (for example
  248. created using tunctl) and UP.
  249. tap0 can be configured as a point-to-point interface and given an IP
  250. address so that UML can talk to the host. Alternatively, it is possible
  251. to connect UML to a tap interface which is connected to a bridge.
  252. While tap relies on the vector infrastructure, it is not a true vector
  253. transport at this point, because Linux does not support multi-packet
  254. IO on tap file descriptors for normal userspace apps like UML. This
  255. is a privilege which is offered only to something which can hook up
  256. to it at kernel level via specialized interfaces like vhost-net. A
  257. vhost-net like helper for UML is planned at some point in the future.
  258. Privileges required: tap transport requires either:
  259. * tap interface to exist and be created persistent and owned by the
  260. UML user using tunctl. Example ``tunctl -u uml-user -t tap0``
  261. * binary to have ``CAP_NET_ADMIN`` privilege
  262. hybrid transport
  263. ----------------
  264. Example::
  265. vecX:transport=hybrid,ifname=tap0,depth=128,gro=1
  266. This is an experimental/demo transport which couples tap for transmit
  267. and a raw socket for receive. The raw socket allows multi-packet
  268. receive resulting in significantly higher packet rates than normal tap.
  269. Privileges required: hybrid requires ``CAP_NET_RAW`` capability by
  270. the UML user as well as the requirements for the tap transport.
  271. raw socket transport
  272. --------------------
  273. Example::
  274. vecX:transport=raw,ifname=p-veth0,depth=128,gro=1
  275. This transport uses vector IO on raw sockets. While you can bind to any
  276. interface including a physical one, the most common use it to bind to
  277. the "peer" side of a veth pair with the other side configured on the
  278. host.
  279. Example host configuration for Debian:
  280. **/etc/network/interfaces**::
  281. auto veth0
  282. iface veth0 inet static
  283. address 192.168.4.1
  284. netmask 255.255.255.252
  285. broadcast 192.168.4.3
  286. pre-up ip link add veth0 type veth peer name p-veth0 && \
  287. ifconfig p-veth0 up
  288. UML can now bind to p-veth0 like this::
  289. vec0:transport=raw,ifname=p-veth0,depth=128,gro=1
  290. If the UML guest is configured with 192.168.4.2 and netmask 255.255.255.0
  291. it can talk to the host on 192.168.4.1
  292. The raw transport also provides some support for offloading some of the
  293. filtering to the host. The two options to control it are:
  294. * ``bpffile=str`` filename of raw bpf code to be loaded as a socket filter
  295. * ``bpfflash=int`` 0/1 allow loading of bpf from inside User Mode Linux.
  296. This option allows the use of the ethtool load firmware command to
  297. load bpf code.
  298. In either case the bpf code is loaded into the host kernel. While this is
  299. presently limited to legacy bpf syntax (not ebpf), it is still a security
  300. risk. It is not recommended to allow this unless the User Mode Linux
  301. instance is considered trusted.
  302. Privileges required: raw socket transport requires `CAP_NET_RAW`
  303. capability.
  304. GRE socket transport
  305. --------------------
  306. Example::
  307. vecX:transport=gre,src=$src_host,dst=$dst_host
  308. This will configure an Ethernet over ``GRE`` (aka ``GRETAP`` or
  309. ``GREIRB``) tunnel which will connect the UML instance to a ``GRE``
  310. endpoint at host dst_host. ``GRE`` supports the following additional
  311. options:
  312. * ``rx_key=int`` - GRE 32-bit integer key for rx packets, if set,
  313. ``txkey`` must be set too
  314. * ``tx_key=int`` - GRE 32-bit integer key for tx packets, if set
  315. ``rx_key`` must be set too
  316. * ``sequence=[0,1]`` - enable GRE sequence
  317. * ``pin_sequence=[0,1]`` - pretend that the sequence is always reset
  318. on each packet (needed to interoperate with some really broken
  319. implementations)
  320. * ``v6=[0,1]`` - force IPv4 or IPv6 sockets respectively
  321. * GRE checksum is not presently supported
  322. GRE has a number of caveats:
  323. * You can use only one GRE connection per IP address. There is no way to
  324. multiplex connections as each GRE tunnel is terminated directly on
  325. the UML instance.
  326. * The key is not really a security feature. While it was intended as such
  327. its "security" is laughable. It is, however, a useful feature to
  328. ensure that the tunnel is not misconfigured.
  329. An example configuration for a Linux host with a local address of
  330. 192.168.128.1 to connect to a UML instance at 192.168.129.1
  331. **/etc/network/interfaces**::
  332. auto gt0
  333. iface gt0 inet static
  334. address 10.0.0.1
  335. netmask 255.255.255.0
  336. broadcast 10.0.0.255
  337. mtu 1500
  338. pre-up ip link add gt0 type gretap local 192.168.128.1 \
  339. remote 192.168.129.1 || true
  340. down ip link del gt0 || true
  341. Additionally, GRE has been tested versus a variety of network equipment.
  342. Privileges required: GRE requires ``CAP_NET_RAW``
  343. l2tpv3 socket transport
  344. -----------------------
  345. _Warning_. L2TPv3 has a "bug". It is the "bug" known as "has more
  346. options than GNU ls". While it has some advantages, there are usually
  347. easier (and less verbose) ways to connect a UML instance to something.
  348. For example, most devices which support L2TPv3 also support GRE.
  349. Example::
  350. vec0:transport=l2tpv3,udp=1,src=$src_host,dst=$dst_host,srcport=$src_port,dstport=$dst_port,depth=128,rx_session=0xffffffff,tx_session=0xffff
  351. This will configure an Ethernet over L2TPv3 fixed tunnel which will
  352. connect the UML instance to a L2TPv3 endpoint at host $dst_host using
  353. the L2TPv3 UDP flavour and UDP destination port $dst_port.
  354. L2TPv3 always requires the following additional options:
  355. * ``rx_session=int`` - l2tpv3 32-bit integer session for rx packets
  356. * ``tx_session=int`` - l2tpv3 32-bit integer session for tx packets
  357. As the tunnel is fixed these are not negotiated and they are
  358. preconfigured on both ends.
  359. Additionally, L2TPv3 supports the following optional parameters.
  360. * ``rx_cookie=int`` - l2tpv3 32-bit integer cookie for rx packets - same
  361. functionality as GRE key, more to prevent misconfiguration than provide
  362. actual security
  363. * ``tx_cookie=int`` - l2tpv3 32-bit integer cookie for tx packets
  364. * ``cookie64=[0,1]`` - use 64-bit cookies instead of 32-bit.
  365. * ``counter=[0,1]`` - enable l2tpv3 counter
  366. * ``pin_counter=[0,1]`` - pretend that the counter is always reset on
  367. each packet (needed to interoperate with some really broken
  368. implementations)
  369. * ``v6=[0,1]`` - force v6 sockets
  370. * ``udp=[0,1]`` - use raw sockets (0) or UDP (1) version of the protocol
  371. L2TPv3 has a number of caveats:
  372. * you can use only one connection per IP address in raw mode. There is
  373. no way to multiplex connections as each L2TPv3 tunnel is terminated
  374. directly on the UML instance. UDP mode can use different ports for
  375. this purpose.
  376. Here is an example of how to configure a Linux host to connect to UML
  377. via L2TPv3:
  378. **/etc/network/interfaces**::
  379. auto l2tp1
  380. iface l2tp1 inet static
  381. address 192.168.126.1
  382. netmask 255.255.255.0
  383. broadcast 192.168.126.255
  384. mtu 1500
  385. pre-up ip l2tp add tunnel remote 127.0.0.1 \
  386. local 127.0.0.1 encap udp tunnel_id 2 \
  387. peer_tunnel_id 2 udp_sport 1706 udp_dport 1707 && \
  388. ip l2tp add session name l2tp1 tunnel_id 2 \
  389. session_id 0xffffffff peer_session_id 0xffffffff
  390. down ip l2tp del session tunnel_id 2 session_id 0xffffffff && \
  391. ip l2tp del tunnel tunnel_id 2
  392. Privileges required: L2TPv3 requires ``CAP_NET_RAW`` for raw IP mode and
  393. no special privileges for the UDP mode.
  394. BESS socket transport
  395. ---------------------
  396. BESS is a high performance modular network switch.
  397. https://github.com/NetSys/bess
  398. It has support for a simple sequential packet socket mode which in the
  399. more recent versions is using vector IO for high performance.
  400. Example::
  401. vecX:transport=bess,src=$unix_src,dst=$unix_dst
  402. This will configure a BESS transport using the unix_src Unix domain
  403. socket address as source and unix_dst socket address as destination.
  404. For BESS configuration and how to allocate a BESS Unix domain socket port
  405. please see the BESS documentation.
  406. https://github.com/NetSys/bess/wiki/Built-In-Modules-and-Ports
  407. BESS transport does not require any special privileges.
  408. VDE vector transport
  409. --------------------
  410. Virtual Distributed Ethernet (VDE) is a project whose main goal is to provide a
  411. highly flexible support for virtual networking.
  412. http://wiki.virtualsquare.org/#/tutorials/vdebasics
  413. Common usages of VDE include fast prototyping and teaching.
  414. Examples:
  415. ``vecX:transport=vde,vnl=tap://tap0``
  416. use tap0
  417. ``vecX:transport=vde,vnl=slirp://``
  418. use slirp
  419. ``vec0:transport=vde,vnl=vde:///tmp/switch``
  420. connect to a vde switch
  421. ``vecX:transport=\"vde,vnl=cmd://ssh remote.host //tmp/sshlirp\"``
  422. connect to a remote slirp (instant VPN: convert ssh to VPN, it uses sshlirp)
  423. https://github.com/virtualsquare/sshlirp
  424. ``vec0:transport=vde,vnl=vxvde://234.0.0.1``
  425. connect to a local area cloud (all the UML nodes using the same
  426. multicast address running on hosts in the same multicast domain (LAN)
  427. will be automagically connected together to a virtual LAN.
  428. Configuring Legacy transports
  429. =============================
  430. Legacy transports are now considered obsolete. Please use the vector
  431. versions.
  432. ***********
  433. Running UML
  434. ***********
  435. This section assumes that either the user-mode-linux package from the
  436. distribution or a custom built kernel has been installed on the host.
  437. These add an executable called linux to the system. This is the UML
  438. kernel. It can be run just like any other executable.
  439. It will take most normal linux kernel arguments as command line
  440. arguments. Additionally, it will need some UML-specific arguments
  441. in order to do something useful.
  442. Arguments
  443. =========
  444. Mandatory Arguments:
  445. --------------------
  446. * ``mem=int[K,M,G]`` - amount of memory. By default in bytes. It will
  447. also accept K, M or G qualifiers.
  448. * ``ubdX[s,d,c,t]=`` virtual disk specification. This is not really
  449. mandatory, but it is likely to be needed in nearly all cases so we can
  450. specify a root file system.
  451. The simplest possible image specification is the name of the image
  452. file for the filesystem (created using one of the methods described
  453. in `Creating an image`_).
  454. * UBD devices support copy on write (COW). The changes are kept in
  455. a separate file which can be discarded allowing a rollback to the
  456. original pristine image. If COW is desired, the UBD image is
  457. specified as: ``cow_file,master_image``.
  458. Example:``ubd0=Filesystem.cow,Filesystem.img``
  459. * UBD devices can be set to use synchronous IO. Any writes are
  460. immediately flushed to disk. This is done by adding ``s`` after
  461. the ``ubdX`` specification.
  462. * UBD performs some heuristics on devices specified as a single
  463. filename to make sure that a COW file has not been specified as
  464. the image. To turn them off, use the ``d`` flag after ``ubdX``.
  465. * UBD supports TRIM - asking the Host OS to reclaim any unused
  466. blocks in the image. To turn it off, specify the ``t`` flag after
  467. ``ubdX``.
  468. * ``root=`` root device - most likely ``/dev/ubd0`` (this is a Linux
  469. filesystem image)
  470. Important Optional Arguments
  471. ----------------------------
  472. If UML is run as "linux" with no extra arguments, it will try to start an
  473. xterm for every console configured inside the image (up to 6 in most
  474. Linux distributions). Each console is started inside an
  475. xterm. This makes it nice and easy to use UML on a host with a GUI. It is,
  476. however, the wrong approach if UML is to be used as a testing harness or run
  477. in a text-only environment.
  478. In order to change this behaviour we need to specify an alternative console
  479. and wire it to one of the supported "line" channels. For this we need to map a
  480. console to use something different from the default xterm.
  481. Example which will divert console number 1 to stdin/stdout::
  482. con1=fd:0,fd:1
  483. UML supports a wide variety of serial line channels which are specified using
  484. the following syntax
  485. conX=channel_type:options[,channel_type:options]
  486. If the channel specification contains two parts separated by comma, the first
  487. one is input, the second one output.
  488. * The null channel - Discard all input or output. Example ``con=null`` will set
  489. all consoles to null by default.
  490. * The fd channel - use file descriptor numbers for input/output. Example:
  491. ``con1=fd:0,fd:1.``
  492. * The port channel - start a telnet server on TCP port number. Example:
  493. ``con1=port:4321``. The host must have /usr/sbin/in.telnetd (usually part of
  494. a telnetd package) and the port-helper from the UML utilities (see the
  495. information for the xterm channel below). UML will not boot until a client
  496. connects.
  497. * The pty and pts channels - use system pty/pts.
  498. * The tty channel - bind to an existing system tty. Example: ``con1=/dev/tty8``
  499. will make UML use the host 8th console (usually unused).
  500. * The xterm channel - this is the default - bring up an xterm on this channel
  501. and direct IO to it. Note that in order for xterm to work, the host must
  502. have the UML distribution package installed. This usually contains the
  503. port-helper and other utilities needed for UML to communicate with the xterm.
  504. Alternatively, these need to be complied and installed from source. All
  505. options applicable to consoles also apply to UML serial lines which are
  506. presented as ttyS inside UML.
  507. Starting UML
  508. ============
  509. We can now run UML.
  510. ::
  511. # linux mem=2048M umid=TEST \
  512. ubd0=Filesystem.img \
  513. vec0:transport=tap,ifname=tap0,depth=128,gro=1 \
  514. root=/dev/ubda con=null con0=null,fd:2 con1=fd:0,fd:1
  515. This will run an instance with ``2048M RAM`` and try to use the image file
  516. called ``Filesystem.img`` as root. It will connect to the host using tap0.
  517. All consoles except ``con1`` will be disabled and console 1 will
  518. use standard input/output making it appear in the same terminal it was started.
  519. Logging in
  520. ============
  521. If you have not set up a password when generating the image, you will have to
  522. shut down the UML instance, mount the image, chroot into it and set it - as
  523. described in the Generating an Image section. If the password is already set,
  524. you can just log in.
  525. The UML Management Console
  526. ============================
  527. In addition to managing the image from "the inside" using normal sysadmin tools,
  528. it is possible to perform a number of low-level operations using the UML
  529. management console. The UML management console is a low-level interface to the
  530. kernel on a running UML instance, somewhat like the i386 SysRq interface. Since
  531. there is a full-blown operating system under UML, there is much greater
  532. flexibility possible than with the SysRq mechanism.
  533. There are a number of things you can do with the mconsole interface:
  534. * get the kernel version
  535. * add and remove devices
  536. * halt or reboot the machine
  537. * Send SysRq commands
  538. * Pause and resume the UML
  539. * Inspect processes running inside UML
  540. * Inspect UML internal /proc state
  541. You need the mconsole client (uml\_mconsole) which is a part of the UML
  542. tools package available in most Linux distritions.
  543. You also need ``CONFIG_MCONSOLE`` (under 'General Setup') enabled in the UML
  544. kernel. When you boot UML, you'll see a line like::
  545. mconsole initialized on /home/jdike/.uml/umlNJ32yL/mconsole
  546. If you specify a unique machine id on the UML command line, i.e.
  547. ``umid=debian``, you'll see this::
  548. mconsole initialized on /home/jdike/.uml/debian/mconsole
  549. That file is the socket that uml_mconsole will use to communicate with
  550. UML. Run it with either the umid or the full path as its argument::
  551. # uml_mconsole debian
  552. or
  553. # uml_mconsole /home/jdike/.uml/debian/mconsole
  554. You'll get a prompt, at which you can run one of these commands:
  555. * version
  556. * help
  557. * halt
  558. * reboot
  559. * config
  560. * remove
  561. * sysrq
  562. * help
  563. * cad
  564. * stop
  565. * go
  566. * proc
  567. * stack
  568. version
  569. -------
  570. This command takes no arguments. It prints the UML version::
  571. (mconsole) version
  572. OK Linux OpenWrt 4.14.106 #0 Tue Mar 19 08:19:41 2019 x86_64
  573. There are a couple actual uses for this. It's a simple no-op which
  574. can be used to check that a UML is running. It's also a way of
  575. sending a device interrupt to the UML. UML mconsole is treated internally as
  576. a UML device.
  577. help
  578. ----
  579. This command takes no arguments. It prints a short help screen with the
  580. supported mconsole commands.
  581. halt and reboot
  582. ---------------
  583. These commands take no arguments. They shut the machine down immediately, with
  584. no syncing of disks and no clean shutdown of userspace. So, they are
  585. pretty close to crashing the machine::
  586. (mconsole) halt
  587. OK
  588. config
  589. ------
  590. "config" adds a new device to the virtual machine. This is supported
  591. by most UML device drivers. It takes one argument, which is the
  592. device to add, with the same syntax as the kernel command line::
  593. (mconsole) config ubd3=/home/jdike/incoming/roots/root_fs_debian22
  594. remove
  595. ------
  596. "remove" deletes a device from the system. Its argument is just the
  597. name of the device to be removed. The device must be idle in whatever
  598. sense the driver considers necessary. In the case of the ubd driver,
  599. the removed block device must not be mounted, swapped on, or otherwise
  600. open, and in the case of the network driver, the device must be down::
  601. (mconsole) remove ubd3
  602. sysrq
  603. -----
  604. This command takes one argument, which is a single letter. It calls the
  605. generic kernel's SysRq driver, which does whatever is called for by
  606. that argument. See the SysRq documentation in
  607. Documentation/admin-guide/sysrq.rst in your favorite kernel tree to
  608. see what letters are valid and what they do.
  609. cad
  610. ---
  611. This invokes the ``Ctl-Alt-Del`` action in the running image. What exactly
  612. this ends up doing is up to init, systemd, etc. Normally, it reboots the
  613. machine.
  614. stop
  615. ----
  616. This puts the UML in a loop reading mconsole requests until a 'go'
  617. mconsole command is received. This is very useful as a
  618. debugging/snapshotting tool.
  619. go
  620. --
  621. This resumes a UML after being paused by a 'stop' command. Note that
  622. when the UML has resumed, TCP connections may have timed out and if
  623. the UML is paused for a long period of time, crond might go a little
  624. crazy, running all the jobs it didn't do earlier.
  625. proc
  626. ----
  627. This takes one argument - the name of a file in /proc which is printed
  628. to the mconsole standard output
  629. stack
  630. -----
  631. This takes one argument - the pid number of a process. Its stack is
  632. printed to a standard output.
  633. *******************
  634. Advanced UML Topics
  635. *******************
  636. Sharing Filesystems between Virtual Machines
  637. ============================================
  638. Don't attempt to share filesystems simply by booting two UMLs from the
  639. same file. That's the same thing as booting two physical machines
  640. from a shared disk. It will result in filesystem corruption.
  641. Using layered block devices
  642. ---------------------------
  643. The way to share a filesystem between two virtual machines is to use
  644. the copy-on-write (COW) layering capability of the ubd block driver.
  645. Any changed blocks are stored in the private COW file, while reads come
  646. from either device - the private one if the requested block is valid in
  647. it, the shared one if not. Using this scheme, the majority of data
  648. which is unchanged is shared between an arbitrary number of virtual
  649. machines, each of which has a much smaller file containing the changes
  650. that it has made. With a large number of UMLs booting from a large root
  651. filesystem, this leads to a huge disk space saving.
  652. Sharing file system data will also help performance, since the host will
  653. be able to cache the shared data using a much smaller amount of memory,
  654. so UML disk requests will be served from the host's memory rather than
  655. its disks. There is a major caveat in doing this on multisocket NUMA
  656. machines. On such hardware, running many UML instances with a shared
  657. master image and COW changes may cause issues like NMIs from excess of
  658. inter-socket traffic.
  659. If you are running UML on high-end hardware like this, make sure to
  660. bind UML to a set of logical CPUs residing on the same socket using the
  661. ``taskset`` command or have a look at the "tuning" section.
  662. To add a copy-on-write layer to an existing block device file, simply
  663. add the name of the COW file to the appropriate ubd switch::
  664. ubd0=root_fs_cow,root_fs_debian_22
  665. where ``root_fs_cow`` is the private COW file and ``root_fs_debian_22`` is
  666. the existing shared filesystem. The COW file need not exist. If it
  667. doesn't, the driver will create and initialize it.
  668. Disk Usage
  669. ----------
  670. UML has TRIM support which will release any unused space in its disk
  671. image files to the underlying OS. It is important to use either ls -ls
  672. or du to verify the actual file size.
  673. COW validity.
  674. -------------
  675. Any changes to the master image will invalidate all COW files. If this
  676. happens, UML will *NOT* automatically delete any of the COW files and
  677. will refuse to boot. In this case the only solution is to either
  678. restore the old image (including its last modified timestamp) or remove
  679. all COW files which will result in their recreation. Any changes in
  680. the COW files will be lost.
  681. Cows can moo - uml_moo : Merging a COW file with its backing file
  682. -----------------------------------------------------------------
  683. Depending on how you use UML and COW devices, it may be advisable to
  684. merge the changes in the COW file into the backing file every once in
  685. a while.
  686. The utility that does this is uml_moo. Its usage is::
  687. uml_moo COW_file new_backing_file
  688. There's no need to specify the backing file since that information is
  689. already in the COW file header. If you're paranoid, boot the new
  690. merged file, and if you're happy with it, move it over the old backing
  691. file.
  692. ``uml_moo`` creates a new backing file by default as a safety measure.
  693. It also has a destructive merge option which will merge the COW file
  694. directly into its current backing file. This is really only usable
  695. when the backing file only has one COW file associated with it. If
  696. there are multiple COWs associated with a backing file, a -d merge of
  697. one of them will invalidate all of the others. However, it is
  698. convenient if you're short of disk space, and it should also be
  699. noticeably faster than a non-destructive merge.
  700. ``uml_moo`` is installed with the UML distribution packages and is
  701. available as a part of UML utilities.
  702. Host file access
  703. ==================
  704. If you want to access files on the host machine from inside UML, you
  705. can treat it as a separate machine and either nfs mount directories
  706. from the host or copy files into the virtual machine with scp.
  707. However, since UML is running on the host, it can access those
  708. files just like any other process and make them available inside the
  709. virtual machine without the need to use the network.
  710. This is possible with the hostfs virtual filesystem. With it, you
  711. can mount a host directory into the UML filesystem and access the
  712. files contained in it just as you would on the host.
  713. *SECURITY WARNING*
  714. Hostfs without any parameters to the UML Image will allow the image
  715. to mount any part of the host filesystem and write to it. Always
  716. confine hostfs to a specific "harmless" directory (for example ``/var/tmp``)
  717. if running UML. This is especially important if UML is being run as root.
  718. Using hostfs
  719. ------------
  720. To begin with, make sure that hostfs is available inside the virtual
  721. machine with::
  722. # cat /proc/filesystems
  723. ``hostfs`` should be listed. If it's not, either rebuild the kernel
  724. with hostfs configured into it or make sure that hostfs is built as a
  725. module and available inside the virtual machine, and insmod it.
  726. Now all you need to do is run mount::
  727. # mount none /mnt/host -t hostfs
  728. will mount the host's ``/`` on the virtual machine's ``/mnt/host``.
  729. If you don't want to mount the host root directory, then you can
  730. specify a subdirectory to mount with the -o switch to mount::
  731. # mount none /mnt/home -t hostfs -o /home
  732. will mount the host's /home on the virtual machine's /mnt/home.
  733. hostfs as the root filesystem
  734. -----------------------------
  735. It's possible to boot from a directory hierarchy on the host using
  736. hostfs rather than using the standard filesystem in a file.
  737. To start, you need that hierarchy. The easiest way is to loop mount
  738. an existing root_fs file::
  739. # mount root_fs uml_root_dir -o loop
  740. You need to change the filesystem type of ``/`` in ``etc/fstab`` to be
  741. 'hostfs', so that line looks like this::
  742. /dev/ubd/0 / hostfs defaults 1 1
  743. Then you need to chown to yourself all the files in that directory
  744. that are owned by root. This worked for me::
  745. # find . -uid 0 -exec chown jdike {} \;
  746. Next, make sure that your UML kernel has hostfs compiled in, not as a
  747. module. Then run UML with the boot device pointing at that directory::
  748. ubd0=/path/to/uml/root/directory
  749. UML should then boot as it does normally.
  750. Hostfs Caveats
  751. --------------
  752. Hostfs does not support keeping track of host filesystem changes on the
  753. host (outside UML). As a result, if a file is changed without UML's
  754. knowledge, UML will not know about it and its own in-memory cache of
  755. the file may be corrupt. While it is possible to fix this, it is not
  756. something which is being worked on at present.
  757. Tuning UML
  758. ============
  759. UML at present is strictly uniprocessor. It will, however spin up a
  760. number of threads to handle various functions.
  761. The UBD driver, SIGIO and the MMU emulation do that. If the system is
  762. idle, these threads will be migrated to other processors on a SMP host.
  763. This, unfortunately, will usually result in LOWER performance because of
  764. all of the cache/memory synchronization traffic between cores. As a
  765. result, UML will usually benefit from being pinned on a single CPU,
  766. especially on a large system. This can result in performance differences
  767. of 5 times or higher on some benchmarks.
  768. Similarly, on large multi-node NUMA systems UML will benefit if all of
  769. its memory is allocated from the same NUMA node it will run on. The
  770. OS will *NOT* do that by default. In order to do that, the sysadmin
  771. needs to create a suitable tmpfs ramdisk bound to a particular node
  772. and use that as the source for UML RAM allocation by specifying it
  773. in the TMP or TEMP environment variables. UML will look at the values
  774. of ``TMPDIR``, ``TMP`` or ``TEMP`` for that. If that fails, it will
  775. look for shmfs mounted under ``/dev/shm``. If everything else fails use
  776. ``/tmp/`` regardless of the filesystem type used for it::
  777. mount -t tmpfs -ompol=bind:X none /mnt/tmpfs-nodeX
  778. TEMP=/mnt/tmpfs-nodeX taskset -cX linux options options options..
  779. *******************************************
  780. Contributing to UML and Developing with UML
  781. *******************************************
  782. UML is an excellent platform to develop new Linux kernel concepts -
  783. filesystems, devices, virtualization, etc. It provides unrivalled
  784. opportunities to create and test them without being constrained to
  785. emulating specific hardware.
  786. Example - want to try how Linux will work with 4096 "proper" network
  787. devices?
  788. Not an issue with UML. At the same time, this is something which
  789. is difficult with other virtualization packages - they are
  790. constrained by the number of devices allowed on the hardware bus
  791. they are trying to emulate (for example 16 on a PCI bus in qemu).
  792. If you have something to contribute such as a patch, a bugfix, a
  793. new feature, please send it to ``linux-um@lists.infradead.org``.
  794. Please follow all standard Linux patch guidelines such as cc-ing
  795. relevant maintainers and run ``./scripts/checkpatch.pl`` on your patch.
  796. For more details see ``Documentation/process/submitting-patches.rst``
  797. Note - the list does not accept HTML or attachments, all emails must
  798. be formatted as plain text.
  799. Developing always goes hand in hand with debugging. First of all,
  800. you can always run UML under gdb and there will be a whole section
  801. later on on how to do that. That, however, is not the only way to
  802. debug a Linux kernel. Quite often adding tracing statements and/or
  803. using UML specific approaches such as ptracing the UML kernel process
  804. are significantly more informative.
  805. Tracing UML
  806. =============
  807. When running, UML consists of a main kernel thread and a number of
  808. helper threads. The ones of interest for tracing are NOT the ones
  809. that are already ptraced by UML as a part of its MMU emulation.
  810. These are usually the first three threads visible in a ps display.
  811. The one with the lowest PID number and using most CPU is usually the
  812. kernel thread. The other threads are the disk
  813. (ubd) device helper thread and the SIGIO helper thread.
  814. Running ptrace on this thread usually results in the following picture::
  815. host$ strace -p 16566
  816. --- SIGIO {si_signo=SIGIO, si_code=POLL_IN, si_band=65} ---
  817. epoll_wait(4, [{EPOLLIN, {u32=3721159424, u64=3721159424}}], 64, 0) = 1
  818. epoll_wait(4, [], 64, 0) = 0
  819. rt_sigreturn({mask=[PIPE]}) = 16967
  820. ptrace(PTRACE_GETREGS, 16967, NULL, 0xd5f34f38) = 0
  821. ptrace(PTRACE_GETREGSET, 16967, NT_X86_XSTATE, [{iov_base=0xd5f35010, iov_len=832}]) = 0
  822. ptrace(PTRACE_GETSIGINFO, 16967, NULL, {si_signo=SIGTRAP, si_code=0x85, si_pid=16967, si_uid=0}) = 0
  823. ptrace(PTRACE_SETREGS, 16967, NULL, 0xd5f34f38) = 0
  824. ptrace(PTRACE_SETREGSET, 16967, NT_X86_XSTATE, [{iov_base=0xd5f35010, iov_len=2696}]) = 0
  825. ptrace(PTRACE_SYSEMU, 16967, NULL, 0) = 0
  826. --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_TRAPPED, si_pid=16967, si_uid=0, si_status=SIGTRAP, si_utime=65, si_stime=89} ---
  827. wait4(16967, [{WIFSTOPPED(s) && WSTOPSIG(s) == SIGTRAP | 0x80}], WSTOPPED|__WALL, NULL) = 16967
  828. ptrace(PTRACE_GETREGS, 16967, NULL, 0xd5f34f38) = 0
  829. ptrace(PTRACE_GETREGSET, 16967, NT_X86_XSTATE, [{iov_base=0xd5f35010, iov_len=832}]) = 0
  830. ptrace(PTRACE_GETSIGINFO, 16967, NULL, {si_signo=SIGTRAP, si_code=0x85, si_pid=16967, si_uid=0}) = 0
  831. timer_settime(0, 0, {it_interval={tv_sec=0, tv_nsec=0}, it_value={tv_sec=0, tv_nsec=2830912}}, NULL) = 0
  832. getpid() = 16566
  833. clock_nanosleep(CLOCK_MONOTONIC, 0, {tv_sec=1, tv_nsec=0}, NULL) = ? ERESTART_RESTARTBLOCK (Interrupted by signal)
  834. --- SIGALRM {si_signo=SIGALRM, si_code=SI_TIMER, si_timerid=0, si_overrun=0, si_value={int=1631716592, ptr=0x614204f0}} ---
  835. rt_sigreturn({mask=[PIPE]}) = -1 EINTR (Interrupted system call)
  836. This is a typical picture from a mostly idle UML instance.
  837. * UML interrupt controller uses epoll - this is UML waiting for IO
  838. interrupts:
  839. epoll_wait(4, [{EPOLLIN, {u32=3721159424, u64=3721159424}}], 64, 0) = 1
  840. * The sequence of ptrace calls is part of MMU emulation and running the
  841. UML userspace.
  842. * ``timer_settime`` is part of the UML high res timer subsystem mapping
  843. timer requests from inside UML onto the host high resolution timers.
  844. * ``clock_nanosleep`` is UML going into idle (similar to the way a PC
  845. will execute an ACPI idle).
  846. As you can see UML will generate quite a bit of output even in idle. The output
  847. can be very informative when observing IO. It shows the actual IO calls, their
  848. arguments and returns values.
  849. Kernel debugging
  850. ================
  851. You can run UML under gdb now, though it will not necessarily agree to
  852. be started under it. If you are trying to track a runtime bug, it is
  853. much better to attach gdb to a running UML instance and let UML run.
  854. Assuming the same PID number as in the previous example, this would be::
  855. # gdb -p 16566
  856. This will STOP the UML instance, so you must enter `cont` at the GDB
  857. command line to request it to continue. It may be a good idea to make
  858. this into a gdb script and pass it to gdb as an argument.
  859. Developing Device Drivers
  860. =========================
  861. Nearly all UML drivers are monolithic. While it is possible to build a
  862. UML driver as a kernel module, that limits the possible functionality
  863. to in-kernel only and non-UML specific. The reason for this is that
  864. in order to really leverage UML, one needs to write a piece of
  865. userspace code which maps driver concepts onto actual userspace host
  866. calls.
  867. This forms the so-called "user" portion of the driver. While it can
  868. reuse a lot of kernel concepts, it is generally just another piece of
  869. userspace code. This portion needs some matching "kernel" code which
  870. resides inside the UML image and which implements the Linux kernel part.
  871. *Note: There are very few limitations in the way "kernel" and "user" interact*.
  872. UML does not have a strictly defined kernel-to-host API. It does not
  873. try to emulate a specific architecture or bus. UML's "kernel" and
  874. "user" can share memory, code and interact as needed to implement
  875. whatever design the software developer has in mind. The only
  876. limitations are purely technical. Due to a lot of functions and
  877. variables having the same names, the developer should be careful
  878. which includes and libraries they are trying to refer to.
  879. As a result a lot of userspace code consists of simple wrappers.
  880. E.g. ``os_close_file()`` is just a wrapper around ``close()``
  881. which ensures that the userspace function close does not clash
  882. with similarly named function(s) in the kernel part.
  883. Using UML as a Test Platform
  884. ============================
  885. UML is an excellent test platform for device driver development. As
  886. with most things UML, "some user assembly may be required". It is
  887. up to the user to build their emulation environment. UML at present
  888. provides only the kernel infrastructure.
  889. Part of this infrastructure is the ability to load and parse fdt
  890. device tree blobs as used in Arm or Open Firmware platforms. These
  891. are supplied as an optional extra argument to the kernel command
  892. line::
  893. dtb=filename
  894. The device tree is loaded and parsed at boottime and is accessible by
  895. drivers which query it. At this moment in time this facility is
  896. intended solely for development purposes. UML's own devices do not
  897. query the device tree.
  898. Security Considerations
  899. -----------------------
  900. Drivers or any new functionality should default to not
  901. accepting arbitrary filename, bpf code or other parameters
  902. which can affect the host from inside the UML instance.
  903. For example, specifying the socket used for IPC communication
  904. between a driver and the host at the UML command line is OK
  905. security-wise. Allowing it as a loadable module parameter
  906. isn't.
  907. If such functionality is desirable for a particular application
  908. (e.g. loading BPF "firmware" for raw socket network transports),
  909. it should be off by default and should be explicitly turned on
  910. as a command line parameter at startup.
  911. Even with this in mind, the level of isolation between UML
  912. and the host is relatively weak. If the UML userspace is
  913. allowed to load arbitrary kernel drivers, an attacker can
  914. use this to break out of UML. Thus, if UML is used in
  915. a production application, it is recommended that all modules
  916. are loaded at boot and kernel module loading is disabled
  917. afterwards.