diff options
author | Jorge E. Moreira <jemoreira@google.com> | 2021-04-12 13:57:49 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-04-19 19:58:32 +0000 |
commit | 1e3cb9faa10b7db3812543ec8a74fc836021f740 (patch) | |
tree | 226480c340b019dc0f85e16e113942299d3275c4 | |
parent | 6d473b36153879641bb9dd464f0ae7ecd4432add (diff) | |
download | crosvm-1e3cb9faa10b7db3812543ec8a74fc836021f740.tar.gz |
Conditionally apply linux-only operations
Rust's libc considers android to be different than linux and provides
certain functions exclusively for target_os = "linux".
BUG=b:185155959
Change-Id: I664821fd678f0c911deb9312fe5fcfc9faf00053
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2822209
Tested-by: Jorge Moreira Broche <jemoreira@google.com>
Commit-Queue: Jorge Moreira Broche <jemoreira@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
-rw-r--r-- | devices/src/proxy.rs | 3 | ||||
-rw-r--r-- | devices/src/virtio/fs/worker.rs | 24 |
2 files changed, 17 insertions, 10 deletions
diff --git a/devices/src/proxy.rs b/devices/src/proxy.rs index 4afa7b38c..5e22786d6 100644 --- a/devices/src/proxy.rs +++ b/devices/src/proxy.rs @@ -158,6 +158,9 @@ impl ProxyDevice { let debug_label_trimmed = &debug_label.as_bytes()[..std::cmp::min(max_len, debug_label.len())]; let thread_name = CString::new(debug_label_trimmed).unwrap(); + // TODO(crbug.com/1199487): remove this once libc provides the wrapper for all + // targets + #[cfg(all(target_os = "linux", target_env = "gnu"))] let _ = libc::pthread_setname_np(libc::pthread_self(), thread_name.as_ptr()); device.on_sandboxed(); child_proc(child_tube, &mut device); diff --git a/devices/src/virtio/fs/worker.rs b/devices/src/virtio/fs/worker.rs index 19fec1159..65a47a9c6 100644 --- a/devices/src/virtio/fs/worker.rs +++ b/devices/src/virtio/fs/worker.rs @@ -188,18 +188,22 @@ impl<F: FileSystem + Sync> Worker<F> { // cases. const SECBIT_NO_SETUID_FIXUP: i32 = 1 << 2; - // Safe because this doesn't modify any memory and we check the return value. - let mut securebits = unsafe { libc::prctl(libc::PR_GET_SECUREBITS) }; - if securebits < 0 { - return Err(Error::GetSecurebits(io::Error::last_os_error())); - } + // TODO(crbug.com/1199487): Remove this once libc provides the wrapper for all targets. + #[cfg(target_os = "linux")] + { + // Safe because this doesn't modify any memory and we check the return value. + let mut securebits = unsafe { libc::prctl(libc::PR_GET_SECUREBITS) }; + if securebits < 0 { + return Err(Error::GetSecurebits(io::Error::last_os_error())); + } - securebits |= SECBIT_NO_SETUID_FIXUP; + securebits |= SECBIT_NO_SETUID_FIXUP; - // Safe because this doesn't modify any memory and we check the return value. - let ret = unsafe { libc::prctl(libc::PR_SET_SECUREBITS, securebits) }; - if ret < 0 { - return Err(Error::SetSecurebits(io::Error::last_os_error())); + // Safe because this doesn't modify any memory and we check the return value. + let ret = unsafe { libc::prctl(libc::PR_SET_SECUREBITS, securebits) }; + if ret < 0 { + return Err(Error::SetSecurebits(io::Error::last_os_error())); + } } #[derive(PollToken)] |