Commit Graph

17 Commits

Author SHA1 Message Date
Jiyong Park 599043a235 Unbundled test apps can obtain virtual machine permissions
Currently, tests for pKVM are written as hode-side tests which interact
with the platform using the `vm` tool. However, that approach has cause
many problems:

* Can't test Java APIs; we were testing the command line interface of
the tool actually.
* Unreliable connection to adb; we had to add busy loops to work around
some of the flakes.

We should move on to the device-side tests. There will be a
self-instrumened test apk which will be driven by tradefed.

However, one blocker to the plan is that the Java APIs are not available
to test apps, as we don't have a plan to make the APIs public in TM and
therefore we put the APIs behind signature-protected permissions
(com.android.MANAGE_VIRTUAL_MACHINE, com.android.DEBUG_VIRTUAL_MACHINE).
Since test apps can't be signed with the platform key, our test apk
can't have the permission.

This CL fixes the problem by turning on the `development` bit in the
protection level of the permissions. Then the permission can be granted
to the test apps satisfying following conditions (all):

* test app has `android:testOnly="true"` in its manifest. The flag
prevents the app from being uploaded to Play or installed from there.
* the app has to be installed with the "-t" (`INSTALL_ALLOW_TEST`) flag
* the permission has to be explicitly granted via `pm grant <package>
<perm>` command`.

Bug: 203483081
Test: TARGET_BUILD_APPS="MicrodroidDemoApp" m apps_only dist
adb install --no-streaming -t out/dist/MicrodroidDemoApp.apk
adb shell
$ su; setenforce 0 // will be fixed
$ pm grant com.android.microdroid.demo
android.permission.MANAGE_VIRTUAL_MACHINE
run the demo app

Change-Id: Ic163a3bc745fc310d690faddde638405faad686c
2021-10-19 17:15:28 +09: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
Inseob Kim 06a64d6606 Add an example for onPayloadReady and VM service
This adds a simple integer addition service to the testapk's binary. The
demo app tries connecting the VM service once onPayloadReady is
triggered. Users can see the VM service's output.

Bug: 195381416
Test: launch MicrodroidDemoApp
Test: atest MicrodroidHostTestCases
Change-Id: I346084d08f753772cc00aa4c052e0b9b41d460ce
2021-09-09 00:44:50 +00:00
Inseob Kim 5e148905f3 Sign demo app with the platform key
Because we'll now allow virtualizationservice permission only to
platform_apps.

Test: run demo app
Change-Id: I1d58403f363c777565f20ae81da447c2d6ce94b6
2021-09-09 00:44:34 +00:00
Inseob Kim 14cb8699b7 Add onPayloadReady callback
The guest VM can notify that its payload has finished initialization and
is ready to serve its own services, by onPayloadReady callback.

Bug: 195381416
Test: atest MicrodroidHostTestCases
Change-Id: I67fee655c410342452bc5ee990e36dfecb30b0cb
2021-09-01 11:10:56 +09:00
Inseob Kim 2444af96c9 Add onPayloadFinished callback
onPayloadFinished will be called from the VM when the payload has just
finished.

Bug: 195381416
Test: atest MicrodroidHostTestCases
Change-Id: I9bb68c2192ee19a40634d10ba77af9d4c3ec30d0
2021-08-31 20:19:35 +09:00
Inseob Kim 42f9709c80 Do not loop infinitely in callback function
If we do, the callback receiver won't get other calls.

Test: MicrodroidDemoApp
Change-Id: Ib2d40e2dd120c07a500294ae483d072e6b01ae0f
2021-08-27 02:44:55 +00:00
Inseob Kim 7f61fe7486 Refactor callback and make payload stream duplex
Guest VMs now directly call onPayloadStarted to tell the host that their
payload started. And the stream passed by onPayloadStarted is now duplex
so it can also be used as an input stream, which will be fed to the
payload's stdin.

Bug: 191845268
Bug: 195381416
Test: run MicrodroidDemoApp and see output
Test: atest MicrodroidHostTestCases ComposHostTestCases AuthFsHostTest
Change-Id: Ic72045b4e4d11ab1efb14cb2e95de319ca8f9f97
2021-08-24 21:15:42 +09:00
Jiyong Park 0a2484304d Create idsig file automatically
Before a VM is started, the idsig file is created (or updated) by the
virtualization service. This is needed because the idsig file is usually
not available, especially when the APK is downloaded from the store.

Note that the generated idsig file is not a signed one. Therefore, the
APK is first verified using the APK signature scheme V3 (or V2) over a
dm-verity device backed by the APK and the merkle tree (and root hash)
from the idsig file. Only if the verification is successful, the root
hash stored to the instance.img and then used for the subsequent boots
of the VM.

Bug: 193504400
Test: atest MicrodroidHostTestCases
Test: run MicrodroidDemoApp without having the idsig file in
/data/local/tmp/virt.

Change-Id: I9fad05ca9562ae0666431102a8147d0f76f04e6a
2021-08-20 23:41:11 +09:00
Jiyong Park 48c9aebb4c update the doc
Rooting and disabling selinux are not longer required.

Bug: N/A
Test: N/A

Change-Id: I2c462caecb68d3bffca8026058d62b90821ba464
2021-07-27 20:20:55 +09:00
Jiyong Park 753553bdb8 Access control for virtualizationservice
The access to the virtualizationservice is now controlled via Android
permissions:

* android.permission.MANAGE_VIRTUAL_MACHINE
* android.permission.DEBUG_VIRTUAL_MACHINE

The two permissions are defined in a resource-only APK
android.system.virtualmachine.res. Virtualizationservice is modified to
do the permission check by using the permission controller service.

Bug: 168588769
Test: /apex/com.android.virt/bin/vm run-app --log /dev/null
/data/local/tmp/virt/MicrodroidDemoApp.apk
/data/local/tmp/virt/MicrodroidDemoApp.apk.idsig assets/vm_config.json

Change-Id: Id210d2a55bc57bf03200c3c8546e3c63aa2a4c52
2021-07-13 22:02:32 +09:00
Jiyong Park 8611a6c9f6 Add the onPayloadStarted callback API
The API is called back to the client when the payload starts in the VM.
The standard output from the payload is accessible via the
ParcelFileDescriptor argument as well.

Bug: 192904048
Test: run MicrodroidDemoApp and check that the payload output is shown.

Change-Id: Ie2afbb455496eec21617b94940ed4386a4865876
2021-07-13 10:58:41 +09:00
Jiyong Park 58db9e82d3 Merge "Implement missing APIs" 2021-07-11 23:57:49 +00:00
Jiyong Park f7516cb4be Implement missing APIs
Bug: 183496040
Test: atest MicrodroidHostTest
Test: run MicrodroidDemoApp
Change-Id: I1ee057726b0c83f8fa24bc6fabaa4c7b6ae851d2
2021-07-09 18:27:59 +09:00
Jiyong Park c68547c7bd Add README for the demo app
Bug: N/A
Test: follow the instruction
Change-Id: Idf63b009c9bccf3ece2ec2079fa92b5c6600ca47
2021-07-08 20:59:54 +09:00
Jiyong Park af1a74b084 Add API for configuring a VM to run in debug mode
Bug: 185211964
Test: run the demo app
Change-Id: I960839037b2f23dbce1552199d9c9e59c36053e2
2021-07-07 15:28:08 +09:00
Jiyong Park b02e95f2a0 Add microdroid demo app
Add a demo app showing how an app can start a VM.

Bug: N/A
Test: TARGET_BUILD_APPS=MicrodroidDemoApp m apps_only dist
adb install out/dist/MicrodroidDemoApp.apk
adb push out/dist/MicrodroidDemoApp.apk.idsig /data/local/tmp/virt/
adb root
adb shell start virtualizationservice
<then launch the app>

Change-Id: If46b2f8910b98b2b29ca0c629e1f7eacc01a477a
2021-07-06 21:31:28 +09:00