Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions confidential-vms/linux_vm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ overlay: setup
rm -rf $(HYPERVISOR_OVERLAY_LINUX_VM_DIR) && mkdir -p $(HYPERVISOR_OVERLAY_LINUX_VM_DIR) ;\
rm -f $(LINUX_VM_COVE_TAP_QEMU) ;\
$(eval $@_TMP = $(shell $(TOOLS_WORK_DIR)/cove-tap-tool measure --base-address=0x80000000 --kernel-file=$(LINUX_VM_IMAGE) | cut -d' ' -f2-;) )
$(TOOLS_WORK_DIR)/cove-tap-tool generate --pcrs 4=$($@_TMP) --secrets 0=0xc0ffee --output-file=$(LINUX_VM_COVE_TAP_QEMU)
$(TOOLS_WORK_DIR)/cove-tap-tool generate --pcrs 4=$($@_TMP) --secrets 0=0xc0ffeec0ffeec0ffeec0ffee --output-file=$(LINUX_VM_COVE_TAP_QEMU)
cp $(LINUX_VM_COVE_TAP_QEMU) $(HYPERVISOR_OVERLAY_LINUX_VM_DIR)/
cp $(LINUX_VM_IMAGE) $(HYPERVISOR_OVERLAY_LINUX_VM_DIR)/
cp $(LINUX_VM_BUILDROOT_ROOTFS) $(HYPERVISOR_OVERLAY_LINUX_VM_DIR)
rm -f $(LINUX_VM_COVE_TAP_KVMTOOL)
$(eval $@_TMP = $(shell $(TOOLS_WORK_DIR)/cove-tap-tool measure --base-address=0x80200000 --kernel-file=$(LINUX_VM_IMAGE) | cut -d' ' -f2-;) )
$(TOOLS_WORK_DIR)/cove-tap-tool generate --pcrs 4=$($@_TMP) --secrets 0=0xc0ffee --output-file=$(LINUX_VM_COVE_TAP_KVMTOOL)
$(TOOLS_WORK_DIR)/cove-tap-tool generate --pcrs 4=$($@_TMP) --secrets 0=0xc0ffeec0ffeec0ffeec0ffee --output-file=$(LINUX_VM_COVE_TAP_KVMTOOL)
cp $(LINUX_VM_COVE_TAP_KVMTOOL) $(HYPERVISOR_OVERLAY_LINUX_VM_DIR)/


Expand Down
2 changes: 1 addition & 1 deletion hypervisor/rootfs/test_attestation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ wait_for_ssh $TVM_USER $TVM_HOST $TVM_PORT
$SSH_CMD -p${TVM_PORT} ${TVM_USER}@${TVM_HOST} 'insmod /root/ace_module/ace.ko'
$SSH_CMD -p${TVM_PORT} ${TVM_USER}@${TVM_HOST} 'dmesg | grep Secret' > tmp_dmesg.log

ATTESTATION_RESULT="$(grep 'Secret=0xc0ffee' tmp_dmesg.log | wc -l)"
ATTESTATION_RESULT="$(grep 'Secret=0xc0ffeec0ffeec0ffeec0ffee' tmp_dmesg.log | wc -l)"

kill_confidential_vm
sleep 5
Expand Down
6 changes: 3 additions & 3 deletions security-monitor/rust-crates/riscv_cove_tap/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,22 @@ impl Digest {
#[derive(Debug, PartialEq, Eq)]
pub enum DigestAlgorithm {
Debug = 0,
Sha512 = 1,
Sha3_256 = 1,
}

impl DigestAlgorithm {
pub fn from_u16(value: u16) -> Result<Self, TapError> {
match value {
0 => Ok(Self::Debug),
1 => Ok(Self::Sha512),
1 => Ok(Self::Sha3_256),
v => Err(TapError::UnsupportedDigestAlgorithm(v)),
}
}

pub fn digest_size(&self) -> u16 {
match self {
&Self::Debug => 0,
&Self::Sha512 => 512 / 8,
&Self::Sha3_256 => 512 / 8,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ impl RetrieveSecretRequest {
ensure!(self.output_buffer_size <= PageSize::Size4KiB.in_bytes(), Error::AddressNotAligned())?;
let secret = confidential_vm.secret(0)?;
ensure!(secret.len() <= self.output_buffer_size, Error::AddressNotAligned())?;
let mut buffer = [0u8; 8];
for offset in 0..secret.len().div_ceil(8) {
let end_boundary = core::cmp::min(secret.len(), offset + 8);
(0..end_boundary).for_each(|i| buffer[i] = secret[offset + i]);
(end_boundary..8).for_each(|i| buffer[i] = 0u8);
const WORD_SIZE: usize = core::mem::size_of::<usize>();
for chunk in 0..secret.len().div_ceil(WORD_SIZE) {
let byte_offset = chunk * WORD_SIZE;
let chunk_len = core::cmp::min(WORD_SIZE, secret.len() - byte_offset);
let mut buffer = [0u8; WORD_SIZE];
buffer[..chunk_len].copy_from_slice(&secret[byte_offset..byte_offset + chunk_len]);
let confidential_memory_address =
confidential_vm.memory_protector().translate_address(&output_buffer_address.add(offset))?;
confidential_vm.memory_protector().translate_address(&output_buffer_address.add(byte_offset))?;
unsafe { confidential_memory_address.write_volatile(usize::from_le_bytes(buffer)) };
}
Ok(SbiResponse::success_with_code(secret.len()))
Expand Down
2 changes: 2 additions & 0 deletions security-monitor/src/core/architecture/riscv/pmp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ fn clear_caches() {
// See Section 3.7.2 of RISC-V privileged specification v1.12.
// PMP translations can be cached and address translation can be done speculatively. Thus, it is adviced to flush caching structures.
super::fence::sfence_vma();
// flush G-stage TLBs
super::fence::hfence_gvma();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ impl ConfidentialVmMmioRegion {
}

pub fn contains(&self, other: &Self) -> bool {
self.base_address <= other.base_address && other.one_past_the_end_address < self.one_past_the_end_address
self.base_address <= other.base_address && other.one_past_the_end_address <= self.one_past_the_end_address
}
}
2 changes: 1 addition & 1 deletion security-monitor/src/core/initialization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ extern "C" fn ace_setup_this_hart() {
// the `MemoryLayout` has been already initialized by the boot hart.
if let Err(error) = unsafe { HypervisorMemoryProtector::setup() } {
debug!("Failed to setup hypervisor memory protector: {:?}", error);
// TODO: block access to attestation keys/registers on this hart?
// TODO: block access to attestation keys/registers on this hart or freeze
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl PromoteToConfidentialVm {
for digest in attestation_payload.digests.iter() {
// codeql[rust/cleartext-logging] - digest values intentionally logged in debug builds
debug!("Reference PCR{:?}={:?}=0x{}", digest.pcr_id, digest.algorithm, digest.value_in_hex());
ensure!(digest.algorithm == riscv_cove_tap::DigestAlgorithm::Sha512, Error::LocalAttestationNotSupportedDigest())?;
ensure!(digest.algorithm == riscv_cove_tap::DigestAlgorithm::Sha3_256, Error::LocalAttestationNotSupportedDigest())?;
let pcr_value = MeasurementDigest::try_from(digest.value.as_slice()).map_err(|_| Error::LocalAttestationFailed())?;
ensure!(measurements.compare(digest.pcr_id() as usize, pcr_value)?, Error::LocalAttestationFailed())?;
}
Expand Down
2 changes: 1 addition & 1 deletion tools/cove_tap_tool/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn generate_tap(
for (pcr_id, pcr_value) in pcrs.into_iter() {
let tap_digest = Digest {
pcr_id,
algorithm: DigestAlgorithm::Sha512,
algorithm: DigestAlgorithm::Sha3_256,
value: pcr_value,
};
// codeql[rust/cleartext-logging] - intentional operator output for CLI tool
Expand Down
Loading