summary refs log tree commit diff
path: root/sys_util
Commit message (Collapse)AuthorAge
* sys_util: add chown wrapperStephen Barber2017-10-26
| | | | | | | | | | | BUG=none TEST=compile Change-Id: I3ae66955b48c8cd7ae2f468da8780c85fce539d2 Reviewed-on: https://chromium-review.googlesource.com/733731 Commit-Ready: Stephen Barber <smbarber@chromium.org> Tested-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* sys_util: add get_user_id and get_group_id functionsStephen Barber2017-10-26
| | | | | | | | | | | | | Add safe wrappers for getpwnam_r and getgrnam_r. BUG=none TEST=./build_test Change-Id: I737b4d264334ed788884a7320f5649cfc2266709 Reviewed-on: https://chromium-review.googlesource.com/733730 Commit-Ready: Stephen Barber <smbarber@chromium.org> Tested-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* Fix new warning with rust 1.21Dylan Reid2017-10-13
| | | | | | | | | | | Mutable references being declared mutable themselves is unnecessary and now generates a warning. Change-Id: I29c7652fb86e17a8eda21efc728dd09b726c304f Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/717733 Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* fix dependency versions and add Cargo.lockZach Reizner2017-09-20
| | | | | | | | | | | | | | | | | | | To ensure dependencies don't accidentally get updated, their versions are fixed using the equals constraint. The Cargo.lock file is also checked in so that the registry won't need to be downloaded by cargo. These changes are needed so that the crosvm ebuild will not need to download anything outside of its list of source packages. TEST=./build_test BUG=None Change-Id: Iae8472de77e3589a453685717b26fb1ceb44e257 Reviewed-on: https://chromium-review.googlesource.com/674092 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* Improve guest memory error handlingDylan Reid2017-09-11
| | | | | | | | | | | | | Pass better errors from mmap and guest_memory. These modules were written before I understood errors. Now the errors passed back to block can be propagated. Change-Id: I1842808a4114a715321c555281aacc211f23511c Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/656837 Reviewed-by: Jason Clinton <jclinton@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: add uid_map/gid_map support to jailed devicesZach Reizner2017-09-08
| | | | | | | | | | | | | | | | | | | | | This CL includes a small tweak to sys_util so that cloned processes PIDs are returned. The proxy device CHILD_SIGNATURE check was removed because it would deadlock with the synchronization that DeviceManager's post clone callback uses to wait for the id maps to be set. The check wasn't that useful to begin with. This also bumps the libc version. TEST=None BUG=None Change-Id: I881e08c9626e035044b0be1dd2e9fff3e7e61ec1 Reviewed-on: https://chromium-review.googlesource.com/634270 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: use libc's openlog to connect to syslogZach Reizner2017-09-06
| | | | | | | | | | | | | | | | | | | | | | | By using libc's openlog, we can ensure that the internal state of the libc syslogger is consistent with the syslog module. Minijail will be able to print to stderr and the syslog in the same way the logging macros in crosvm do. The FD the syslog module uses is shared with libc and via `syslog::get_fds`, jailed processes can inherit the needed FDs to continue logging. Now that `sys_log::init()` must be called in single threaded process, this moves its tests to the list of the serially run ones in build_test.py. TEST=./build_test BUG=None Change-Id: I8dbc8ebf9d97ef670185259eceac5f6d3d6824ea Reviewed-on: https://chromium-review.googlesource.com/649951 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Jason Clinton <jclinton@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* fix armv7a and aarch64 build errors and warningsZach Reizner2017-09-01
| | | | | | | | | | | | | | BUG=None TEST=cargo build --target=armv7a-cros-linux-gnueabi && cargo build --target=aarch64-cros-linux-gnu Change-Id: I954c152f3c8086e24c4809dd5aabb5043fdd63af Reviewed-on: https://chromium-review.googlesource.com/644408 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Jason Clinton <jclinton@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* fix compiler errors and warningsZach Reizner2017-08-30
| | | | | | | | | | | | | | | | | | | | | | Problems that were fixed: - gcc crate deprecated compile_library - `cargo test -p kvm` had a compile error - `cargo test -p kvm_sys` failed to link with libc - main.rs failed to include `getpid` and had dead code - fork.rs had a warning in `cargo test -p sys_util` - unused const in serial.rs BUG=None TEST=sudo cargo test -p data_model -p io_jail -p kernel_loader -p kvm \ -p kvm_sys -p net_sys -p net_util -p syscall_defines -p sys_util \ -p virtio_sys -p vhost -p x86_64 -p crosvm Change-Id: Iaf0389013fbcdfbfaa7cf37ea1a1fc045f480ada Reviewed-on: https://chromium-review.googlesource.com/642509 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Jason Clinton <jclinton@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org>
* sys_util: add safe wrappers getpid,geteuid,getguid,waitpid,killZach Reizner2017-08-28
| | | | | | | | | | | | | | | | | | These functions are trivially safe and by adding them to sys_util, we can remove some unsafe blocks from crosvm. This CL also replaces the unsafe call sites with the safe alternatives. There are no previous usages of gete{g,u}id(2), but they will be needed in a future change. TEST=None BUG=None Change-Id: Ief8787b298cfaa5b7fd1b83f0eba6660369e687d Reviewed-on: https://chromium-review.googlesource.com/634268 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* crosvm: refactor and expand vm control socket IPCZach Reizner2017-08-25
| | | | | | | | | | | | | | | | This CL adds VM request capabilities to the control socket. These requests include the basic exit as well as the essential ioeventfd and irqfd requests. For virtio wayland, the register/unregister device memory request was added. TEST=cargo test BUG=chromium:738638 Change-Id: I0cbf62d85a299cf454bcf6924a4e1d52d5b7183f Reviewed-on: https://chromium-review.googlesource.com/602593 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: add read_slice_at_addr to GuestMemoryStephen Barber2017-08-09
| | | | | | | | | | BUG=none TEST=cargo test Change-Id: Ifeda91de37bf83a2e5a00f5e308db786fa5d49d5 Signed-off-by: Stephen Barber <smbarber@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/604934 Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: allow sock_ctrl_msg to be more flexible with iovecsZach Reizner2017-08-03
| | | | | | | | | | | | | | | | Because there are more than one kind of slice (typical &[T] and VolatileSlice), the trait IntoIovec is added that any linear memory region-like type can implement. This helps to reduce the number of copies needed when dealing with volatile memory. TEST=cargo test BUG=chromium:738638 Change-Id: I86bbb693cb7a10ec85bafccf562c078167121c03 Reviewed-on: https://chromium-review.googlesource.com/599042 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: add Pollable impls for UnixDatagram and UnixStreamZach Reizner2017-08-03
| | | | | | | | | | | | | | UnixDatagram and UnixStream are both wrappers around unix domain sockets which are often polled. TEST=None BUG=chromium:738638 Change-Id: Ib5572faf1d601b89b9fdd323f654ba04650b7600 Reviewed-on: https://chromium-review.googlesource.com/599041 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: fix include in sock_ctrl_msgStephen Barber2017-07-24
| | | | | | | | | | | | close() is from unistd.h. BUG=none TEST=cargo build Change-Id: I62730c374b016118dececcfd7e2cd009f12611a7 Signed-off-by: Stephen Barber <smbarber@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/583904 Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: add sock_ctrl_msg module for transmitting messages with FDZach Reizner2017-07-20
| | | | | | | | | | | | | | | This CL also includes the gcc build time dependency for building the sock_ctrl_msg.c helper code. TEST=cargo test BUG=chromium:738638 Change-Id: I4adc2360b7fab4ed7d557603aa7bad2e738b69b4 Reviewed-on: https://chromium-review.googlesource.com/562574 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: add get_host_address for GuestMemoryStephen Barber2017-07-19
| | | | | | | | | | | Add a method get_host_address for converting a GuestAddress to a (usize) pointer in crosvm's address space. Change-Id: I6dc09e942c95204f4e53218b3250664782c8f8f9 Signed-off-by: Stephen Barber <smbarber@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/575439 Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: add ioctl moduleStephen Barber2017-07-13
| | | | | | | | | | | | | | | | Factor out common ioctl wrappers and macros into their own module. Signed-off-by: Stephen Barber <smbarber@chromium.org> BUG=none TEST=cargo test Change-Id: Ibede8a853f5cc6c6d62565930f312b11024cc5b5 Reviewed-on: https://chromium-review.googlesource.com/566540 Commit-Ready: Stephen Barber <smbarber@chromium.org> Tested-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: syslog - Scope access from within macrosDylan Reid2017-07-13
| | | | | | | | | | When syslog is used from another crate, the compiler needs a specific place to look for the symbols. Change-Id: I5ba1b7ae0e8f6825aaf2a0d0b6ff31dcab21aa0c Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/569360 Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: add signalfd moduleStephen Barber2017-07-13
| | | | | | | | | | | | | | | | Dealing with signals is unpleasant business. SignalFd wraps a kernel signalfd for a signal, and blocks the default handling for the signal. Signed-off-by: Stephen Barber <smbarber@chromium.org> BUG=none TEST=cargo test Change-Id: I161c992b65b98ffa5c07d546f13efa6b56890df4 Reviewed-on: https://chromium-review.googlesource.com/557459 Commit-Ready: Stephen Barber <smbarber@chromium.org> Tested-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: add fork module for cloning processZach Reizner2017-07-13
| | | | | | | | | | | | | | | This module is designed as a safe wrapper around clone for use by the proxy device. It includes safe guards that prevent errors with typical forking applications in rust. TEST=cargo test BUG=None Change-Id: I09132a4cae61ebdaa97ec3b95d22567c36c5f15d Reviewed-on: https://chromium-review.googlesource.com/518446 Commit-Ready: Stephen Barber <smbarber@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: add shared memory moduleZach Reizner2017-07-10
| | | | | | | | | | | | | | This CL adds the SharedMemory structure for managing memory attached to a file descriptor, which can be sent to external processes. TEST=cargo test BUG=chromium:738638 Change-Id: I2b6a10e0e7275367ddb578831a73de6956d231bb Reviewed-on: https://chromium-review.googlesource.com/562509 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: add with_regions_mut and make do_in_region pubStephen Barber2017-07-07
| | | | | | | | | | | | | | | | | | Add a new method to GuestMemory that allows running a FnMut over all regions. This will allow the virtio module to generate a vhost memory table. Also make do_in_region public, so that VHOST_NET can find the host userspace address of vrings (necessary for VHOST ioctls). BUG=none TEST=cargo build Change-Id: I43611dcc56146ed4d160f0e189b9328ca0e6d87d Reviewed-on: https://chromium-review.googlesource.com/543909 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: add syslog module for logging to syslogZach Reizner2017-07-05
| | | | | | | | | | | TEST=cargo test BUG=None Change-Id: Ia7ae04976d0ccbabd6d1656ddd9275f16cce218a Reviewed-on: https://chromium-review.googlesource.com/553741 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: remove accidental HTML from doc commentsZach Reizner2017-06-30
| | | | | | | | | | | | | | | | For some reason, the angle brackets in the comments confused doc-tests such that they hung everytime `cargo test` was run on sys_util on my machine. My theory is that the angle brackets triggered some strange HTML behavior in `cargo test`. BUG=None TEST=cd sys_util; cargo test Change-Id: Iceb81e64aecc4cc2a9397f2d1af2e64aeb8e2b5e Reviewed-on: https://chromium-review.googlesource.com/518444 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: add signal module for killing threadsZach Reizner2017-06-30
| | | | | | | | | | | | | | | | The signal module is used for registering signal handlers and for signalling threads. Normally signals would be a method of last resort, but in this case it's the only possible way to trigger a VM exit on a thread currently inside of a KVM_RUN call. BUG=None TEST=None Change-Id: If1db1e17937d1af08fc24b422c460be754cf9d22 Reviewed-on: https://chromium-review.googlesource.com/514415 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* src_util: add terminal moduleZach Reizner2017-06-30
| | | | | | | | | | | | | The terminal module is for configuring pseudo-terminals in raw mode. TEST=None BUG=None Change-Id: Ic724309e0a0f338fb3b35974643c5ab281eb525e Reviewed-on: https://chromium-review.googlesource.com/514414 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* src_util: add poll moduleZach Reizner2017-06-30
| | | | | | | | | | | | | | | | The poll module adds the Poller object for waiting on mutliple file descriptors at once. The Pollable trait is introduced so rust objects can expose a file descriptor useful for polling. An impl for EventFd is included with this change for testing. TEST=cargo test BUG=None Change-Id: I94fd15a17fe0527c0d29c623badb90668d708689 Reviewed-on: https://chromium-review.googlesource.com/514413 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: move handle_eintr!() to sys_util so it can be reusedZach Reizner2017-06-30
| | | | | | | | | | | | | | | This CL takes the handle_intr!() macro, changes its name to handle_eintr!(), and overloads it so it can handle EINTR embedded in other kinds of Result types. BUG=None TEST=cargo test Change-Id: I920ea7d9f156137f42e9e8ea44a3e6946d06b746 Reviewed-on: https://chromium-review.googlesource.com/556348 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: implement VolatileMemory for Mmap and GuestMemoryZach Reizner2017-06-27
| | | | | | | | | | | | | | Mmap and GuestMemory are the intended targets for the VolatileMemory trait. TEST=cargo test BUG=None Change-Id: Ie228b5daef691a6dcb80841be1c3dddb4b19ffc4 Reviewed-on: https://chromium-review.googlesource.com/547335 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* crosvm: add virtio block deviceZach Reizner2017-06-27
| | | | | | | | | | | | | | This device is useful for exposing a block device, for example a rootfs image, to the guest. TEST=None BUG=None Change-Id: Ida0d24ed57602f25352563893a1c85b171771c7a Reviewed-on: https://chromium-review.googlesource.com/514688 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* Limit types that can be read from guest memoryDylan Reid2017-06-27
| | | | | | | | | | | | | | | | | | | | Not all types are safe to read from guest memory. Any type with a reference or pointer will be initialized to random bits that don't refer to a valid address. This can cause dangling pointer and general unsafe behavior. To fix this, limit types that can be read with read_obj to those that implement the unsafe trait `DataInit`. Provide implementations of `DataInit` for intrinsic types that are obviously safe to initialize with random data. Implement the needed traits for bootparam types as they are read from the kernel image directly. Change-Id: I1040f5bc1b2fc4c58c87d8a2ce3f618edcf6f9b1 Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/540750 Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: Add TempDir classDylan Reid2017-06-09
| | | | | | | | | | This will be used to create temporary directories that are lifetime managed for running jails. Change-Id: I35dfeae76a211c820db090b65baf72277d9e2d8a Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/520706 Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: Add guest_memoryDylan Reid2017-05-25
| | | | | | | | | | | | | | Add a module for accessing guest memory. This module will replace all the slices that are used to access it currently as those slices aren't valid because the memory is volatile and a volatile slice doesn't exist in rust. Modify the existing users so they no longer depend on the deprecated slice access. Change-Id: Ic0e86dacf66f68bd88ed9cc197cb14e45ada891d Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/509919
* sys_util: Add conversion from errno io::Error.Zach Reizner2017-05-25
| | | | | | | | Change-Id: Ia49aa8eac1dedbc4e3f6277120bf332404e8b818 Reviewed-on: https://chromium-review.googlesource.com/509918 Commit-Ready: Dylan Reid <dgreid@chromium.org> Tested-by: Dylan Reid <dgreid@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: Add struct utilsDylan Reid2017-05-10
| | | | | | | | | | | These utilities are used for reading structs from u8 slices. Often the kernel returns pointers to void pointers that represent a struct. This helps convert back to the struct. Change-Id: I6e59fb772f3ba75f006c9370412267ff565dfe4c Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/497768 Reviewed-by: Zach Reizner <zachr@chromium.org>
* sys_util: add eventfd moduleZach Reizner2017-05-08
| | | | | | | | | | | | | | In KVM, eventfd's are essential for sending and receiving signals to the VM. This CL adds a safe wrapper around their usage. TEST=cargo test BUG=None Change-Id: I04cd9036db156bfa8b9bd49281347a2460fbff2c Reviewed-on: https://chromium-review.googlesource.com/496988 Commit-Ready: Dylan Reid <dgreid@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
* sys_util: add sys_util crate for misc system modulesZach Reizner2017-05-08
This initial commit includes an mmap wrapper. TEST=cargo test BUG=None Change-Id: I9625bd446fcd4801b2e16188897e84714b4e4ce0 Reviewed-on: https://chromium-review.googlesource.com/496987 Commit-Ready: Dylan Reid <dgreid@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>