Skip to content

Commit f1eb2a6

Browse files
committed
Merge branch 'dimstav23/diff_attest_reports' into dev
2 parents b68ce76 + 86087de commit f1eb2a6

File tree

8 files changed

+374
-84
lines changed

8 files changed

+374
-84
lines changed

kernel/src/attestation/monitor.rs

+308-60
Large diffs are not rendered by default.

kernel/src/greq/pld_report.rs

+8
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ impl SnpReportResponse {
111111

112112
Ok(())
113113
}
114+
115+
pub fn get_report(&self) -> &AttestationReport {
116+
&self.report
117+
}
118+
119+
pub fn get_report_size(&self) -> u32 {
120+
self.report_size
121+
}
114122
}
115123

116124
/// The `TCB_VERSION` contains the security version numbers of each

kernel/src/process_manager/allocation.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::mm::PAGE_SIZE;
33
use crate::address::{Address, VirtAddr};
44
use crate::process_manager::process_paging::ProcessPageTableRef;
55
use crate::process_manager::process_paging::ProcessPageFlags;
6+
use super::process_memory::{ALLOCATION_RANGE_VIRT_START, PGD};
67
use crate::cpu::control_regs::read_cr3;
78
use crate::sev::{rmp_adjust, RMPFlags};
89
use crate::types::PageSize;
@@ -19,6 +20,9 @@ pub struct AllocationRange(pub u64, pub u64);
1920
impl AllocationRange {
2021

2122
pub fn allocate(&mut self, pages: u64){
23+
// Allocates a new memory range for the Monitor
24+
// Currently the start virtual address is fixed to ALLOCATION_RANGE_VIRT_START
25+
// Reuses the Process page managment to add new memory to the Monitor
2226
let mut page_table_ref = ProcessPageTableRef::default();
2327
page_table_ref.set_external_table(read_cr3().bits() as u64);
2428
self.allocate_(&mut page_table_ref, pages, ALLOCATION_VADDR_START, true, false);
@@ -54,9 +58,9 @@ impl AllocationRange {
5458
self.0 = pgd[DEFAULT_ALLOCATION_RANGE_MOUNT];
5559
self.1 = pages;
5660
} else {
57-
let offset = start_addr >> PGD_SHIFT;
61+
let offset: usize = start_address.to_pgtbl_idx::<PGD>();
5862
let (_mapping, pgd) = paddr_as_slice!(page_table_ref.process_page_table);
59-
self.0 = pgd[offset as usize];
63+
self.0 = pgd[offset];
6064
self.1 = pages;
6165
}
6266
}

kernel/src/process_manager/call_handler.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use crate::attestation;
44
use crate::process_manager::process::TrustedProcessType;
55

66
const MONITOR_INIT: u32 = 0;
7-
const ATTEST_MONITOR: u32 = 1;
8-
//const LOAD_POLICY: u32 = 2;
7+
// const MONITOR: u32 = 1;
8+
const DIFF_ATTEST: u32 = 2;
9+
//const LOAD_POLICY: u32 = 3;
910
const CREATE_ZYGOTE: u32 = 4;
1011
const DELETE_ZYGOTE: u32 = 5;
1112
const CREATE_TRUSTLET: u32 = 6;
@@ -14,16 +15,22 @@ const INVOKE_TRUSTLET: u32 = 8;
1415

1516
const GET_PUBLIC_KEY: u32 = 30;
1617
const SEND_POLICY: u32 = 31;
17-
pub fn attest_monitor(params: &mut RequestParams) -> Result<(), SvsmReqError>{
18-
attestation::monitor::attest_monitor(params)
18+
19+
pub fn diff_attestation(params: &mut RequestParams) -> Result<(), SvsmReqError>{
20+
attestation::monitor::diff_attestation(params)
1921
}
2022

21-
fn monitor_init(_params: &mut RequestParams) -> Result<(), SvsmReqError>{
23+
fn monitor_init(params: &mut RequestParams) -> Result<(), SvsmReqError>{
2224

2325
log::info!("Initilization Monitor");
26+
27+
/* Request a monitor measurement upon initialization */
28+
params.rdx = attestation::monitor::MONITOR_ATTESTATION;
29+
params.rcx = 0;
30+
let _ = attestation::monitor::diff_attestation(params);
2431
//add_monitor_memory();
2532
//super::process::PROCESS_STORE.init(10);
26-
// crate::sp_pagetable::set_ecryption_mask_address_size();
33+
//crate::sp_pagetable::set_ecryption_mask_address_size();
2734
log::info!("Initilization Done");
2835
Ok(())
2936
}
@@ -60,7 +67,7 @@ pub fn monitor_call_handler(request: u32, params: &mut RequestParams) -> Result<
6067
log::info!("request: {}",request);
6168
match request {
6269
MONITOR_INIT => monitor_init(params),
63-
ATTEST_MONITOR => attest_monitor(params),
70+
DIFF_ATTEST => diff_attestation(params),
6471
CREATE_ZYGOTE => create_zygote(params),
6572
DELETE_ZYGOTE => delete_zygote(params),
6673
CREATE_TRUSTLET => create_trustlet(params),

kernel/src/process_manager/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use memory_helper::set_ecryption_mask_address_size;
2-
use process::PROCESS_STORE;
32
use process_memory::additional_monitor_memory_init;
3+
pub use process::PROCESS_STORE;
44

55
use crate::utils::immut_after_init::ImmutAfterInitCell;
66

kernel/src/process_manager/process.rs

+26-8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use cpuarch::vmsa::VMSA;
2828
use core::mem::replace;
2929

3030
use super::memory_channels::MemoryChannel;
31+
use crate::attestation::monitor::{ProcessMeasurements, measure};
3132

3233
trait FromVAddr {
3334
fn from_virt_addr(v: VirtAddr) -> &'static mut VMSA;
@@ -114,7 +115,9 @@ pub struct ProcessID(pub usize);
114115
pub struct TrustedProcess {
115116
pub process_type: TrustedProcessType,
116117
pub id: u64,
118+
pub parent_id: u64,
117119
pub base: ProcessBaseContext,
120+
pub measurements: ProcessMeasurements,
118121
#[allow(dead_code)]
119122
pub context: ProcessContext,
120123
//pub channel: MemoryChannel,
@@ -138,36 +141,47 @@ impl TrustedProcess {
138141
let libos_size= zygote_data_struct[5];
139142

140143

141-
// The allocation is always starting at the same virtual address which is why only one allocaiton is valid
144+
// The allocation (AllocationRange) is always starting at the same virtual address which is why only one allocaiton is valid
142145
// at the same time. TODO: Allow for different start addresses
143-
let (pal_data, pal_range) = ProcessPageTableRef::copy_data_from_guest(pal, pal_size, pgt);
144146
let mut base = ProcessBaseContext::default();
147+
let mut measurements = ProcessMeasurements::default();
148+
149+
let (pal_data, pal_range) = ProcessPageTableRef::copy_data_from_guest(pal, pal_size, pgt);
145150
base.init_with_data(pal_data, pal_size, pal_range);
151+
measurements.init_measurement = measure(pal_data.into(), pal_size);
152+
146153
let (manifest_data, manifest_range) = ProcessPageTableRef::copy_data_from_guest(manifest, manifest_size, pgt);
147154
base.add_manifest(manifest_data, manifest_size, manifest_range);
155+
measurements.manifest_measurement = measure(manifest_data.into(), manifest_size);
156+
148157
let(libos_data, libos_range) = ProcessPageTableRef::copy_data_from_guest(libos, libos_size, pgt);
149158
base.add_libos(libos_data, libos_size, libos_range);
150-
159+
measurements.libos_measurement = measure(libos_data.into(), libos_size);
151160

152161
// TODO: Free zygote data
153162
Self {
154163
process_type: TrustedProcessType::Zygote,
155164
id: 0,
165+
parent_id: 0,
156166
base,
167+
measurements,
157168
context: ProcessContext::default(),
158169
}
159170
}
160171

161172
fn dublicate(pid: ProcessID) -> TrustedProcess {
162173
let process = PROCESS_STORE.get(pid);
163174
let base: ProcessBaseContext = process.base;
175+
let measurements: ProcessMeasurements = process.measurements;
164176
let mut context = ProcessContext::default();
165-
context.init(base);
177+
context.init(base, measurements);
166178

167179
TrustedProcess {
168180
process_type: TrustedProcessType::Trustlet,
169181
id: 0,
182+
parent_id: pid.0 as u64, // set the id of the parent zygote
170183
base,
184+
measurements,
171185
context,
172186
}
173187

@@ -189,7 +203,9 @@ impl TrustedProcess {
189203
Self {
190204
process_type: TrustedProcessType::Undefined,
191205
id: 0,
206+
parent_id: 0,
192207
base: ProcessBaseContext::default(),
208+
measurements: ProcessMeasurements::default(),
193209
context: ProcessContext::default(),
194210
}
195211
}
@@ -337,9 +353,9 @@ impl ProcessBaseContext {
337353
self.alloc_range_manifest = data;
338354
}
339355

340-
pub fn add_libos(&mut self, manifest: VirtAddr, size: u64, data: AllocationRange){
356+
pub fn add_libos(&mut self, libos: VirtAddr, size: u64, data: AllocationRange){
341357
let size = (4096 - (size & 0xFFF)) + size;
342-
self.page_table_ref.add_libos(manifest,size);
358+
self.page_table_ref.add_libos(libos,size);
343359
self.alloc_range_libos = data;
344360
}
345361

@@ -356,6 +372,7 @@ pub struct ProcessContext {
356372
pub vmsa: PhysAddr,
357373
pub channel: MemoryChannel,
358374
pub sev_features: u64,
375+
pub measurements: ProcessMeasurements,
359376
}
360377

361378
impl Default for ProcessContext {
@@ -365,14 +382,15 @@ impl Default for ProcessContext {
365382
vmsa: PhysAddr::null(),
366383
channel: MemoryChannel::default(),
367384
sev_features: 0,
385+
measurements: ProcessMeasurements::default(),
368386
}
369387
}
370388
}
371389

372390

373391
impl ProcessContext {
374392

375-
pub fn init(&mut self, base: ProcessBaseContext) {
393+
pub fn init(&mut self, base: ProcessBaseContext, measurements: ProcessMeasurements) {
376394

377395
//Creating new VMSA for the Process
378396
let new_vmsa_page = allocate_page();
@@ -424,7 +442,7 @@ impl ProcessContext {
424442
self.vmsa = new_vmsa_page;
425443
self.sev_features = vmsa.sev_features;
426444
self.base = base;
427-
445+
self.measurements = measurements;
428446
}
429447

430448
pub fn add_function(&mut self, function: VirtAddr, size: u64) {

kernel/src/process_manager/process_memory.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct ProcessMemConfig {
4040
free_page_list_table_entry: u64,
4141
}
4242

43-
pub const ALLOCATION_RANGE_VIRT_START: u64 = 0x30000000000u64;
43+
pub const ALLOCATION_RANGE_VIRT_START: u64 = 0x300_0000_0000u64;
4444

4545
static PROCESS_MEM_CONFIG: SpinLock<ProcessMemConfig> = SpinLock::new(ProcessMemConfig::new());
4646
pub static CPU_COUNT: ImmutAfterInitCell<u64> = ImmutAfterInitCell::new(0);
@@ -52,7 +52,7 @@ const MiB: usize = KiB * 1024;
5252
#[allow(non_upper_case_globals)]
5353
const GiB: usize = MiB * 1024;
5454

55-
const ADDRESS_START_FREE_PAGE_LIST: usize = 0x8000000000;
55+
const ADDRESS_START_FREE_PAGE_LIST: usize = 0x80_0000_0000;
5656

5757
const CONDITION_MIN_MEM_SIZE: usize = 1 * GiB;
5858

@@ -74,7 +74,7 @@ impl ProcessMemConfig{
7474
initilized: false,
7575
total_size: 0,
7676
free: 0,
77-
free_page_list: 0x8000000000u64,
77+
free_page_list: ADDRESS_START_FREE_PAGE_LIST as u64,
7878
free_page_list_used_len: 0,
7979
page_top: PhysAddr::null(),
8080
page_base: PhysAddr::null(),

kernel/src/process_manager/process_paging.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ use crate::process_manager::allocation::AllocationRange;
1515
use core::ffi::CStr;
1616
use super::memory_helper::{ZERO_PAGE};
1717

18+
// TP: Trusted Process
19+
const TP_STACK_START_VADDR: u64 = 0x80_0000_0000;
20+
const TP_MANIFEST_START_VADDR: u64 = 0x100_0000_0000;
21+
const TP_LIBOS_START_VADDR: u64 = 0x180_0000_0000;
22+
1823
// Flags for the Page Table
1924
// In general all Trusted Processes need to
2025
// have user accessable set
@@ -269,21 +274,21 @@ impl ProcessPageTableRef {
269274
self.add_region(program_header, elf_file );
270275
}
271276
//Add stack
272-
self.add_stack(VirtAddr::from(0x8000000000usize), 8);
277+
self.add_stack(VirtAddr::from(TP_STACK_START_VADDR), 8);
273278
self.print_table();
274279
VirtAddr::from(elf.elf_hdr.e_entry)
275280
}
276281

277282
pub fn add_manifest(&self, data: VirtAddr, size: u64) {
278283
let data: *mut u8 = data.as_mut_ptr::<u8>();
279284
let data = unsafe { slice::from_raw_parts(data, size as usize) };
280-
self.add_region_vaddr(VirtAddr::from(0x10000000000u64), data);
285+
self.add_region_vaddr(VirtAddr::from(TP_MANIFEST_START_VADDR), data);
281286
}
282287

283288
pub fn add_libos(&self, data: VirtAddr, size: u64) {
284289
let data: *mut u8 = data.as_mut_ptr::<u8>();
285290
let data = unsafe { slice::from_raw_parts(data, size as usize) };
286-
self.add_region_vaddr(VirtAddr::from(0x18000000000u64), data);
291+
self.add_region_vaddr(VirtAddr::from(TP_LIBOS_START_VADDR), data);
287292
}
288293

289294
pub fn add_function(&self, data:VirtAddr, size: u64) {

0 commit comments

Comments
 (0)