• Home
Name Date Size #Lines LOC

..--

aarch64/03-May-2024-939708

arch/03-May-2024-709529

assertions/03-May-2024-9939

bin/03-May-2024-11959

bit_field/03-May-2024-1,325830

crosvm_plugin/03-May-2024-2,2641,648

data_model/03-May-2024-888516

devices/03-May-2024-28,77223,379

docker/03-May-2024-324242

enumn/03-May-2024-308181

fuzz/03-May-2024-249176

gpu_buffer/03-May-2024-1,283973

gpu_display/03-May-2024-3,2782,718

gpu_renderer/03-May-2024-34,57434,006

io_jail/03-May-2024-876729

kernel_cmdline/03-May-2024-255195

kernel_loader/03-May-2024-599523

kokoro/03-May-2024-160105

kvm/03-May-2024-2,6131,943

kvm_sys/03-May-2024-15,61215,532

msg_socket/03-May-2024-1,5651,336

net_sys/03-May-2024-2,8732,817

net_util/03-May-2024-671473

p9/03-May-2024-2,8832,364

protos/03-May-2024-652489

qcow/03-May-2024-3,0942,514

qcow_utils/03-May-2024-557436

rand_ish/03-May-2024-9166

render_node_forward/03-May-2024-7350

resources/03-May-2024-667475

seccomp/03-May-2024-711631

src/03-May-2024-5,8704,881

sync/03-May-2024-216109

sys_util/03-May-2024-8,3705,547

syscall_defines/03-May-2024-1,4921,452

tempfile/03-May-2024-9765

tests/03-May-2024-2,4271,926

tpm2/03-May-2024-23366

tpm2-sys/03-May-2024-8260

usb_util/03-May-2024-6,1825,149

vhost/03-May-2024-703496

virtio_sys/03-May-2024-2,2442,207

vm_control/03-May-2024-493378

x86_64/03-May-2024-4,3213,713

.dockerignoreD03-May-202430 54

.gitignoreD03-May-202468 76

.gitmodulesD03-May-2024125 43

.rustfmt.tomlD03-May-202457 32

Android.bpD03-May-20242.1 KiB9386

Cargo.lockD03-May-202415.9 KiB605541

Cargo.tomlD03-May-20242.3 KiB8475

LICENSED03-May-20241.5 KiB2827

OWNERSD03-May-202498 65

README.mdD03-May-20248.3 KiB190143

build_testD03-May-20246.9 KiB238175

build_test.pyD03-May-20246.9 KiB238175

rust-toolchainD03-May-20247 21

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