Commit Graph

114 Commits

Author SHA1 Message Date
Jooyung Han 80245f29c2 Use microdroid_sign_key for prebuilt bootloader
Prebuilt bootloader embeds its own public key, which is exposed as
microdroid_crosvm_bootloader.avbpubkey from prebuilt repo. When building
the virt apex, it's replaced with microdroid_sign_key's pubkey.

Bug: 193504286
Test: sign_virt_apex_test
Change-Id: I034558d31ea2907b8000f558425d32f642ec2987
2021-11-09 17:20:53 +09:00
Jooyung Han d35952e0f6 Reland "apex: use the same key for all microdroid items"
This reverts commit aea73f82a0.

Relanding with the fix for arm & x86 builds.

apex: use the same key for all microdroid items

The pubkey embedded in bootloader should match with the key signing
VBmeta. The updated build graph is to ensure bootloader and VBmeta to be
generated with the same key.

All other filesystem images are signed with the same key for
convenience even though it's not necessary.

Bug: 193504286
Bug: 203726593
Test: atest MicrodroidHostTestCases
Change-Id: Iae93934b18955e86ee6b73ad204c68a3f7456102
2021-11-08 18:10:33 +09:00
Ivana Chen aea73f82a0 Revert "apex: use the same key for all microdroid items"
This reverts commit 6351310cfa.

Reason for revert: broken build b/205506708

Change-Id: Id3a283aa7cc271454b3f5d2cf5c3853aa6229332
2021-11-08 07:28:26 +00:00
Jooyung Han 6351310cfa apex: use the same key for all microdroid items
The pubkey embedded in bootloader should match with the key signing
VBmeta. The updated build graph is to ensure bootloader and VBmeta to be
generated with the same key.

All other filesystem images are signed with the same key for
convenience even though it's not necessary.

Bug: 193504286
Bug: 203726593
Test: atest MicrodroidHostTestCases
Change-Id: I4ecb9e2c00d739aba84677036edf256f141767ac
2021-11-08 10:45:42 +09:00
Jiyong Park acf31b0105 Sign bootconfig partitions
We need to verify the bootconfig partitions. Otherwise, attackers can
compose a random bootconfig partition, and use it instead of the
prebuilt ones. Then they would be able to modify the behavior of the VM.

Now, bootconfig partitions are signed using avb just like other
partitions. In addition, the disk 1 where the bootconfig is in has
a new vbmeta partition. The partition has the bootconfig partition as
the chained partition. This vbmeta partition can be used to add more
bootconfig-like partitions in the future.

Bug: 203031847
Test: run microdroid test app
Change-Id: I66c7defd07785fcb13180a368786151bd973cc65
2021-11-04 21:26:17 +09:00
Jooyung Han 31b1c2b56b sign_virt_apex: replace bootloader pubkey
VBmeta's key should match with pubkey embedded in bootloader. The
bootloader pubkey is added to the APEX so that sign_virt_apex can
replace it with a new pubkey.

Bug: 193504286
Test: sign_apex --sign_tool sign_virt_apex ...
      & install & run a VM
Change-Id: Ic8e5ec9cb45434691c8dce0ca09243e181dc59cc
2021-10-27 10:33:37 +09:00
Jooyung Han 21e668cb97 microdroid: use a single vbmeta for all partitions
Since we don't need to update partitions separately, a single vbmeta is
enough for all partitions.

Bug: 193504286
Test: atest MicrodroidHostTestCases
Change-Id: I4f0e84dc0132c8f3ff9262e11bfc68eaf7863169
2021-10-26 12:11:26 +09:00
Jiyong Park 747d636b49 Use virtio-console for the serial devices
A VM is now provided with two
serial devices. One is the uart device which is used as the output
device for the cases where virtio-console device driver is not
available. In the case of Microdroid, it's used by bootloader (u-boot)
and by the kernel as earlycon. The other is the virtio-serial device. It
is used as the console for the kernel.

This CL has two X86 specific hacks though.

1. The PCI addresses of the boot devices were adjusted. This is because
we have added one more PCI device (the virtio-serial device) and crosvm
for x86_64 puts serial devices prior to the block devices and they all
share the same bus ID. As a result, the block device addresses are all
shifted by 1.

2. The kernel command line embedded in boot.img now has `console=none`.
This is to prevent u-boot from automatically adding `console=ttyS0`. If
we let u-boot do that, then we will have console=ttyS0 together with
console=hvc0. Then each kernel message is printed twice; once to ttyS0
and once again to hvc0.

Bug: 200914564
Test: run a VM
Change-Id: I4349c4d70ac76c1b4ddc77bbff6c9b697b2f1f4e
2021-10-20 16:04:34 +09:00
Jiyong Park 4d2289579f Microdroid has its own ueventd.rc
So far, Microdroid used ueventd.rc from Android. Although ueventd.rc for
Android has some device nodes that are not relevant to microdroid (e.g.
gpu, input, etc.) but that wasn't harmful. However, we will soon have
/dev/hvc* entries for the virtualized console which is exclusive for
Microdroid.

Forking the file in preparation for the change.

Bug: 200914564
Test: atest MicrodroidHostTestCases
Change-Id: I3d42203f4835b8058249ef0783d0509d693e81e0
2021-10-19 21:29:43 +09:00
Ram Muthiah 310210238b Shifted microdroid to a separate bootloader
Microdroid's bootloader is locked and cuttlefish is unlocked. Hence the
split.

Bug: 155019925
Test: MicrodroidTestCases and Treehugger
Change-Id: I2adf1298145c02c9863b0376fee92f231feb92ae
2021-10-18 11:19:13 -07:00
Jiyong Park c2a49cc0db Define debug levels
Previously, a VM can be configured as running in debug mode or not.
However, the debug mode was not defined clearly and debugging features
like logging and adb-shell were actually left enabled even when the
debug mode is off.

This CL re-defines the debuggability of a VM. A VM has a debug level
which can be either of these three:

1. None: In this level, VM is not debuggable at all. No log is exported
from the VM, and debugger can't be attached to any process in the VM.
adb-shell of course is not supported.

2. App-only: In this level, only the app payload is debuggable. Logs
from the app process is exported to the host and the process can be
attached to debugger. adb-shell is not supported.

3. Full: In this level, the VM is fully debuggable. All logs including
kernel logs are exported to the VM and developers can adb-shell into the
VM.

Note that this CL doesn't fully implement all the levels yet, but
implements the framework around supporting multiple debug levels.
Specifically, each debug level is associated with a bootconfig image.
Each image has config values each of which enables or disables a
debugging feature. For example, bootconfig images for the none and
app-only levels have "kernel.console = none" to not show kernel console
output.

The `vm` tool and the Java APIs are also amended accordingly. The debug
level can be set via `--debug <level>` flag and the `DebugLevel(...)`
method.

Future work:
* Implement each debug level
* Each level uses different vm-instance image. Debug level is stored in
the instance image and is compared against the given level when
microdroid boots.
* Sign bootconfig images with avb and let uboot verify them
(b/203031847)

Bug: 201362865
Test: atest MicrodroidHostTestCases
Test: adb shell /apex/com.android.virt/bin/vm run-app
/data/local/tmp/virt/MicrodroidDemoApp.apk
/data/local/tmp/virt/MicrodroidDemoApp.apk.idsig
/data/local/tmp/virt/instance.img assets/vm_config.json

shows ...

Created VM from
"/data/local/tmp/virt/MicrodroidDemoApp.apk"!"assets/vm_config.json"
with CID 13, state is NOT_STARTED.
Started VM, state now STARTING.
Hello Microdroid /mnt/apk/lib/arm64-v8a/MicrodroidTestNativeLib.so hello
microdroid

, which is without logs from the bootloader and the kernel

Change-Id: I897dcd88723f014524d2cd2b6ffaa6f9fb5696d6
2021-10-15 08:58:15 +09:00
Jiyong Park 1b3bcdc972 Use keystore2_microdroid instead.
keystore2_microdroid is a variant of keystore2 which uses libsqlite
which doesn't depend on the i18n APEX. Previously, the same keystore2
module was used across Android and microdroid. However, the use of the
new libsqlite variant caused a small regression (6ms) to the boot time -
because it couldn't make use of the original libsqlite which was already
pre-loaded by zygote.

To fix the regression, keystore2 for Android goes back to use the
original libsqlite, and keystore2_microdroid is created to use the
no-icu version of libsqlite.

Bug: 201344281
Test: measure SystemServerTiming_StartLockSettingsService-total
Change-Id: I01de5d803479b48ec407e97c193d7e093cdc0ac9
2021-10-04 22:40:53 +09:00
Inseob Kim 998c27f2e1 Migrate precompiled sepolicy to se_policy_binary
Bug: 33691272
Test: boot microdroid
Change-Id: I61e4bd77d0b864b73e8cc42675f0112ba54e51c0
2021-09-27 13:44:09 +00:00
Jiyong Park 4e619bcc37 Remove the i18n APEX from microdroid
It was used only by keystore2 via libsqlite. keystore2 now depends on
libsqlite_noicu which is a variant of libsqlite built without the ICU
extension [1].

[1] https://www.sqlite.org/src/file?name=ext/icu/README.txt

Bug: 199674764
Test: du -sh com.android.virt.apex 162MB -> 97MB
Change-Id: Iac25e11bb63509c0518b56597dd422c60c08fb60
2021-09-13 15:51:34 +09:00
Jooyung Han 1c2d758996 Update microdroid's built-in apexes
i18n apex is non-updatable and has no-hashtree in its payload image.
Without hashtree, apex can't be dm-verity mounted. So microroid should
have the apex as a built-in (in /system/apex) so that it can be directly
loop-mounted.

Bug: n/a
Test: MicrodroidHostTestCases
Change-Id: Iea5d9cd7b39e909259ed452258395cfb20804f70
2021-09-08 22:49:28 +09:00
Jiyong Park 3f7728e61e Merge "Mount system and vendor over dm-verity" 2021-09-01 23:28:21 +00:00
Jiyong Park 52ea0830e5 Mount system and vendor over dm-verity
This CL fixes a series of mistakes which let the system and the vendor
partition be mounted without dm-verity.

* avb=vbmeta and avb=vbmeta_system flags are added to fstab so that the
partitions are mounted over dm-verity

* uboot script is modified to append avb_bootargs into bootargs so that
avb parameters like the root hash, etc. are passed to the kernel via
cmdline

* The boot partition is no longer a chained partition. Its hashtree is
included in vbmeta.img directly. This is firstly because we don't have a
need to update the kernel independently from other partitions. And
secondly, boot as a chained partition requires us to create
/dev/block/by-name/boot during the first stage init, which require
additional-but-useless entry in fstab.

* Name of the logical partitions in super.img is changed to system_a and
vendor_a from system and vendor, respectively.

Bug: 198303625
Test: boot microdroid. `ls /dev/block/mapper` shows
```
drwxr-xr-x 3 root root  160 2021-09-01 03:10 .
drwxr-xr-x 5 root root 1180 2021-09-01 03:10 ..
drwxr-xr-x 2 root root  140 2021-09-01 03:10 by-uuid
lrwxrwxrwx 1 root root   15 2021-09-01 03:10 microdroid-apk -> /dev/block/dm-4
lrwxrwxrwx 1 root root   15 2021-09-01 03:10 system-verity -> /dev/block/dm-2
lrwxrwxrwx 1 root root   15 2021-09-01 03:10 system_a -> /dev/block/dm-0
lrwxrwxrwx 1 root root   15 2021-09-01 03:10 vendor-verity -> /dev/block/dm-3
lrwxrwxrwx 1 root root   15 2021-09-01 03:10 vendor_a -> /dev/block/dm-1
```

Change-Id: I6b485d841d9bd774ab964fd9ae7d2e0a15795b14
2021-09-01 17:27:30 +09:00
Jiyong Park 21ce2c5b1e Store apk root hash to the instance disk
The instance disk has been created, but hasn't actually been used. This
CL is the first step towards actually using it. Specifically, this CL

* provides routines for navigating the instance disk. The disk consists
of a disk header, followed by partitions each of which consists of a
header and payload. Each partition is dedicated to a program loader like
pVM firmware, Android Boot Loader, and microdroid_manager. A partition
is identified by UUID and this CL provides a routine to locate the
partition for a given UUID.

* provides routines for reading and writing on payload in a partition.
The data is stored encrypted when it is written and is decrypted when
read. The key is currently hard-coded but, it will eventually be derived
from the sealing CDI from the previous stage.

* Root hash of an apk extracted from the idsig file is stored to the
disk. Note that the stored root hash is not yet used by apkdmverity. It
shall be done in a follow-up change.

Bug: 193504400
Test: boot microdroid twice. check that the root hash is written to the
disk during the first boot, and then read during the second boot. Also
check that the two root hashes are the same.

Change-Id: Ia1afcda4d8444ad52a47ebcc659b2698159da816
2021-09-01 01:58:22 +09:00
Jiyong Park c893717b6b Turn the /dev/kmsg ratelimiting on for production builds
Bug: 181936135
Test: inspect build.ninja
Change-Id: I6e91847c8daa880ba61e623c4b2cd9ca62035f32
2021-08-30 18:41:52 +09:00
Victor Hsieh 8bb67b66f7 Start authfs_service during boot on microdroid
Bug: 194717985
Test: see the service starts on boot
Test: MicrodroidHostTestCases
Change-Id: Ia91cf6d8316bfd95ba3a0ea1fb45c64422c2f85f
2021-08-06 14:45:45 -07:00
Alistair Delva 16a83c0dcd Merge "Fix microdroid boot with newer crosvm" 2021-08-05 03:29:18 +00:00
Alistair Delva f1c9d0ca22 Fix microdroid boot with newer crosvm
The same fix was made to the cuttlefish launcher wrapper already.

Bug: 175151042
Change-Id: I7776be90e16675e04b9457ab4f294948ab35d349
2021-08-04 10:07:45 -07:00
Treehugger Robot fc8091b7e4 Merge changes I851bc789,I8ccf8abd
* changes:
  Remove shell invoking of payload
  Mount data partitions prior to keystore
2021-08-04 13:33:50 +00:00
Inseob Kim 4e207a1753 Remove shell invoking of payload
The payload will be automatically run by microdroid_manager.

Bug: 193118220
Test: atest MicrodroidHostTestCases
Change-Id: I851bc7890ebfc27dadea1fa9ce09413e18aed07c
2021-08-04 09:03:15 +00:00
Jooyung Han 8a17ef71a9 microdroid: add required libs manually
TARGET_BUILD_APPS build makes libs with sdk_version not included in
microdroid system image. Until fixing the build system, those missing
libs can be manually added to the list of microdroid's deps.

Bug: 195425111
Test: TARGET_BUILD_APPS=com.android.virt m apps_only dist
      install the apex and run MicrodroidHostTestCases
Change-Id: Ied90997026e2ade327ef337109676aca5636e9b5
2021-08-04 15:39:54 +09:00
Victor Hsieh 1ef3cb7a62 Add strace to microdroid image
This makes it easier to debug some problems.

Bug: None
Test: use strace in the VM
Change-Id: Iafae572f1f1b66481d28197d5747c308b03b1f6c
2021-07-21 08:49:10 -07:00
Jiyong Park b810cfe572 Use bootconfig
androidboot.* parameters now passed via bootconfig

Bug: 185211964
Test: atest MicrodroidHostTestCases
Change-Id: I686dbbbcd4fffa7598130139b3bcbe9ee798d666
2021-07-05 15:42:40 +09:00
Jiyong Park 62d936917d Merge "A lib in APK can depend on other libs in the same APK" 2021-06-24 04:24:40 +00:00
Andrew Scull b10ee781c3 Merge "Add microdroid-specialized KeyMint service" 2021-06-23 17:00:41 +00:00
Jiyong Park fe5b28ef8e A lib in APK can depend on other libs in the same APK
This hasn't worked because the path /mnt/apk/lib/<abi> wasn't in the
search paths of the linker namespace that the library is loaded (which
is the default namespace).

Fixing that by creating a new linker namespace 'microdroid' that
inherits the settings from the default namespace but adds the library
directory to the search paths, and loading the library from that
namespace.

Bug: N/A
Test: atest MicrodroidHostTestCases

Change-Id: I30c4ce86a48b80fa65e3b5ffeb90561fa1d2544e
2021-06-24 01:36:37 +09:00
Andrew Scull 9ba2657f2f Add microdroid-specialized KeyMint service
KeyMint in microdroid will initially be a specialized version of the
software KeyMint reference implementation. Begin this specialization by
removing the services that aren't needed within VMs.

Bug: 190578423
Test: atest MicrodroidHostTestCases
Change-Id: I6eee95944ccc555656868dad193f29b83ebf46a4
2021-06-23 08:46:56 +00:00
Treehugger Robot 9045c68dc0 Merge "Minimize microdroid file_contexts" 2021-06-23 00:46:24 +00:00
Inseob Kim ac2cfb96e3 Minimize microdroid file_contexts
file_contexts was copied from system/sepolicy/private. It's contained a
lot of redundant entries for microdroid.

Bug: 191131624
Test: atest MicrodroidHostTestCases
Change-Id: Ia4e2664822b9cb984dddb99c03faaa6f54f2dfc6
2021-06-22 19:18:14 +09:00
Andrew Scull 6661661714 Basic Keystore availability test
Loop up the Keystore service from the test payload to make sure it can
be found and communicated with.

Bug: 190578423
Test: atest MicrodroidHostTestCases
Change-Id: I1dd863202b7de5405658ee5e922b955e3cba6741
2021-06-21 16:53:38 +00:00
Jiyong Park e9b74d0532 Use the vm tool
MicrodroidHostTestCases now uses the vm tool to create the VM. It no
longer directly interacts with crosvm and mk_cdisk.

The READMD.md file is rewritten to fully reflect the recent changes, and
also to add description about building an app for microdroid.

Bug: 185891097
Test: atest MicrodroidHostTestCases
Change-Id: I5fdc854390fd362ebead22a4a36af75c30500a81
2021-06-21 22:11:17 +09:00
Inseob Kim 476b48b67c Merge "Update init_first_stage" 2021-06-18 17:12:23 +00:00
Treehugger Robot 553baa9d3b Merge changes from topic "rust-rpc-binder"
* changes:
  compsvc/pvm_exec: Support RPC binder
  authfs: Support RPC binder
2021-06-17 21:43:55 +00:00
Paul Crowley 62c5682bbc Merge "Remove wait_for_keymaster and all references" 2021-06-17 18:18:28 +00:00
Victor Hsieh 2445e33ba4 authfs: Support RPC binder
This change adds a new flag --rpc-binder to authfs, and --cid to
fd_server. The flag allows both to communicate through vsock. The
capability of local binder is kept for now (and still the default),
but can be removed later.

The change relies on the newly introduced libbinder_rpc_unstable.so
and the corresponding bindgen, in order to access the unstable API from
Rust.

Also, add authfs and libbinder_rpc_unstable to microdroid.

Bug: 190547489
Bug: 189947807
Test: [Android shell] sh -c 'exec 9<>/data/local/tmp/output \
          /apex/com.android.virt/bin/fd_server --rw-fds 9 --rpc-binder'
      [VM shell] /apex/com.android.virt/bin/authfs \
          /data/local/tmp --cid 2 --remote-new-rw-file 9:9
      [VM shell 2] ps -A > /data/local/tmp/9
      [Android shell] cat /data/local/tmp/output  # see correct data
Change-Id: I200f746aa4078508a0f0d2498a1525bb898a6e3b
2021-06-17 08:22:36 -07:00
Jooyung Han 7ce2e53528 microdroid: pass idsig in payload.img
apkdmverity is added to microdroid as well.

Bug: 190343842
Test: MicrodroidHostTestCases (not changed)
Change-Id: If5d6608b52cc93cd13ace85c03b5b2891041b8b4
2021-06-16 22:30:54 +09:00
Paul Crowley d5426704bd Remove wait_for_keymaster and all references
No longer needed now init listens for property changes on a
separate thread.

Bug: 186580823
Test: Cuttlefish boots successfully
Test: atest MicrodroidHostTestCases
Change-Id: I4953e1f9e596db6e8b5ecc49a05cbf4375b7f6c4
2021-06-15 16:45:02 -07:00
Jiyong Park 2393439dd1 Remove microdroid_payload.json
The file was the input to make the payload.img. Instead using the
hard-coded file, let the test make it from the vm_config file in the
test APK. This will eventually be done by the client-side library, but
since we don't have it, let the test do it.

Bug: 185891097
Test: atest MicrodroidHostTestCases

Change-Id: I677dff58abb1b49d76b53c39ec33ccc0c8b88dc4
2021-06-16 02:09:36 +09:00
Inseob Kim 9733096fab Update init_first_stage
Bug: 187196593
Test: boot microdroid
Change-Id: I7cb582ca02e1b71bffec0d0507789bf84234027c
2021-06-14 11:51:41 +09:00
Victor Hsieh 527b81d0ed Add libartpalette-system to microdroid
libartpalette-system is a run-time dependency of dex2oat.

Bug: 187547405
Test: dex2oat
Change-Id: I6bb46ecccc7d83227c9f150a0c39e922311b4d87
2021-06-11 10:43:03 -07:00
Inseob Kim 17d0db10da Change /data to tmpfs
For security reason, we will use tmpfs for /data. It should contain only
small, temporary files for now.

vold is removed as it's redundant now. MicrodroidTestCase's boot marker
is also updated because logd reinit won't happen if vold is removed.

Bug: 185767624
Test: atest MicrodroidHostTestCases
Change-Id: I3f60d5dfad2519b6d593a3f514bb50c50019b526
2021-06-09 14:30:47 +09:00
Inseob Kim ff43be2ca9 Add microdroid specific sepolicy
Microdroid will have a separate sepolicy, apart from the core policy.
This is the first step; For now it's a simple copy of system/sepolicy.
For the future work, it will be stripped.

Bug: 189165759
Test: boot microdroid and see selinux enforced
Change-Id: I2fee39f7231560b49c93bd5e8d0feeffada40938
2021-06-07 18:44:35 +09:00
Inseob Kim 8f095c900c Add vold and keymint related services
These are for encrypting /data partition. Also vintf related xmls are
added for the services.

Bug: 185767624
Bug: 188013319
Test: boot microdroid
Change-Id: Ie511e2b4f3565fef181cc57588c2e107182f1961
2021-06-02 20:38:51 +09:00
Jooyung Han 347d9f2bee microdroid_manager: initial impl
It is started by init in microdroid and executes a command specified in
a VM payload config.

Bug: 189301496
Test: MicrodroidHostTestCases
  (in a microdroid, run /system/bin/microdroid_manager manulally)
Change-Id: I85c7e370d4a0dcf58b4aafbe6e9fba73e69c2a44
2021-05-28 07:30:44 +09:00
Inseob Kim 67ab436363 Update init.rc and fstab to normal convention
Bug: 185767624
Test: boot and see data mounted
Change-Id: Iabeca8c4c03df586ee1a65e8274e3667c2bdd2dc
2021-05-26 17:17:05 +09:00
Jiyong Park 8f2a46884b Don't use qcow2 for userdata.
We provide a sparse file directly as a (writable) partition image and
format a filesystem on the partition inside the VM.

To format it only when it's not formatted, the option `formattable` is
added to the fstab entry for the userdata partition.

Bug: 185767624
Test: atest MicrodroidHostTestCases
Change-Id: Ia938fd60071e64170b8280d19c17c4413c769337
2021-05-25 22:47:43 +09:00