pvmfw: Encrypt instance.img entries
As the host owns the files backing the virtio-blk devices, encrypt the
entries in a tamper-evident way.
Derive the private key used for encryption from the sealing CDI. Note
that this patch uses a _randnonce() AEAD but doesn't provide entropy,
which will be added in a future patch.
Implement a wrapper for BoringSSL AEAD functions, key derivation,
hashing, and error handling. Implement the CRYPTO_sysrand* symbols those
require.
Add sterror(), required by ERR_reason_error_string, to vmbase instead of
using the Bionic version, which is harder to integrate due to
thread-safety support and TLS layout. Error reporting also requires the
standard bsearch() function.
Note: Entries added to an instance.img before applying this patch will
now be rejected.
Bug: 249723852
Test: atest MicrodroidHostTests
Change-Id: If41aa8e1961121d9aee116c14b54d983dd10f61e
diff --git a/pvmfw/src/main.rs b/pvmfw/src/main.rs
index 6545a07..48bab0c 100644
--- a/pvmfw/src/main.rs
+++ b/pvmfw/src/main.rs
@@ -21,6 +21,7 @@
extern crate alloc;
mod config;
+mod crypto;
mod debug_policy;
mod dice;
mod entry;
@@ -34,6 +35,7 @@
mod memory;
mod mmio_guard;
mod mmu;
+mod rand;
mod smccc;
mod virtio;
@@ -49,6 +51,7 @@
use crate::virtio::pci;
use diced_open_dice::bcc_handover_main_flow;
use diced_open_dice::bcc_handover_parse;
+use diced_open_dice::DiceArtifacts;
use fdtpci::{PciError, PciInfo};
use libfdt::Fdt;
use log::{debug, error, info, trace};
@@ -100,8 +103,9 @@
error!("Failed to compute partial DICE inputs: {e:?}");
RebootReason::InternalError
})?;
- let (new_instance, salt) =
- get_or_generate_instance_salt(&mut pci_root, &dice_inputs).map_err(|e| {
+ let cdi_seal = DiceArtifacts::cdi_seal(&bcc_handover);
+ let (new_instance, salt) = get_or_generate_instance_salt(&mut pci_root, &dice_inputs, cdi_seal)
+ .map_err(|e| {
error!("Failed to get instance.img salt: {e}");
RebootReason::InternalError
})?;