Commit graph

27 commits

Author SHA1 Message Date
Noah Gold
46f3f081bf win_util: securely zero buffers used by DPAPI.
The buffers used by DPAPI calls will often contain cryptographic key
material. This CL securely zeroes them on drop.

Note: Windows does provide a platform intrinsic to securely zero memory
(SecureZeroMemory), but it is provided as a macro, which is exceedingly
painful to use from Rust. Zeroize used to call SecureZeroMemory under
the hood in versions of the crate, but it no longer does. Likely
because it's a pain.

BUG=b:286345300
TEST=unit tests

Change-Id: Ifabeecb47563828616f278ff1c28266f4014e753
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5333894
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Judson Powers <judsonp@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-03-04 18:31:37 +00:00
Keiichi Watanabe
8039f7149b Don't build winapi crate on non-windows environment
Hide winapi crate behind 'cfg(windows)' in Cargo.toml.
This CL is for ChromeOS build.

This commit is unneeded on non-ChromeOS environment because winapi has
'#![cfg(windows)]' in its body so it can be built as empty crate even
on non-windows environments.
However, in ChromeOS build system, winapi crate is replaced with an
empty crate that cannot be built on Linux [1].

[1]: http://cs/h/chromium/chromiumos/codesearch/+/main:src/third_party/rust_crates/vendor/winapi-0.3.9/src/lib.rs?l=1

BUG=none
TEST=cros_run_unit_tests --board octopus --packages crosvm on cros_skd

Change-Id: I6174b4f777b9ad5d94544e4ea9cbfd2e65f48089
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5321370
Auto-Submit: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2024-02-26 16:13:38 +00:00
Daniel Verkamp
f88a2f3e03 win_util: remove from exclude and fix clippy checks
Change-Id: Ibfe05312db8c44dbc7f515b10b830c1e75e96852
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5321575
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-02-23 21:42:57 +00:00
Kaiyi Li
c28067d1d9 Reformat comments
Test: presubmit
Change-Id: I39c261d9985989873b698213c5d8b653fc13757b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5299850
Auto-Submit: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-02-15 23:30:13 +00:00
Noah Gold
75e21814ac win_util: add DPAPI wrappers
Adds wrappers for CryptProtectData and CryptUnprotectData.

BUG=b:324301901
TEST=unit tests

Change-Id: I89373a6e546c0364471d05b3f665de0e96b3cd81
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5277999
Reviewed-by: Judson Powers <judsonp@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2024-02-09 02:54:02 +00:00
Dennis Kempin
73aed77b49 Run rustfmt on whole codebase with nightly enabled
Nigthly is enabled as part of https://crrev.com/c/4950268
This change contains the formatting changes resulting from the switch.

BUG=b:302055317
TEST=dev_container presubmit format --no-delta

Change-Id: Idaf2b8bae2e09c624b19d9cd3dd5fc8e4d099b3c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5067088
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2023-11-29 18:41:29 +00:00
Pujun Lun
1a8f413d7d gpu_display: add KeyboardInputManager to handle key events on Windows.
BUG=b:306407787

Change-Id: I28286cb6f999da56020fba2e79d4ad9a1875c8eb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5026248
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Pujun Lun <lunpujun@google.com>
2023-11-17 01:34:38 +00:00
Daniel Verkamp
d5cd443dc7 Fix some cargo doc warnings in Windows-only code
Change-Id: I0ff72840853db764db6dfc8145581447dff8795d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4883336
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
2023-09-22 00:59:46 +00:00
Kaiyi Li
79a105ff53 Do not require unsafe block to use syscall_bail
GetLastError() should be always safe to call.

Test: build
Change-Id: I2accfba608514a9da03b8c46bd7048137c14b462
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4814443
Commit-Queue: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-09-20 17:18:26 +00:00
Vikram Auradkar
373aaa6edb metrics: upstream local metrics related changes
These metrics allows to measure io related performance.

BUG=b:286107739
TEST=none

Change-Id: Ieb0920a239e0e5d952ef51210393350ca34ee611
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4601851
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2023-06-13 21:57:14 +00:00
Daniel Verkamp
7806484161 win_util: move SYSTEM_INFO helpers to base
These helper functions for getting system information are only used to
implement the equivalent base functions, so move the implementation into
base itself.

This also cleans up the initialization of the cached system information
so that it is contained in a single once_cell::sync::Lazy. The relevant
data is retrieved once and stored in an internal struct SystemInfo to
avoid problems with storing SYSTEM_INFO itself (the Win32 structure
contains pointers, so it is not Sync and can't be stored directly in a
sync::Lazy).

BUG=b:263815124
TEST=tools/run_tests --platform=mingw64

Change-Id: I94d029ef165764f976fd34d846fab60b8754cfb1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4126566
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-05-17 19:25:32 +00:00
Daniel Verkamp
3acd42c084 win_util: remove build.rs script
This seems to only generate bindings for ImmDisableIME(), which is
unused in upstream crosvm and also seems to be available without running
a build step now.

BUG=b:277957421
TEST=tools/dev_container tools/presubmit

Change-Id: Ic5a996eb9d8c7d7c65e2138fe92e8ea335cac76f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4477411
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-04-26 18:25:31 +00:00
Noah Gold
e746033396 win_util: upgrade to windows 0.39.0.
This version is already used downstream, and upgrading means we only
have one version of the windows crate to maintain in crosvm downstreams.

BUG=none
TEST=builds

Change-Id: Ic823b0d07eaf75dac941bd32e23a4a5bfd52d088
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4416223
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2023-04-11 21:56:19 +00:00
Noah Gold
29e018652f base: move read/write wrappers to their own module.
In the future we'll be using read/write wrappers in multiple places,
but the wrapping code currently lives in the named pipe implementation.
This CL pulls it out to its own module. It also brings in some other
code in win_util that wasn't upstreamed.

BUG=b:272614458
TEST=presubmit

Change-Id: I6871f3db6991336f42706652b69935755bf2fbc3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4326942
Commit-Queue: Noah Gold <nkgold@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-03-14 18:24:44 +00:00
Idan Raiter
5c6d0439bd win_util: Expand token functionality with other types & thread tokens
Adds more tokens to the supported token queries. Also refactors the
ProcessToken type to instead be a general Token type, which can also
provide support for thread tokens.

Bug: b/242355890
Test: downstream
Change-Id: Ib1fd574abb3bc46203ef8f03e991efcc22561dc5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4294675
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Idan Raiter <idanr@google.com>
2023-03-01 23:09:19 +00:00
Idan Raiter
f1c283e4b6 metrics: Add missing process types
Downstream we've added the SPU + Broker process types, this should be
reflected here to avoid numbers going out of sync.

Also adds sound type.

BUG=b:269313507
TEST=presubmit

Change-Id: I5e3e269c9aca7bc9504e3e822302bcccf3bf377f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4246713
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Idan Raiter <idanr@google.com>
2023-02-22 20:01:38 +00:00
Zihan Chen
28ce4e5423 crosvm: Uprev rust toolchain and dev container
- Rust toolchain is updated to 1.65.0
- Catapult dashboard upload tool is added to dev_container
- Bindgen is updated to latest version to support custom derive
- Derive Eq when PartialEq is derived as required by new Clippy

TEST=CQ, bindgen-all-the-things

FIXED=b:260784028
BUG=b:257303497

Change-Id: I2034cd09e0aed84d4e9b30f2e85d84d94a442ea4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4228427
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2023-02-08 20:26:30 +00:00
Daniel Verkamp
ac0fc378a3 Fix remaining Chrome/Chromium OS instances
These should be written as ChromeOS and ChromiumOS (without the space)
to match the updated branding. The copyright headers were already
migrated to the new style (https://crrev.com/c/3894243), but there were
some more instances left over.

BUG=None
TEST=tools/cargo-doc

Change-Id: I8c76aea2eb33b2e370ab71ee9b5cc0a4cfd00585
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4129934
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-01-03 22:14:30 +00:00
Richard Otap
616e84ae54 win_util: Fix DLL notification tests
The DLL notification tests were flaky because we were trying to test an
operation that is somewhat asynchronous from the actions of the test
itself. We would see failures at a pretty low rate because the DLL we
were trying to observe unloads for would not necessarily unload
immediately, or within a short timeout of when we would expect it to
unload.

This was exacerbated by the test using the same DLL for the load and
unload portions of the test. This would add another layer of
nondeterminism about what the state of the test runner process was which
we were trying to deterministically observe.

We can fix this by doing two things:

  1. Introduce some synchronization to allow us to wrangle the
     asynchronous nature of the test.
  2. Use different DLLs for the load and unload tests.

By implementing these changes, the flakiness doesn't appear anymore
after running the test a few thousand times.

BUG: b:229288169
TEST: cargo test --package win_util --lib -- dll_notification
Change-Id: Id6aa216ed91bd9e13523118bcee1b352d511a883
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4062048
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Richard Otap <rotap@google.com>
2022-11-29 04:03:47 +00:00
Idan Raiter
21e083a108 device: vhost-user: Bring up Windows GPU
Brings up the Windows vhost-user GPU, when there is a vhost-user flag.
Otherwise, uses the original worker in the main process.

- Creates backend and VMM configs in broker.

- Always passes the VMM config to the main process.

- Passes backend config either to main or the vhost-user process.

- Create exit read / write event pair in broker, so GPU can request it
  from its process (on Windows, when we close the rendering window).

BUG=b:243061269
TEST=downstream / presubmit

Change-Id: I373e59e936bc21580e7962942742750444807093
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3968458
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Idan Raiter <idanr@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-11-21 20:05:59 +00:00
Pujun Lun
dd2c0a932a crosvm: move enum ProcessType to win_util.
This is to keep consistency with Windows downstream code.
The conversion from ProcessType to EmulatorProcessType is moved to
the metrics crate as it is only used for generating metrics.

BUG=b:213146388
TEST=presubmit

Change-Id: Ia62f76835a1f162dd8bbc9e53fd671968c368473
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3908370
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Pujun Lun <lunpujun@google.com>
2022-09-21 19:28:49 +00:00
Dennis Kempin
1dab58a2cf Update all copyright headers to match new style
This search/replace updates all copyright notices to drop the
"All rights reserved", Use "ChromiumOS" instead of "Chromium OS"
and drops the trailing dots.

This fulfills the request from legal and unifies our notices.

./tools/health-check has been updated to only accept this style.

BUG=b:246579983
TEST=./tools/health-check

Change-Id: I87a80701dc651f1baf4820e5cc42469d7c5f5bf7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3894243
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-09-13 18:41:29 +00:00
Dennis Kempin
4fea399df9 Reformat imports
crosvm is switching the import style to use one import per line.
While more verbose, this will greatly reduce the occurence of merge
conflicts going forward.

Note: This is using a nightly feature of rustfmt. So it's a one-off
re-format only. We are considering adding a nightly toolchain to
enable the feature permanently.

BUG=b:239937122
TEST=CQ

Change-Id: Id2dd4dbdc0adfc4f8f3dd1d09da1daafa2a39992
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3784345
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-07-28 00:15:50 +00:00
Vikram Auradkar
2314c4701b crosvm: Fix drift
BUG=b:213146388
TEST=presubmit

Change-Id: I59e6b7ad7aff8d4659c62e310a7955146a10d743
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3777405
Tested-by: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Auto-Submit: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-07-21 23:13:18 +00:00
Daniel Verkamp
19fc097eb8 crosvm: replace lazy_static with once_cell
We depend on both lazy_static and once_cell, which do basically the same
thing.

The once_cell crate has a few advantages:
- once_cell is on track to be included into libstd.
  (https://github.com/rust-lang/rust/issues/74465)
- once_cell doesn't require macro magic.

Replace the uses of lazy_static with their once_cell equivalents so we
don't need to pull in both crates.

BUG=b:236191006
TEST=tools/presubmit --all
TEST=tools/run_tests --target=host --arch=win64 --build-only
TEST=cargo test --features=plugin

Change-Id: I7cabcd837ef4878e8e8ae635bb4f235a58e4cae3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3707624
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-06-21 23:40:55 +00:00
Daniel Verkamp
8a4b2c448b rustfmt, win_util: update to 2021 edition
These are the only two places still using edition = 2018.

BUG=None
TEST=tools/fmt --check

Change-Id: I32577672d768db51ded66831089f135ffa77ea41
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3680641
Reviewed-by: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-05-31 23:35:02 +00:00
Dennis Kempin
9fbf4987f0 Refactoring: Move win_(sys_)util
This executes the script in https://crrev.com/c/3537257

BUG=b:223206469
TEST=presubmit

Change-Id: I51176d02081a7130270cf1b2ebe7c58ef9056db3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3537258
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-03-22 22:23:41 +00:00