diff options
author | Jingkui Wang <jkwang@google.com> | 2018-12-04 13:08:31 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-12-20 13:49:37 -0800 |
commit | 7df5a0ef1a23542b0cc7db7797b8b287eaa05699 (patch) | |
tree | 1fb3aaf44f814b439245b0b032cb20ff24e2449a | |
parent | f8a6bdddb79d9724fc7547f5ffc7c601c1561978 (diff) | |
download | crosvm-7df5a0ef1a23542b0cc7db7797b8b287eaa05699.tar crosvm-7df5a0ef1a23542b0cc7db7797b8b287eaa05699.tar.gz crosvm-7df5a0ef1a23542b0cc7db7797b8b287eaa05699.tar.bz2 crosvm-7df5a0ef1a23542b0cc7db7797b8b287eaa05699.tar.lz crosvm-7df5a0ef1a23542b0cc7db7797b8b287eaa05699.tar.xz crosvm-7df5a0ef1a23542b0cc7db7797b8b287eaa05699.tar.zst crosvm-7df5a0ef1a23542b0cc7db7797b8b287eaa05699.zip |
usb_util: add sandboxed-libusb feature
make open_fd patch optional. if sandboxed-libusb feature is not selected, open_fd is not required. In this case, the code must have access to /dev/bus/usb, and not external fd is needed. BUG=chromium:831850 TEST=cargo test Change-Id: I21fa87dd15d08a03c2fe2b190559abbe6f63dcd5 Reviewed-on: https://chromium-review.googlesource.com/1375019 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Jingkui Wang <jkwang@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | usb_util/Cargo.toml | 3 | ||||
-rw-r--r-- | usb_util/src/libusb_device.rs | 8 |
3 files changed, 8 insertions, 4 deletions
diff --git a/Cargo.toml b/Cargo.toml index 912f9c6..c8f7473 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ default-no-sandbox = [] wl-dmabuf = ["devices/wl-dmabuf", "gpu_buffer", "resources/wl-dmabuf"] gpu = ["devices/gpu"] usb-emulation = ["usb_util"] +sandboxed-libusb = ["usb_util/sandboxed-libusb"] [dependencies] arch = { path = "arch" } diff --git a/usb_util/Cargo.toml b/usb_util/Cargo.toml index bdb11f0..1ab1cf2 100644 --- a/usb_util/Cargo.toml +++ b/usb_util/Cargo.toml @@ -4,6 +4,9 @@ version = "0.1.0" authors = ["The Chromium OS Authors"] build = "build.rs" +[features] +sandboxed-libusb = [] + [dependencies] assertions = { path = "../assertions" } data_model = { path = "../data_model" } diff --git a/usb_util/src/libusb_device.rs b/usb_util/src/libusb_device.rs index 4ee80d2..d1a6e47 100644 --- a/usb_util/src/libusb_device.rs +++ b/usb_util/src/libusb_device.rs @@ -110,11 +110,11 @@ impl LibUsbDevice { /// Get device handle of this device. Take an external fd. This function is only safe when fd /// is an fd of this usb device. + #[cfg(feature = "sandboxed-libusb")] pub unsafe fn open_fd(&self, fd: RawFd) -> Result<DeviceHandle> { let mut handle: *mut bindings::libusb_device_handle = std::ptr::null_mut(); - // Safe because 'self.device' is constructed from libusb device list and handle is on stack. - try_libusb!(unsafe { bindings::libusb_open_fd(self.device, fd, &mut handle) }); - // Safe because handle is successfully initialized with libusb_open_fd. - Ok(unsafe { DeviceHandle::new(self._context.clone(), handle) }) + // Safe when 'self.device' is constructed from libusb device list and handle is on stack. + try_libusb!(bindings::libusb_open_fd(self.device, fd, &mut handle)); + Ok(DeviceHandle::new(self._context.clone(), handle)) } } |