Commit graph

985 commits

Author SHA1 Message Date
Zach Reizner
2ea297ac76 seccomp: add sendto, writev, and readv to common seccomp policies
Using syslog from glibc will use some syscalls we haven't seen before,
leading to the process getting killed. This change fixes that.

TEST=use syslog from C
BUG=chromium:988082

Change-Id: I4cfb317a8faf70188995487f4fa844229683d6d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721616
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-27 03:50:22 +00:00
Zach Reizner
92e75f0e2a gpu_display: fix use after free for the wayland socket path
Using .map in the way it was caused the CString to get moved into the closure
and then dropped by that closure. The returned pointer is then used in
dwl_context_setup after it was freed by the drop.

This change fixes that first by using .as_ref() before calling .map to
prevent the move. As an additional safeguard, some optional types were
added to the closure to make sure a reference to the CString was being
handled instead of a moved CString.

TEST=vmc start --enable-gpu termina
BUG=chromium:988082

Change-Id: I58c2c002f08688ecd85715d9cd45085dffb32457
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1721615
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-07-27 03:50:21 +00:00
Zach Reizner
f5285c647a gpu_display: add X11 backend
This change adds an X11 backend to the gpu_display crate. With this
addition, the virtio-gpu device can display to traditional linux
desktops that only have X11 output.

Change-Id: I86c80cac91ca5bdc97588194a44040273ae69385
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1591572
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Zach Reizner <zachr@chromium.org>
2019-07-25 22:15:48 +00:00
Zach Reizner
b2110bef59 tree-wide: use PollContext::build_with where possible
The old method of creating a PollContext and calling `add` inside of
`and_then` chains was an ugly way handle the Results that can crop up
after each call. The `build_with` function is equivalent but operates on
a slice which has way less boilerplate.

TEST=./build_test
BUG=None

Change-Id: I8b0d6532680e04c501187397bd211014a2363c25
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715581
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-07-24 06:07:20 +00:00
Zach Reizner
229063c2bf sys_util: poll: add build_with and add_many helper functions
These functions are wrappers around multiple `add` calls that will fail at the
first error. This replaces lots of ugly `and_then`, `and`, and `ok` calls that
had been sprinkled around the to initialize a `PollContext`.

TEST=cargo test -p sys_util
     ./build_test
BUG=None

Change-Id: I69aa1c9ad87677cf220eda57148ff8eb2268bf67
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715580
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-07-24 06:07:19 +00:00
Dylan Reid
2f0c0b3f5d sys_util: fix new warning initializing Once
"warning: use of deprecated item 'std::sync::ONCE_INIT': the `new` function is now preferred"

Change-Id: I029611f2978d5baf3b0bc426ab2285e282708da0
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715577
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-24 02:22:23 +00:00
Dylan Reid
e19cae8c6a tree-wide: Use new trait object syntax
A few places were using the old syntax without `dyn`. Nightly compilers
have started warning more aggressively, so fix up the last of those.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: I4df49b4a27a62acfd8c542cec903e4c5b31bedcc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715576
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-24 02:22:23 +00:00
Dylan Reid
c3bee1f8c3 tree-wide: update to new inclusive range syntax
1.38 nightly started warning about using `...` vs `..=`, update to avoid
the warning.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: Ibc3d24c5410b6eed9a1207db21e529ec6a763376
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1715575
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-24 02:22:21 +00:00
Dylan Reid
13c2191395 qcow: Add a zero_cluster method to raw file
Zeroing a cluster will be done from more than one place in qcow.rs soon,
add a helper to reduce duplication.

Change-Id: Idb40539f8e4ed2338fc84c0d53b37c913f2d90fe
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1697122
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-19 21:19:13 +00:00
Jorge E. Moreira
cb3ec5ed2b Refactor input devices interactions with buffers in guest memory
Input devices were using GuestMemory's read_to_memory and
write_from_memory under the (incorrect) assumption that these function
used the io::Read and io::Write traits, when they in fact use AsRawFd.

BUG=b/137138116
TEST=ran cuttlefish in workstation

Change-Id: I7ab1e2d0ab685dd25dcc91e794766c2f210665f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1700418
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
2019-07-17 22:04:23 +00:00
Jorge E. Moreira
009392ac76 Don't call UNGRAB IOCTL on a socket
That IOCTL only makes sense on devices from /dev/input

BUG=none
TEST=ran cuttlefish in workstation

Change-Id: I1aa1eea1a10db9a4d67337546782e118fceb14ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1703209
Tested-by: Jorge Moreira Broche <jemoreira@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
Auto-Submit: Jorge Moreira Broche <jemoreira@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-07-17 19:23:13 +00:00
Gurchetan Singh
ed88b0ef5e devices: gpu: advertise support for capset 3
Useful for prototyping new features.

BUG=chromium:924405
TEST=compile

Change-Id: Ibdc4a70761493939ca96b92540b9e0cca88c17a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1650290
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Auto-Submit: Gurchetan Singh <gurchetansingh@chromium.org>
2019-07-16 17:21:39 +00:00
David Tolnay
e33b55c429 tempfile: Unify the two tempdir implementations
Looks like we ended up with two totally different tempdir
implementations: one from CL:520706 and the other from CL:1409705.

This CL consolidates them into one implementation.

BUG=chromium:974059
TEST=tempfile: cargo test
TEST=crosvm: cargo check --all-features
TEST=devices: cargo check --tests
TEST=sys_util: cargo check --tests
TEST=local kokoro
TEST=./build_test

Cq-Depend: chromium:1574668
Change-Id: Id70e963c9986ed2fc5f160819c4a7f9f16092b3b
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1573227
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
2019-07-11 16:15:38 -07:00
Daniel Verkamp
8f94a9ff71 devices: silence unused code warning in PCI
Now that nothing uses the PCI-to-PCI bridge device type, the compiler
warns that it is never constructed.  Mark the PciHeaderType enum to
allow this, since the enum is public and could be constructed outside
this file.

BUG=None
TEST=./build_test

Change-Id: I6832996c4e00a33cc1ba88d97fede65b226cbfc5
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1691239
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-07-10 00:53:12 +00:00
Daniel Verkamp
9f86c7a221 seccomp: return error from socket for TPM device
The crosvm TPM process calls ssleay_rand_bytes(), which in some cases
attempts to acquire entropy through an EGD ("entropy gathering daemon")
- see OpenSSL's RAND_query_egd_bytes(). Attempting to communicate with
this daemon by creating a socket would cause the process to exit
currently because the syscall whitelist did not allow socket() or
connect().

Since we don't have an EGD and don't want to expose it to the sandboxed
TPM process anyway, modify the TPM seccomp policy to cause socket() to
return an error rather than aborting.

BUG=None
TEST=`vmc start --software-tpm termina`

Change-Id: Ib7c6bceced0f6cbe7199614ece8446aa300cec1e
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1684411
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-07-09 23:34:57 +00:00
Dylan Reid
93b0c02227 qcow: limit the size of a qcow file
There are many corner cases when handling sizes that approach u64::max.
Limit the files to 16TB.

BUG=979458
TEST=Added unittest to check large disks fail

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: I93a87c17267ae69102f8d46ced9dbea8c686d093
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1679892
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-09 17:46:22 +00:00
Dylan Reid
eecbccc4d9 qcow: Avoid overflow when taking ceiling of division
The extra % operation will be slower, but none of these divisions are in
hot paths. They are only used during setup. Many of these operations
take untrusted input from the disk file, so need to be hardened.

BUG=979458
TEST=unit tests still pass

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: I0e93c73b345faf643da53ea41bde3349d756bdc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1679891
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-09 17:46:17 +00:00
Daniel Verkamp
bb5a4f1843 devices: remove use of mem::uninitialized
mem::uninitialized is unsafe, and we already replaced most instances of
it with alternate implementations; however, another one slipped in since
then.  Replace it with Default::default() as a safe alterantive.

BUG=None
TEST=./build_test

Change-Id: Idacdcb0ebe197cc93fba4b15c3dda774bb56e73e
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1691233
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-09 17:07:51 +00:00
Daniel Verkamp
da52468b34 tempfile: reimplement using libc::mkdtemp
POSIX provides a standard mkdtemp() function to securely create a
temporary directory; use it rather than reinventing the wheel.

This also drops the dependency of tempfile on rand_ish, which will allow
easier use of the tempfile implementation outside of crosvm.

BUG=chromium:974059
TEST=cargo test -p tempfile

Change-Id: I34a226b046dc6f272106988a78d121a24a377f44
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1659971
Tested-by: kokoro <noreply+kokoro@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-07-03 16:35:43 -07:00
Daniel Verkamp
5104b9641c build_test.py: test more packages
Add a number of packages to the build_test.py list so that they are
built and tested during local development. build_test.py doesn't run in
any automated tests currently, but it's still useful for checking
whether everything still builds for multiple architectures without the
overhead of a full portage build.

BUG=None
TEST=./build_test.py

Change-Id: I6d3300ae3189311fb6faffaf10c254636adba7c1
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1682925
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-07-03 20:39:50 +00:00
Xiong Zhang
e09e470177 pci: Let device could trap pci config read/write
Currently device impliments PciDevice trait, it will return config
register to bus trait at pci cfg r/w, then BusDevice trait on behave
of device to do actual pci config r/w.

But vfio device need to handle the pci config r/w by itself, as
vfio device need to transfer this request to kernel.

For pci config read, this patch delete PciDevice->config_registers(),
and add PciDevice->read_config_register(), then BusDevice->
config_register_read() call PciDevice->read_config_register(), finally
Device could trap the PciConfig Read.

For pci config write, it is similiar with pci config read. But the
common code is moved into PciConfiguration.

BUG=none
TEST=none

Change-Id: Ie6bd3a8c94f523d6fb1ef3d1e97d087bb0407d9f
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1580457
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2019-07-03 16:56:46 +00:00
Gurchetan Singh
ad656a9d3a seccomp: whitelist read-only/write-only GPU mappings
minigbm sometimes maps buffer with only PROT_READ or only
PROT_WRITE, so allow this.

BUG=b:132939420
TEST=glxgears in container

Change-Id: Ie5ccd827dd14ee78b999d70287b7165d81c5c85e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1673533
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2019-07-03 15:41:58 +00:00
David Riley
996beb6499 virtio-gpu: Allocate buffers with shared bind flag using gbm.
BUG=chromium:972237
TEST=eglgears_wayland

Change-Id: If5a09c1ad95dfdbd47e7810c466c127c53413f21
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1657291
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Riley <davidriley@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2019-07-03 15:41:57 +00:00
David Riley
aa36a2923a gpu_renderer: update virglrenderer bindings
Results of:
  gpu_renderer/src/generated/generate --sysroot /build/$BOARD
  bin/fmt

BUG=chromium:972237
TEST=builds

Change-Id: I75063345a6cc77b54f51cfdaf244e5f73dffefcb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1657290
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: David Riley <davidriley@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
2019-07-03 15:41:55 +00:00
Gurchetan Singh
33626056f4 devices: virtio: add bindings to a new capset
This is useful for prototyping new virtgpu features (zero copy, YUV, Vulkan)
without stepping on virglrenderer's capsets.

Initially, the plan is just to transparently support zero-copy in ARCVM.

The bindings were generated from the following header:

https://gitlab.freedesktop.org/gurchetansingh/virtio-gpu-test/blob/master/virtgpu_hw.h
Generated via:

bindgen --with-derive-default virtgpu_hw.h -o virtgpu_hw.rs --no-doc-comments --no-layout-tests \
        --whitelist-type=virtgpu_.+ --whitelist-var VIRTGPU_.+ --no-prepend-enum-name

BUG=chromium:924405
TEST=compile

Change-Id: I6000244faa0d619c3ac74105713e63a52d0d9cb4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1650289
Reviewed-by: David Riley <davidriley@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2019-07-03 05:42:27 +00:00
Gurchetan Singh
ab827ab177 gpu_buffer: add ability to get backend name
This is useful for letting the guest know about host-specific
features.

BUG=chromium:924405
TEST=compile

Change-Id: I0edc4280eec7235644c9ad8561dbe063276bb3bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1650288
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
2019-07-03 05:42:25 +00:00
Zach Reizner
44863792aa main: add seccomp-log-failures flag to command line
All cros-debug versions of crosvm enabled seccomp logging, which is now
broken on kernels <4.4 thanks to new minijail changes as explained in
the referenced BUG. This seems to be intended by the minijail folks as
the aim to improve the seccomp logging in part by changing its semantics
to logging failures without killing the violating process. In such a
world, crosvm should not as a compile time choice, enable logging, which
would amount to disabling some of the security. This change adds a
command line flag to emulate the old behavior for the purposes of
developer debugging, as long as that developer is running on a kernel
that supports the new minijail seccomp filter failure logging.

BUG=chromium:978998
TEST=USE=cros-debug emerge-eve crosvm && cros deploy eve crosvm
     then start crostini in UI

Change-Id: I98190a068a919929e466fe22d6d630b90a758336
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1679380
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Auto-Submit: Zach Reizner <zachr@chromium.org>
2019-06-27 20:51:15 +00:00
Daniel Verkamp
6160e479f6 usb: switch to new libusb_wrap_sys_device API
Replace use of our custom, patched libusb APIs with the new
libusb_wrap_sys_device() function, which has been submitted to libusb
upstream. This allows us to drop the bindings for the custom APIs (and
will also allow us to drop the libusb patch that introduces them).

For now, keep this path behind the sandboxed-libusb feature to allow
crosvm to build against older libusb versions that do not have the new
API. This should be cleaned up eventually once we are comfortable with
raising the minimum libusb version required.

BUG=b:133773289
TEST=Attach Android device to Linux VM; deploy app via adb

Change-Id: Ie249c6f3f3b4c63210dd163ca7ad03e2de8a8872
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1676601
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-27 17:51:06 +00:00
Daniel Verkamp
6a8cd101b2 main: add --rwroot option to run
This allows specifying a read-write rootfs (rather than read-only as
with --root), including the automatic kernel command line additions
normally added by --root.

BUG=None
TEST=Boot crosvm with --rwroot and write to root filesystem

Change-Id: I6a3dc9176bffdefe664139cb33bf3e65a751dbf2
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1679531
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-27 17:29:53 +00:00
Daniel Verkamp
06944ec625 usb: Arm seccomp policy needs _llseek, not lseek
Since our Arm version is a 32-bit process, it uses the _llseek syscall
rather than lseek for 64-bit file offset support.  Fix the seccomp
filter to match.

Fixes a SIGSYS when attaching a USB device to Linux VM on Arm.

BUG=None
TEST=Attach USB device to kevin; verify device in `adb devices`

Change-Id: Ia46e60df17950bfbe967c4730c62ddb26fb6faa7
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1677318
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-06-27 17:07:01 +00:00
Daniel Verkamp
76199b4a05 kernel_loader: check phdr memory size addition
The mem_offset + phdr.memsz addition is using untrusted input
(phdr.memsz) and can overflow; add an explicit check to avoid panics on
invalid values.

BUG=None
TEST=/usr/libexec/fuzzers/crosvm_zimage_fuzzer in cros_fuzz shell

Change-Id: Ie6f7f27bd00958ff85201cecaa75ce2b19779b8b
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1674664
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-06-25 17:12:06 +00:00
Daniel Verkamp
6b51bd334f fuzz: zimage: use a fixed guest memory size
GuestMemory::new returns an error if the requested size is not divisible
by the page size.  The zimage fuzzer was using a GuestMemory size based
on the size of the fuzzer input; however, it doesn't necessarily make
sense to limit the guest memory to the size of the input.  Pick an
arbitrary 256 MB (matching the block fuzzer), which is also a page size
multiple to resolve the original issue.

BUG=chromium:977883
TEST=/usr/libexec/fuzzers/crosvm_zimage_fuzzer in cros_fuzz shell

Change-Id: I08c6be9d920bede18d67f8a1c5c39b9d37fb839c
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1645040
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-25 17:12:05 +00:00
Daniel Verkamp
dade4c7425 devices: pci: preserve read-only bits in write_reg
The 32-bit write_reg() function for PCI configuration space masked off
non-writable (read-only) bits from the incoming value, but it did not
preserve the original bits from the register; this results in writes to
read-only registers to clear all read-only bits to 0 instead. Preserve
the original value of the read-only bits and add a test to verify that
this works.

BUG=None
TEST=./build_test

Change-Id: Icc67b429f17d519ec4e9090f8e0ce48aaff76491
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660204
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-06-25 04:36:47 +00:00
Daniel Verkamp
5e3442e675 devices: pci: check BAR address alignment
Each PCI BAR address must be aligned to at least its own size to allow
the BAR sizing mechanism to work properly.  Add a check in add_pci_bar()
to enforce this.

BUG=None
TEST=Boot vm_kernel in crosvm

Change-Id: Iee9d866c4982bd79935337682bd50b9205b95024
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660203
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-25 04:36:46 +00:00
Daniel Verkamp
4dd6ddbc39 devices: pci: allocate BARs with correct alignment
Each PCI BAR must be aligned to at least its own size to allow the BAR
sizing mechanism to work.  Change all BAR allocations to use
allocate_with_align(), specifying the size as the alignment.

In particular, this fixes the alignment of the XHCI BAR, whose size is
larger than a page (the default MMIO allocator alignment).

BUG=None
TEST=Boot vm_kernel in crosvm

Change-Id: Icba03771a896b9b4feae608efdb7685fe24f8b98
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660202
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-06-25 04:36:45 +00:00
Xiong Zhang
c9b0ea544d devices: pci: Change host brige into Intel
For kvmgt linux guest, intel graphic driver i915 need intel host bridge
located at 0000:00.0, so this patch change the vendor id of 0000:00.0 device
to intel.

BUG=none
TEST=none

Change-Id: I52f2341d25859f2b7d4a3837f4f0c8a4b2443525
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581139
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-25 04:36:44 +00:00
Daniel Verkamp
0b4232fcd9 devices: pci: use header type 0 for host bridge
Previously, we were using header type 1 (which is meant to be used only
for PCI-to-PCI bridges), which upsets the Linux PCI probing code:

pci 0000:00:00.0: ignoring class 0x060000 (doesn't match header type 01)

Switch to the standard type 0 header instead, which makes the kernel
happy and matches what real hardware uses.

BUG=None
TEST=Boot vm_kernel (Linux 4.19) in crosvm

Change-Id: I33d10bda39edf6d949827963cebbfe66c9147ea2
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660892
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-06-25 04:36:42 +00:00
Zach Reizner
4a93a21ab3 gpu_renderer: make Box3 less error prone with constructor
The argument order of the new_2d constructor was very odd. That has been
changed to the ordinary x,y,w,h order. Also, each Box3 is checked by
is_empty() before being used, which prevents some degenerate operations
on zero area boxes.

TEST=cargo run -- run --gpu
BUG=None

Change-Id: I6954fa4846f20353517fe81028058b639752d8ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1670549
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: David Riley <davidriley@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-06-24 23:59:15 +00:00
Zach Reizner
f448721872 data_model: add sub_slice method to VolatileSlice
The new method is a copy of the get_slice trait method without the
restriction that the returned VolatileSlice has a lifetime limited to the
VolatileSlice, rather the VolatileSlice's lifetime parameter, which is
longer.

TEST=None
BUG=None

Change-Id: I1578981fcd046ce2d6232b28746c08d912c51b4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1670548
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-06-24 23:59:10 +00:00
Zach Reizner
f51787b1c7 gpu_display: fix dangling NULL pointer in dwl_context_setup
If the dwl_context_setup routine fails after creating a wayland
connection succesfully (e.g. if an extension is missing), the fail label
is jumped to in order to disconnect the wayland connection and
deallocate the wl_display structure. That label did not set
self->display to NULL after calling wl_display_disconnect, which would
cause the dwl_context_destroy routine to call wl_display_disconnect again,
which is a double free. This CL fixes that ommission.

TEST=None
BUG=None

Change-Id: I5b6c2d6fadda82dff4130bd4abb0e7764c15e004
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1668528
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
2019-06-24 23:59:06 +00:00
Jakub Staron
4aaefc377f devices: Use Reader/Writer interfaces in virtio-net.
BUG=chromium:966258
TEST=tast run ${IP} vm.CrostiniStartEverything
TEST=tast run ${IP} vm.CrostiniNetworkPerf

Change-Id: I99c5b9e564c219b76593d729fb934722fc8a3431
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1658980
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen Barber <smbarber@chromium.org>
2019-06-24 07:53:29 +00:00
Chirantan Ekbote
dd11d43473 gpu: Allow more than one resource bridge socket
Currently the wayland device accesses buffers allocated by the gpu
device via a dedicated socket connection.  Upcoming virtual devices like
vdec and camera will also need access to these buffers.  Modify the gpu
device so that it can process requests on multiple resource_bridge
sockets.

Each future device that needs access to gpu device buffers should create
a new resource bridge socket pair and add it to the list of sockets that
the gpu device monitors.

The actual interface between the devices is unchanged.

BUG=b:133381367
TEST=run glxgears in a crostini container with and without gpu enabled

Change-Id: I58693881945965071a53653bf4f86681725267d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1652876
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
2019-06-24 03:29:42 +00:00
Jakub Staron
cc91fc8252 devices: Add separate seccomp policy for pmem device
This change adds separate seccomp policy for pmem device. Previously,
pmem device was using block device seccomp policy.

BUG=None
TEST=Boot VM and run xfstests on pmem device

Change-Id: I3f25d64d4da6ad8f0ff22b285e1a7e958f545c55
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1652441
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jakub Staroń <jstaron@google.com>
2019-06-21 21:47:58 +00:00
Dylan Reid
b38bde9bd1 fuzz: Comply with new guest memory requirement for page alignment
When the input's length is not page aligned, round it up. This allows
the fuzzer to provide more random inputs without causing the `unwrap`
call to trigger false positives when creating guest memory.

BUG=chromium:972172
TEST=run fuzz case from the bug

Change-Id: Iaf8f2ba943f38b90e168301dbb8c15dee5ee45c8
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1659626
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-21 21:12:39 +00:00
Jakub Staron
d0bf5dc602 crosvm: Implement Reader/Writer interface over DescriptorChain.
This change adds a convinient interface over DescriptorChain. It hides
the complexity of DescriptorChain and allows to treat it as a pair
of read-only and write-only buffers. In the future, it will also allow
to easily support indirect descriptors.

BUG=chromium:966258
TEST=cargo test --package devices descriptor_utils
TEST=run crosvm without sandbox, share a directory, compare
checksum of shared file between host and guest

Change-Id: I9fb722ee2024c8d7d40f560571ec7d7c454bfc2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1647370
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jakub Staroń <jstaron@google.com>
2019-06-21 20:27:08 +00:00
Dylan Reid
70d7bad284 qcow: disallow crazy l1 table sizes
Before this change, a corrupt or malicious qcow file could cause crosvm
to allocate absurd amounts of memory. The fuzzer found this case,
limit the L1 table size so it can't cause issues.

BUG=chromium:974123
TEST=run fuzzer locally, add unit test

Change-Id: Ieb6db6c87f71df726b3cc9a98404581fe32fb1ce
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660890
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-21 19:22:33 +00:00
Dylan Reid
c9f254b192 qcow: Fix invalid_cluster_bits test
Start with a valid header so the invalid cluster bits field is tested in
isolation. Before this change the test would pass even if the cluster
bits check was removed from the code because the header was invalid for
other reasons.

BUG=none
TEST=this is a test

Change-Id: I5c09417ae3f974522652a50cb0fdc5dc0e10dd44
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1660889
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-06-21 19:22:31 +00:00
Jorge E. Moreira
0dfe1be88a crosvm: Ensure slices are the same size when copying.
Bug=b/135190799
TEST=run cuttlefish in debian host

Change-Id: I7f9343dd202da2a163b3e8aeb8fbde5eb4cfb1d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1659144
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Jorge Moreira Broche <jemoreira@google.com>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2019-06-21 19:12:40 +00:00
Daniel Verkamp
c62f41681c usb: update USBDEVFS_CONNINFO_EX value to new size
The layout of struct usbfs_conninfo_ex was changed in the final revision
of the patch, so the corresponding ioctl number needs to change to
match, since the parameter size is encoded in the ioctl.

The new size is 0x18 or 24, which matches the struct usbfs_conninfo_ex
layout with 7 ports.

BUG=chromium:977020
TEST=Attach Android device to Linux VM on nami

Change-Id: Iec60b4c04880d7d2c71fdea49cfdf7fb5a75f5c6
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1669530
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
2019-06-21 09:13:29 +00:00
Trent Begin
923bab011f crosvm: default serial parameter num field to 1 if not provided
If multiple serial parameters do not have `num` fields, or a different
parameter has already defined serial num 1, then crosvm will show an
error.

BUG=chromium:974885
TEST=cargo test; emerge-sarien crosvm && cros deploy dut crosvm;
Manual testing with and without num field in --serial parameter

Change-Id: Ia80247e8d055179adfd9e7471a98e8a2923cf1f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1662773
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Trent Begin <tbegin@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Trent Begin <tbegin@chromium.org>
2019-06-20 18:08:25 +00:00