Skip to content

Commit 1ebdebf

Browse files
authored
Fix attestation secret release, key naming, and tests (#144)
Signed-off-by: Wojciech Ozga <woz@zurich.ibm.com>
1 parent ef0ca0f commit 1ebdebf

9 files changed

Lines changed: 19 additions & 16 deletions

File tree

‎confidential-vms/linux_vm/Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ overlay: setup
8080
rm -rf $(HYPERVISOR_OVERLAY_LINUX_VM_DIR) && mkdir -p $(HYPERVISOR_OVERLAY_LINUX_VM_DIR) ;\
8181
rm -f $(LINUX_VM_COVE_TAP_QEMU) ;\
8282
$(eval $@_TMP = $(shell $(TOOLS_WORK_DIR)/cove-tap-tool measure --base-address=0x80000000 --kernel-file=$(LINUX_VM_IMAGE) | cut -d' ' -f2-;) )
83-
$(TOOLS_WORK_DIR)/cove-tap-tool generate --pcrs 4=$($@_TMP) --secrets 0=0xc0ffee --output-file=$(LINUX_VM_COVE_TAP_QEMU)
83+
$(TOOLS_WORK_DIR)/cove-tap-tool generate --pcrs 4=$($@_TMP) --secrets 0=0xc0ffeec0ffeec0ffeec0ffee --output-file=$(LINUX_VM_COVE_TAP_QEMU)
8484
cp $(LINUX_VM_COVE_TAP_QEMU) $(HYPERVISOR_OVERLAY_LINUX_VM_DIR)/
8585
cp $(LINUX_VM_IMAGE) $(HYPERVISOR_OVERLAY_LINUX_VM_DIR)/
8686
cp $(LINUX_VM_BUILDROOT_ROOTFS) $(HYPERVISOR_OVERLAY_LINUX_VM_DIR)
8787
rm -f $(LINUX_VM_COVE_TAP_KVMTOOL)
8888
$(eval $@_TMP = $(shell $(TOOLS_WORK_DIR)/cove-tap-tool measure --base-address=0x80200000 --kernel-file=$(LINUX_VM_IMAGE) | cut -d' ' -f2-;) )
89-
$(TOOLS_WORK_DIR)/cove-tap-tool generate --pcrs 4=$($@_TMP) --secrets 0=0xc0ffee --output-file=$(LINUX_VM_COVE_TAP_KVMTOOL)
89+
$(TOOLS_WORK_DIR)/cove-tap-tool generate --pcrs 4=$($@_TMP) --secrets 0=0xc0ffeec0ffeec0ffeec0ffee --output-file=$(LINUX_VM_COVE_TAP_KVMTOOL)
9090
cp $(LINUX_VM_COVE_TAP_KVMTOOL) $(HYPERVISOR_OVERLAY_LINUX_VM_DIR)/
9191

9292

‎hypervisor/rootfs/test_attestation.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ wait_for_ssh $TVM_USER $TVM_HOST $TVM_PORT
1717
$SSH_CMD -p${TVM_PORT} ${TVM_USER}@${TVM_HOST} 'insmod /root/ace_module/ace.ko'
1818
$SSH_CMD -p${TVM_PORT} ${TVM_USER}@${TVM_HOST} 'dmesg | grep Secret' > tmp_dmesg.log
1919

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

2222
kill_confidential_vm
2323
sleep 5

‎security-monitor/rust-crates/riscv_cove_tap/src/spec.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,22 @@ impl Digest {
141141
#[derive(Debug, PartialEq, Eq)]
142142
pub enum DigestAlgorithm {
143143
Debug = 0,
144-
Sha512 = 1,
144+
Sha3_256 = 1,
145145
}
146146

147147
impl DigestAlgorithm {
148148
pub fn from_u16(value: u16) -> Result<Self, TapError> {
149149
match value {
150150
0 => Ok(Self::Debug),
151-
1 => Ok(Self::Sha512),
151+
1 => Ok(Self::Sha3_256),
152152
v => Err(TapError::UnsupportedDigestAlgorithm(v)),
153153
}
154154
}
155155

156156
pub fn digest_size(&self) -> u16 {
157157
match self {
158158
&Self::Debug => 0,
159-
&Self::Sha512 => 512 / 8,
159+
&Self::Sha3_256 => 512 / 8,
160160
}
161161
}
162162
}

‎security-monitor/src/confidential_flow/handlers/attestation/retrieve_secret.rs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ impl RetrieveSecretRequest {
3232
ensure!(self.output_buffer_size <= PageSize::Size4KiB.in_bytes(), Error::AddressNotAligned())?;
3333
let secret = confidential_vm.secret(0)?;
3434
ensure!(secret.len() <= self.output_buffer_size, Error::AddressNotAligned())?;
35-
let mut buffer = [0u8; 8];
36-
for offset in 0..secret.len().div_ceil(8) {
37-
let end_boundary = core::cmp::min(secret.len(), offset + 8);
38-
(0..end_boundary).for_each(|i| buffer[i] = secret[offset + i]);
39-
(end_boundary..8).for_each(|i| buffer[i] = 0u8);
35+
const WORD_SIZE: usize = core::mem::size_of::<usize>();
36+
for chunk in 0..secret.len().div_ceil(WORD_SIZE) {
37+
let byte_offset = chunk * WORD_SIZE;
38+
let chunk_len = core::cmp::min(WORD_SIZE, secret.len() - byte_offset);
39+
let mut buffer = [0u8; WORD_SIZE];
40+
buffer[..chunk_len].copy_from_slice(&secret[byte_offset..byte_offset + chunk_len]);
4041
let confidential_memory_address =
41-
confidential_vm.memory_protector().translate_address(&output_buffer_address.add(offset))?;
42+
confidential_vm.memory_protector().translate_address(&output_buffer_address.add(byte_offset))?;
4243
unsafe { confidential_memory_address.write_volatile(usize::from_le_bytes(buffer)) };
4344
}
4445
Ok(SbiResponse::success_with_code(secret.len()))

‎security-monitor/src/core/architecture/riscv/pmp/mod.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@ fn clear_caches() {
4747
// See Section 3.7.2 of RISC-V privileged specification v1.12.
4848
// PMP translations can be cached and address translation can be done speculatively. Thus, it is adviced to flush caching structures.
4949
super::fence::sfence_vma();
50+
// flush G-stage TLBs
51+
super::fence::hfence_gvma();
5052
}

‎security-monitor/src/core/control_data/confidential_vm_mmio_region.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ impl ConfidentialVmMmioRegion {
2525
}
2626

2727
pub fn contains(&self, other: &Self) -> bool {
28-
self.base_address <= other.base_address && other.one_past_the_end_address < self.one_past_the_end_address
28+
self.base_address <= other.base_address && other.one_past_the_end_address <= self.one_past_the_end_address
2929
}
3030
}

‎security-monitor/src/core/initialization/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ extern "C" fn ace_setup_this_hart() {
237237
// the `MemoryLayout` has been already initialized by the boot hart.
238238
if let Err(error) = unsafe { HypervisorMemoryProtector::setup() } {
239239
debug!("Failed to setup hypervisor memory protector: {:?}", error);
240-
// TODO: block access to attestation keys/registers on this hart?
240+
// TODO: block access to attestation keys/registers on this hart or freeze
241241
return;
242242
}
243243

‎security-monitor/src/non_confidential_flow/handlers/cove_host_extension/promote_to_confidential_vm.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl PromoteToConfidentialVm {
207207
for digest in attestation_payload.digests.iter() {
208208
// codeql[rust/cleartext-logging] - digest values intentionally logged in debug builds
209209
debug!("Reference PCR{:?}={:?}=0x{}", digest.pcr_id, digest.algorithm, digest.value_in_hex());
210-
ensure!(digest.algorithm == riscv_cove_tap::DigestAlgorithm::Sha512, Error::LocalAttestationNotSupportedDigest())?;
210+
ensure!(digest.algorithm == riscv_cove_tap::DigestAlgorithm::Sha3_256, Error::LocalAttestationNotSupportedDigest())?;
211211
let pcr_value = MeasurementDigest::try_from(digest.value.as_slice()).map_err(|_| Error::LocalAttestationFailed())?;
212212
ensure!(measurements.compare(digest.pcr_id() as usize, pcr_value)?, Error::LocalAttestationFailed())?;
213213
}

‎tools/cove_tap_tool/src/generate.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn generate_tap(
5454
for (pcr_id, pcr_value) in pcrs.into_iter() {
5555
let tap_digest = Digest {
5656
pcr_id,
57-
algorithm: DigestAlgorithm::Sha512,
57+
algorithm: DigestAlgorithm::Sha3_256,
5858
value: pcr_value,
5959
};
6060
// codeql[rust/cleartext-logging] - intentional operator output for CLI tool

0 commit comments

Comments
 (0)