|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | - | - |
| aarch64/ | | 03-May-2024 | - | 939 | 708 |
| arch/ | | 03-May-2024 | - | 709 | 529 |
| assertions/ | | 03-May-2024 | - | 99 | 39 |
| bin/ | | 03-May-2024 | - | 119 | 59 |
| bit_field/ | | 03-May-2024 | - | 1,325 | 830 |
| crosvm_plugin/ | | 03-May-2024 | - | 2,264 | 1,648 |
| data_model/ | | 03-May-2024 | - | 888 | 516 |
| devices/ | | 03-May-2024 | - | 28,772 | 23,379 |
| docker/ | | 03-May-2024 | - | 324 | 242 |
| enumn/ | | 03-May-2024 | - | 308 | 181 |
| fuzz/ | | 03-May-2024 | - | 249 | 176 |
| gpu_buffer/ | | 03-May-2024 | - | 1,283 | 973 |
| gpu_display/ | | 03-May-2024 | - | 3,278 | 2,718 |
| gpu_renderer/ | | 03-May-2024 | - | 34,574 | 34,006 |
| io_jail/ | | 03-May-2024 | - | 876 | 729 |
| kernel_cmdline/ | | 03-May-2024 | - | 255 | 195 |
| kernel_loader/ | | 03-May-2024 | - | 599 | 523 |
| kokoro/ | | 03-May-2024 | - | 160 | 105 |
| kvm/ | | 03-May-2024 | - | 2,613 | 1,943 |
| kvm_sys/ | | 03-May-2024 | - | 15,612 | 15,532 |
| msg_socket/ | | 03-May-2024 | - | 1,565 | 1,336 |
| net_sys/ | | 03-May-2024 | - | 2,873 | 2,817 |
| net_util/ | | 03-May-2024 | - | 671 | 473 |
| p9/ | | 03-May-2024 | - | 2,883 | 2,364 |
| protos/ | | 03-May-2024 | - | 652 | 489 |
| qcow/ | | 03-May-2024 | - | 3,094 | 2,514 |
| qcow_utils/ | | 03-May-2024 | - | 557 | 436 |
| rand_ish/ | | 03-May-2024 | - | 91 | 66 |
| render_node_forward/ | | 03-May-2024 | - | 73 | 50 |
| resources/ | | 03-May-2024 | - | 667 | 475 |
| seccomp/ | | 03-May-2024 | - | 711 | 631 |
| src/ | | 03-May-2024 | - | 5,870 | 4,881 |
| sync/ | | 03-May-2024 | - | 216 | 109 |
| sys_util/ | | 03-May-2024 | - | 8,370 | 5,547 |
| syscall_defines/ | | 03-May-2024 | - | 1,492 | 1,452 |
| tempfile/ | | 03-May-2024 | - | 97 | 65 |
| tests/ | | 03-May-2024 | - | 2,427 | 1,926 |
| tpm2/ | | 03-May-2024 | - | 233 | 66 |
| tpm2-sys/ | | 03-May-2024 | - | 82 | 60 |
| usb_util/ | | 03-May-2024 | - | 6,182 | 5,149 |
| vhost/ | | 03-May-2024 | - | 703 | 496 |
| virtio_sys/ | | 03-May-2024 | - | 2,244 | 2,207 |
| vm_control/ | | 03-May-2024 | - | 493 | 378 |
| x86_64/ | | 03-May-2024 | - | 4,321 | 3,713 |
| .dockerignore | D | 03-May-2024 | 30 | 5 | 4 |
| .gitignore | D | 03-May-2024 | 68 | 7 | 6 |
| .gitmodules | D | 03-May-2024 | 125 | 4 | 3 |
| .rustfmt.toml | D | 03-May-2024 | 57 | 3 | 2 |
| Android.bp | D | 03-May-2024 | 2.1 KiB | 93 | 86 |
| Cargo.lock | D | 03-May-2024 | 15.9 KiB | 605 | 541 |
| Cargo.toml | D | 03-May-2024 | 2.3 KiB | 84 | 75 |
| LICENSE | D | 03-May-2024 | 1.5 KiB | 28 | 27 |
| OWNERS | D | 03-May-2024 | 98 | 6 | 5 |
| README.md | D | 03-May-2024 | 8.3 KiB | 190 | 143 |
| build_test | D | 03-May-2024 | 6.9 KiB | 238 | 175 |
| build_test.py | D | 03-May-2024 | 6.9 KiB | 238 | 175 |
| rust-toolchain | D | 03-May-2024 | 7 | 2 | 1 |
README.md
1# crosvm - The Chrome OS Virtual Machine Monitor
2
3This component, known as crosvm, runs untrusted operating systems along with
4virtualized devices. No actual hardware is emulated. This only runs VMs
5through the Linux's KVM interface. What makes crosvm unique is a focus on
6safety within the programming language and a sandbox around the virtual
7devices to protect the kernel from attack in case of an exploit in the
8devices.
9
10## Building with Docker
11
12See the [README](docker/README.md) from the `docker` subdirectory to learn how
13to build crosvm in enviroments outside of the Chrome OS chroot.
14
15## Usage
16
17To see the usage information for your version of crosvm, run `crosvm` or `crosvm
18run --help`.
19
20### Boot a Kernel
21
22To run a very basic VM with just a kernel and default devices:
23
24```bash
25$ crosvm run "${KERNEL_PATH}"
26```
27
28The uncompressed kernel image, also known as vmlinux, can be found in your kernel
29build directory in the case of x86 at `arch/x86/boot/compressed/vmlinux`.
30
31### Rootfs
32
33In most cases, you will want to give the VM a virtual block device to use as a
34root file system:
35
36```bash
37$ crosvm run -r "${ROOT_IMAGE}" "${KERNEL_PATH}"
38```
39
40The root image must be a path to a disk image formatted in a way that the kernel
41can read. Typically this is a squashfs image made with `mksquashfs` or an ext4
42image made with `mkfs.ext4`. By using the `-r` argument, the kernel is
43automatically told to use that image as the root, and therefore can only be
44given once. More disks can be given with `-d` or `--rwdisk` if a writable disk
45is desired.
46
47To run crosvm with a writable rootfs:
48
49>**WARNING:** Writable disks are at risk of corruption by a malicious or
50malfunctioning guest OS.
51```bash
52crosvm run --rwdisk "${ROOT_IMAGE}" -p "root=/dev/vda" vmlinux
53```
54>**NOTE:** If more disks arguments are added prior to the desired rootfs image,
55the `root=/dev/vda` must be adjusted to the appropriate letter.
56
57### Control Socket
58
59If the control socket was enabled with `-s`, the main process can be controlled
60while crosvm is running. To tell crosvm to stop and exit, for example:
61
62>**NOTE:** If the socket path given is for a directory, a socket name underneath
63that path will be generated based on crosvm's PID.
64```bash
65$ crosvm run -s /run/crosvm.sock ${USUAL_CROSVM_ARGS}
66 <in another shell>
67$ crosvm stop /run/crosvm.sock
68```
69>**WARNING:** The guest OS will not be notified or gracefully shutdown.
70
71This will cause the original crosvm process to exit in an orderly fashion,
72allowing it to clean up any OS resources that might have stuck around if crosvm
73were terminated early.
74
75### Multiprocess Mode
76
77By default crosvm runs in multiprocess mode. Each device that supports running
78inside of a sandbox will run in a jailed child process of crosvm. The
79appropriate minijail seccomp policy files must be present either in
80`/usr/share/policy/crosvm` or in the path specified by the
81`--seccomp-policy-dir` argument. The sandbox can be disabled for testing with
82the `--disable-sandbox` option.
83
84### Virtio Wayland
85
86Virtio Wayland support requires special support on the part of the guest and as
87such is unlikely to work out of the box unless you are using a Chrome OS kernel
88along with a `termina` rootfs.
89
90To use it, ensure that the `XDG_RUNTIME_DIR` enviroment variable is set and that
91the path `$XDG_RUNTIME_DIR/wayland-0` points to the socket of the Wayland
92compositor you would like the guest to use.
93
94## Defaults
95
96The following are crosvm's default arguments and how to override them.
97
98* 256MB of memory (set with `-m`)
99* 1 virtual CPU (set with `-c`)
100* no block devices (set with `-r`, `-d`, or `--rwdisk`)
101* no network (set with `--host_ip`, `--netmask`, and `--mac`)
102* virtio wayland support if `XDG_RUNTIME_DIR` enviroment variable is set (disable with `--no-wl`)
103* only the kernel arguments necessary to run with the supported devices (add more with `-p`)
104* run in multiprocess mode (run in single process mode with `--disable-sandbox`)
105* no control socket (set with `-s`)
106
107## System Requirements
108
109A Linux kernel with KVM support (check for `/dev/kvm`) is required to run
110crosvm. In order to run certain devices, there are additional system
111requirements:
112
113* `virtio-wayland` - The `memfd_create` syscall, introduced in Linux 3.17, and a Wayland compositor.
114* `vsock` - Host Linux kernel with vhost-vsock support, introduced in Linux 4.8.
115* `multiprocess` - Host Linux kernel with seccomp-bpf and Linux namespacing support.
116* `virtio-net` - Host Linux kernel with TUN/TAP support (check for `/dev/net/tun`) and running with `CAP_NET_ADMIN` privileges.
117
118## Emulated Devices
119
120| Device | Description |
121|------------------|------------------------------------------------------------------------------------|
122| `CMOS/RTC` | Used to get the current calendar time. |
123| `i8042` | Used by the guest kernel to exit crosvm. |
124| `serial` | x86 I/O port driven serial devices that print to stdout and take input from stdin. |
125| `virtio-block` | Basic read/write block device. |
126| `virtio-net` | Device to interface the host and guest networks. |
127| `virtio-rng` | Entropy source used to seed guest OS's entropy pool. |
128| `virtio-vsock` | Enabled VSOCKs for the guests. |
129| `virtio-wayland` | Allowed guest to use host Wayland socket. |
130
131## Contributing
132
133### Code Health
134
135#### `build_test`
136
137There are no automated tests run before code is committed to crosvm. In order to
138maintain sanity, please execute `build_test` before submitting code for review.
139All tests should be passing or ignored and there should be no compiler warnings
140or errors. All supported architectures are built, but only tests for x86_64 are
141run. In order to build everything without failures, sysroots must be supplied
142for each architecture. See `build_test -h` for more information.
143
144#### `rustfmt`
145
146All code should be formatted with `rustfmt`. We have a script that applies
147rustfmt to all Rust code in the crosvm repo: please run `bin/fmt` before
148checking in a change. This is different from `cargo fmt --all` which formats
149multiple crates but a single workspace only; crosvm consists of multiple
150workspaces.
151
152#### Dependencies
153
154With a few exceptions, external dependencies inside of the `Cargo.toml` files
155are not allowed. The reason being that community made crates tend to explode the
156binary size by including dozens of transitive dependencies. All these
157dependencies also must be reviewed to ensure their suitability to the crosvm
158project. Currently allowed crates are:
159
160* `byteorder` - A very small library used for endian swaps.
161* `cc` - Build time dependency needed to build C source code used in crosvm.
162* `libc` - Required to use the standard library, this crate is a simple wrapper around `libc`'s symbols.
163
164### Code Overview
165
166The crosvm source code is written in Rust and C. To build, crosvm generally
167requires the most recent stable version of rustc.
168
169Source code is organized into crates, each with their own unit tests. These
170crates are:
171
172* `crosvm` - The top-level binary front-end for using crosvm.
173* `devices` - Virtual devices exposed to the guest OS.
174* `io_jail` - Creates jailed process using `libminijail`.
175* `kernel_loader` - Loads elf64 kernel files to a slice of memory.
176* `kvm_sys` - Low-level (mostly) auto-generated structures and constants for using KVM.
177* `kvm` - Unsafe, low-level wrapper code for using `kvm_sys`.
178* `net_sys` - Low-level (mostly) auto-generated structures and constants for creating TUN/TAP devices.
179* `net_util` - Wrapper for creating TUN/TAP devices.
180* `sys_util` - Mostly safe wrappers for small system facilities such as `eventfd` or `syslog`.
181* `syscall_defines` - Lists of syscall numbers in each architecture used to make syscalls not supported in `libc`.
182* `vhost` - Wrappers for creating vhost based devices.
183* `virtio_sys` - Low-level (mostly) auto-generated structures and constants for interfacing with kernel vhost support.
184* `vm_control` - IPC for the VM.
185* `x86_64` - Support code specific to 64 bit intel machines.
186
187The `seccomp` folder contains minijail seccomp policy files for each sandboxed
188device. Because some syscalls vary by architecture, the seccomp policies are
189split by architecture.
190