Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eventlog for Stage0 #5029

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
57a735a
Stage0 attestation
souravdasgupta Sep 7, 2023
452d52c
Stage0 attestation
souravdasgupta Sep 7, 2023
d474874
Merge branch 'souravd_oak' of https://github.com/project-oak/oak into…
souravdasgupta Sep 7, 2023
3710dc7
Move the attestation related code to different file.
souravdasgupta Sep 7, 2023
4f6d3e2
Move the attestation related code to different file.
souravdasgupta Sep 7, 2023
c9ce389
Merge branch 'souravd_oak' of https://github.com/project-oak/oak into…
souravdasgupta Sep 7, 2023
3f66c9d
Add code for signing measurements
souravdasgupta Sep 12, 2023
9fb044e
Address many of the review comments.
souravdasgupta Sep 21, 2023
9fb7bc7
Address additional review comments.
souravdasgupta Sep 22, 2023
3e8a664
Made changes to fix the checks that were failing.
souravdasgupta Oct 11, 2023
6ff8047
Reverting name changed for Stage 0 signer class due to check failure.
souravdasgupta Oct 11, 2023
90be88f
Fixing the return type to pass checks
souravdasgupta Oct 11, 2023
03e19ca
Merge https://github.com/project-oak/oak into souravd_oak
souravdasgupta Oct 16, 2023
0602f01
DICE related changes to existing code
souravdasgupta Oct 25, 2023
d26dbaa
Merge https://github.com/project-oak/oak into souravd_oak
souravdasgupta Oct 25, 2023
1d00236
syncing with head
souravdasgupta Oct 25, 2023
057d2bc
Merge https://github.com/project-oak/oak into souravd_oak
souravdasgupta Oct 31, 2023
aeb28e6
Merge https://github.com/project-oak/oak into souravd_oak
souravdasgupta Nov 3, 2023
3e32a24
Merge https://github.com/project-oak/oak into souravd_oak
souravdasgupta Feb 6, 2024
cf674fc
Merge https://github.com/project-oak/oak into souravd_oak
souravdasgupta Mar 14, 2024
157bb46
Merge https://github.com/project-oak/oak into souravd_oak
souravdasgupta Mar 25, 2024
d629f81
Merge https://github.com/project-oak/oak into souravd_oak
souravdasgupta Mar 29, 2024
94834bc
Merge https://github.com/project-oak/oak into souravd_oak
souravdasgupta Apr 5, 2024
2c1dbbd
Merge https://github.com/project-oak/oak into souravd_oak
souravdasgupta Apr 25, 2024
56cddbc
Eventlog proto for stage 0
souravdasgupta May 1, 2024
6bc107f
Merge https://github.com/project-oak/oak into souravd_oak
souravdasgupta May 1, 2024
b7de511
Add all measurements and generate eventlog
souravdasgupta May 3, 2024
3a103c9
Fix errors due to previous changes.
souravdasgupta May 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions stage0/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ authors = ["Andri Saar <andrisaar@google.com>"]
edition = "2021"
license = "Apache-2.0"

[build-dependencies]
prost-build = { version = "*" }

[dependencies]
bitflags = "*"
coset = { version = "*", default-features = false }
Expand All @@ -23,6 +26,8 @@ p256 = { version = "*", default-features = false, features = ["ecdsa"] }
rand_core = { version = "*", default-features = false, features = [
"getrandom",
] }
prost = {version = "*", default-features = false, features = ["prost-derive"]}
prost-types = {version = "*", default-features = false}
sev_serial = { path = "../sev_serial" }
sha2 = { version = "*", default-features = false, features = ["force-soft"] }
spinning_top = "*"
Expand Down
8 changes: 8 additions & 0 deletions stage0/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extern crate prost_build;

fn main() {
let mut config = prost_build::Config::new();
config.btree_map(&["."]);
prost_build::compile_protos(&["src/eventlog.proto"],
&["src/"]).unwrap();
}
39 changes: 39 additions & 0 deletions stage0/src/eventlog.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
syntax = "proto2";

package eventlog;

import "google/protobuf/any.proto";

// All the related measurements for Stage 0.
message Stage0Measurements {
// Kernel setup data digest.
optional bytes setup_data_digest = 1;
// Kernel digest.
optional bytes kernel_measurement = 2;
// Initial RAM disk digest.
optional bytes ram_disk_digest = 3;
// E820 table digest
optional bytes memory_map_digest = 4;
// ACPI table generation digest
optional bytes acpi_digest = 5;
// Kernel Command line.
optional string kernel_cmdline = 6;
}

// Represents an event intended for inclusion in attestation.
// For example, in an attested measured boot, each event is a reference to the
// code identity of the boot layer being launched next.
// An Event message must have a canonical serialization and contain what's
// necessary for an attestation verifier to verify the Event against a Reference
// Value.
message Event {
// Represents what is contains in the event. For example, the tag for
// TaskConfig for the Layer 2 is "layer2".
optional string tag = 1;
optional google.protobuf.Any event = 2;
}

// A sequence of Events intended for inclusion in attestation evidence.
message EventLog {
repeated Event events = 1;
}
59 changes: 58 additions & 1 deletion stage0/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@

extern crate alloc;

use alloc::{boxed::Box, format};
use alloc::{boxed::Box, format, string::String};
use core::{arch::asm, ffi::c_void, mem::MaybeUninit, panic::PanicInfo};

use linked_list_allocator::LockedHeap;
use oak_core::sync::OnceCell;
use oak_dice::evidence::{TeePlatform, DICE_DATA_CMDLINE_PARAM};
use oak_linux_boot_params::{BootE820Entry, E820EntryType};
use oak_sev_guest::{io::PortFactoryWrapper, msr::SevStatus};
use prost::{Message, Name};
use prost_types::Any;
use sha2::{Digest, Sha256};
use x86_64::{
instructions::{hlt, interrupts::int3},
Expand Down Expand Up @@ -61,6 +63,10 @@ mod sev;
mod smp;
mod zero_page;

pub mod eventlog {
include!(concat!(env!("OUT_DIR"), "/eventlog.rs"));
}

type Measurement = [u8; 32];

// Reserve 128K for boot data structures that will outlive Stage 0.
Expand Down Expand Up @@ -339,13 +345,34 @@ pub fn rust64_start(encrypted: u64) -> ! {
),
&crate::BOOT_ALLOC,
));

// Reserve the memory containing the DICE data.
zero_page.insert_e820_entry(BootE820Entry::new(
dice_data.as_bytes().as_ptr() as usize,
dice_data.as_bytes().len(),
E820EntryType::RESERVED,
));

// Generate Stage0 Event Log data.
let mut stage0event = eventlog::Stage0Measurements::default();
stage0event.kernel_measurement = Some(kernel_info.measurement.as_bytes().to_vec());
stage0event.acpi_digest = Some(acpi_sha2_256_digest.as_bytes().to_vec());
stage0event.memory_map_digest = Some(memory_map_sha2_256_digest.as_bytes().to_vec());
stage0event.ram_disk_digest = Some(ram_disk_sha2_256_digest.as_bytes().to_vec());
stage0event.setup_data_digest = Some(setup_data_sha2_256_digest.as_bytes().to_vec());
stage0event.kernel_cmdline = Some(cmdline.clone());
let event_log = Box::leak(Box::new_in(
generate_event_log(stage0event),
&crate::BOOT_ALLOC,
));
log::info!("event tag = {:?}", event_log);
// Reserve memory containing Eventlog Data.
zero_page.insert_e820_entry(BootE820Entry::new(
event_log.encode_to_vec().as_bytes().as_ptr() as usize,
event_log.encode_to_vec().as_bytes().len(),
E820EntryType::RESERVED,
));

// Append the DICE data address to the kernel command-line.
let extra = format!("--{DICE_DATA_CMDLINE_PARAM}={dice_data:p}");
let cmdline = if kernel_info.kernel_type == KernelType::Elf {
Expand Down Expand Up @@ -414,3 +441,33 @@ fn io_port_factory() -> PortFactoryWrapper {
PortFactoryWrapper::new_raw()
}
}

const PACKAGE: &str = "google.protobuf";

/// Compute the type URL for the given `google.protobuf` type, using
/// `type.googleapis.com` as the authority for the URL.
fn type_url_for<T: Name>() -> String {
format!("type.googleapis.com/{}.{}", T::PACKAGE, T::NAME)
}

impl Name for eventlog::Stage0Measurements {
const PACKAGE: &'static str = PACKAGE;
const NAME: &'static str = "Stage0";

fn type_url() -> String {
type_url_for::<Self>()
}
}

fn generate_event_log(measurements: eventlog::Stage0Measurements) -> eventlog::EventLog {
let mut event = eventlog::Event::default();
let mut str = String::new();
let any = Any::from_msg(&measurements);
str.push_str("Stage0");
let m = Some(str);
event.tag = m;
event.event = Some(any.unwrap());
let mut eventlog = eventlog::EventLog::default();
eventlog.events.push(event);
eventlog
}