From 5b5309628c46e9e28ba35d57fd08a2308a9417ba Mon Sep 17 00:00:00 2001 From: Jiaqi Gao Date: Fri, 10 May 2024 03:41:11 -0400 Subject: [PATCH] td-shim: subtract large payload size for metadata offset The metadata offset at the `end - 0x20`of image is the offset of the metadata from the beginning of the file, so subtract the large payload size when calculating metadata offset. Signed-off-by: Jiaqi Gao --- td-shim/src/bin/td-shim/shim_info.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/td-shim/src/bin/td-shim/shim_info.rs b/td-shim/src/bin/td-shim/shim_info.rs index 30e10686..b3e1c55a 100644 --- a/td-shim/src/bin/td-shim/shim_info.rs +++ b/td-shim/src/bin/td-shim/shim_info.rs @@ -7,7 +7,9 @@ use core::mem::size_of; use core::str::FromStr; use log::error; use scroll::{Pread, Pwrite}; -use td_layout::build_time::{TD_SHIM_FIRMWARE_BASE, TD_SHIM_FIRMWARE_SIZE}; +use td_layout::build_time::{ + TD_SHIM_FIRMWARE_BASE, TD_SHIM_FIRMWARE_SIZE, TD_SHIM_LARGE_PAYLOAD_SIZE, +}; use td_layout::memslice; use td_shim::speculation_barrier; use td_shim::{ @@ -35,7 +37,8 @@ impl BootTimeStatic { // Validate the metadata and get the basic infomation from // it if any pub fn new() -> Option { - let metadata_offset = unsafe { *((u32::MAX - TDX_METADATA_OFFSET + 1) as *const u32) }; + let metadata_offset = unsafe { *((u32::MAX - TDX_METADATA_OFFSET + 1) as *const u32) } + - TD_SHIM_LARGE_PAYLOAD_SIZE; if metadata_offset >= TD_SHIM_FIRMWARE_SIZE || metadata_offset < size_of::() as u32 || metadata_offset > TD_SHIM_FIRMWARE_SIZE - size_of::() as u32