forked from confidential-containers/td-shim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create td-shim-interface crate for publishig
Signed-off-by: OuyangHang33 <[email protected]>
- Loading branch information
1 parent
36a9200
commit 814a8c7
Showing
59 changed files
with
239 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "td-shim-interface" | ||
version = "0.1.0" | ||
license = "BSD-2-Clause-Patent" | ||
description = "TD-shim metadata data structures and related functions. UEFI Platform Initializaiton data structures and accessors" | ||
|
||
edition = "2018" | ||
homepage = "https://github.com/confidential-containers/td-shim" | ||
repository = "https://github.com/confidential-containers/td-shim" | ||
readme = "README.md" | ||
keywords = ["td-shim", "TDX", "intel"] | ||
|
||
[dependencies] | ||
r-efi = "3.2.0" | ||
scroll = { version = "0.10", default-features = false, features = ["derive"] } | ||
zerocopy = { version = "0.7.31", features = ["derive"] } | ||
|
||
log = "0.4.13" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fconfidential-containers%2Ftd-shim.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fconfidential-containers%2Ftd-shim?ref=badge_shield) | ||
# TD-shim-interface - Confidential Containers Shim Firmware Interface | ||
|
||
## Documents | ||
|
||
* [TD-Shim specification](doc/tdshim_spec.md) | ||
|
||
* Introduction [PDF](doc/td-shim-introduction.pdf) and [conference talk](https://fosdem.org/2023/schedule/event/cc_online_rust/) | ||
|
||
## Introduction | ||
|
||
This td-shim-interface is to support user for creating data structures and functions required for td-shim, such as TdxMetadataDescriptor and TdxMetadataSection. | ||
Td-uefi-pi is used for UEFI Platform Initializaiton data structures and accessors. | ||
|
||
To import the data structure of metadata, TD HOB and related function, such as: | ||
``` | ||
use td_shim_interface::{TD_ACPI_TABLE_HOB_GUID, TD_E820_TABLE_HOB_GUID, TD_PAYLOAD_INFO_HOB_GUID}; | ||
use td_shim_interface::PayloadInfo; | ||
use td_shim_interface::acpi; | ||
use td_shim_interface::td_uefi_pi::{hob, pi, pi::guid} | ||
``` | ||
|
||
This is a Shim Firmware to support [Intel TDX](https://software.intel.com/content/www/us/en/develop/articles/intel-trust-domain-extensions.html). | ||
|
||
The API specification is at [td-shim specification](doc/tdshim_spec.md). | ||
|
||
The secure boot specification for td-shim is at [secure boot specification](doc/secure_boot.md) | ||
|
||
The design is at [td-shim design](doc/design.md). | ||
|
||
The threat model analysis is at [td-shim threat model](doc/threat_model.md). | ||
|
||
|
||
## License | ||
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fconfidential-containers%2Ftd-shim.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fconfidential-containers%2Ftd-shim?ref=badge_large) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// Copyright (c) 2022 Alibaba Cloud | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause-Patent | ||
|
||
#![no_std] | ||
|
||
use scroll::{Pread, Pwrite}; | ||
|
||
pub mod acpi; | ||
pub mod metadata; | ||
pub mod td_uefi_pi; | ||
|
||
use td_uefi_pi::pi::{self, guid}; | ||
|
||
// This GUID is used for ACPI GUID Extension HOB | ||
// Please refer to: | ||
// https://github.com/confidential-containers/td-shim/blob/main/doc/tdshim_spec.md#acpi-guid-extension-hob | ||
pub const TD_ACPI_TABLE_HOB_GUID: guid::Guid = guid::Guid::from_fields( | ||
0x6a0c5870, | ||
0xd4ed, | ||
0x44f4, | ||
[0xa1, 0x35, 0xdd, 0x23, 0x8b, 0x6f, 0xc, 0x8d], | ||
); | ||
|
||
// This GUID is used for TD Payload Info GUID Extension HOB | ||
// Please refer to: | ||
// https://github.com/confidential-containers/td-shim/blob/main/doc/tdshim_spec.md#td-payload-info-guid-extension-hob | ||
pub const TD_PAYLOAD_INFO_HOB_GUID: guid::Guid = guid::Guid::from_fields( | ||
0xb96fa412, | ||
0x461f, | ||
0x4be3, | ||
[0x8c, 0xd, 0xad, 0x80, 0x5a, 0x49, 0x7a, 0xc0], | ||
); | ||
|
||
// This GUID is used for E820 Memory Map GUID Extension HOB | ||
// Please refer to: | ||
// https://github.com/confidential-containers/td-shim/blob/main/doc/tdshim_spec.md#e820-memory-map-guid-extension-hob | ||
pub const TD_E820_TABLE_HOB_GUID: pi::guid::Guid = pi::guid::Guid::from_fields( | ||
0x8f8072ea, | ||
0x3486, | ||
0x4b47, | ||
[0x86, 0xa7, 0x23, 0x53, 0xb8, 0x8a, 0x87, 0x73], | ||
); | ||
|
||
#[repr(u32)] | ||
#[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
pub enum TdPayloadInfoHobType { | ||
/// Payload Binary is a PE/COFF or ELF executable image as payload. | ||
/// | ||
/// Entrypoint can be found by parsing the image header. This type image does not follow | ||
/// Linux boot protocol. A payload HOB is used to pass data from TdShim to payload. | ||
ExecutablePayload = 0, | ||
|
||
/// Payload Binary is bzImage, follow Linux boot protocol. | ||
/// | ||
/// The first 512 bytes are boot_param. (zero page). The entrypoint is start address of loaded | ||
/// 64bit Linux kernel plus 0x200 | ||
BzImage, | ||
|
||
/// Payload Binary is VMM loaded vmLinux, follow Linux boot protocol. | ||
/// | ||
/// The entrypoint is defined at HOB_PAYLOAD_INFO_TABLE.Entrypoint. | ||
RawVmLinux, | ||
|
||
/// Unknown Image type | ||
UnknownImage = u32::MAX, | ||
} | ||
|
||
impl From<&TdPayloadInfoHobType> for u32 { | ||
fn from(v: &TdPayloadInfoHobType) -> Self { | ||
*v as u32 | ||
} | ||
} | ||
|
||
impl From<u32> for TdPayloadInfoHobType { | ||
fn from(v: u32) -> Self { | ||
match v { | ||
0 => TdPayloadInfoHobType::ExecutablePayload, | ||
1 => TdPayloadInfoHobType::BzImage, | ||
2 => TdPayloadInfoHobType::RawVmLinux, | ||
_ => TdPayloadInfoHobType::UnknownImage, | ||
} | ||
} | ||
} | ||
|
||
#[repr(C)] | ||
#[derive(Default, Clone, Copy, Pread, Pwrite)] | ||
pub struct PayloadInfo { | ||
pub image_type: u32, | ||
pub reserved: u32, | ||
pub entry_point: u64, | ||
} | ||
|
||
/// Write three bytes from an integer value into the buffer. | ||
pub fn write_u24(data: u32, buf: &mut [u8; 3]) { | ||
assert!(data <= 0xffffff); | ||
buf[0] = (data & 0xFF) as u8; | ||
buf[1] = ((data >> 8) & 0xFF) as u8; | ||
buf[2] = ((data >> 16) & 0xFF) as u8; | ||
} | ||
|
||
// To protect against speculative attacks, place the LFENCE instruction after the range | ||
// check and branch, but before any code that consumes the checked value. | ||
pub fn speculation_barrier() { | ||
unsafe { core::arch::asm!("lfence") } | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_tdpayload_info_hob_type() { | ||
assert_eq!( | ||
TdPayloadInfoHobType::from(0), | ||
TdPayloadInfoHobType::ExecutablePayload | ||
); | ||
assert_eq!(TdPayloadInfoHobType::from(1), TdPayloadInfoHobType::BzImage); | ||
assert_eq!( | ||
TdPayloadInfoHobType::from(2), | ||
TdPayloadInfoHobType::RawVmLinux | ||
); | ||
assert_eq!( | ||
TdPayloadInfoHobType::from(3), | ||
TdPayloadInfoHobType::UnknownImage | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_write_u24() { | ||
let mut buf: [u8; 3] = [0; 3]; | ||
write_u24(0xffffff, &mut buf); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.