-
Notifications
You must be signed in to change notification settings - Fork 57
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
Improve the method for getting Region 1~3 base and size #677
Conversation
Hi @arronwy , could you take a look and test it? Thank you! |
// Cert table Offset: 128/144 Size: 8 | ||
|
||
let magic = ((buf[optional_header_addr + 1] as u16) << 8) | buf[optional_header_addr] as u16; | ||
let is_pe32 = is_pe32(magic).ok().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why unwrap()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
let is_pe32 = is_pe32(magic).ok().unwrap(); | ||
let optional_size_of_headers_offset: usize = 0x003c; | ||
let optional_checksum_offset: usize = 0x0040; | ||
let optional_cert_table_offset = if is_pe32 { 0x0080 } else { 0x0090 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we support PE32 (IA32), not PE32+ (X64)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only support PE32+, removed magic check
Signed-off-by: OuyangHang33 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @OuyangHang33 LGTM!
Verified with guest 6.6 kernel and 6.8 kernel:
file /root/tdx_vm/bzImage
/root/tdx_vm/bzImage: Linux kernel x86 boot executable bzImage, version 6.8.0-rc5-g1470fd2f6d23-dirty (root@tdx-ac2) #11 SMP PREEMPT_DYNAMIC Wed Mar 20 06:56:33 UTC 2024, RO-rootFS, swap_dev 0X11, Normal VGA
target/release/td-payload-reference-calculator kernel -q --kernel /root/tdx_vm/bzImage
6ad357abcad6dd3c91cda809428937bb5915b48f71c961c603c78652c35452dc1286430fa59a54e47841a1ce1b9c5028
Event Entry:
RTMR: 2
Event Type: EV_EFI_BOOT_SERVICES_APPLICATION
Digest Algorithm: TPM_ALG_SHA384
Digest: 6ad357abcad6dd3c91cda809428937bb5915b48f71c961c603c78652c35452dc1286430fa59a54e47841a1ce1b9c5028
Event Desc: 1840cd790000000000421d010000000000000000000000002a000000000000000403140072f728144ab61e44b8c39ebdd7f893c7040412006b00650072006e0065006c0000007fff0400
file /root/tdx_vm/bzImage_6.6
/root/tdx_vm/bzImage_6.6: Linux kernel x86 boot executable bzImage, version 6.6.0-rc2-gc177cc781327 (root@tdx-ac2) #1 SMP PREEMPT_DYNAMIC Thu Mar 7 03:35:48 UTC 2024, RO-rootFS, swap_dev 0X11, Normal VGA
target/release/td-payload-reference-calculator kernel -q --kernel /root/tdx_vm/bzImage_6.6
ddb0ae763ef79685a2102128325e6a7f765ef3b602ad22c12e13b97d6f1e44d1dbb4e55fef418003ad37125a14a67a65
Event Entry:
RTMR: 2
Event Type: EV_EFI_BOOT_SERVICES_APPLICATION
Digest Algorithm: TPM_ALG_SHA384
Digest: ddb0ae763ef79685a2102128325e6a7f765ef3b602ad22c12e13b97d6f1e44d1dbb4e55fef418003ad37125a14a67a65
Event Desc: 18e0db790000000080f315010000000000000001000000002a000000000000000403140072f728144ab61e44b8c39ebdd7f893c7040412006b00650072006e0065006c0000007fff0400
Fix: #676
Tested with bzImage6.8 and get:
6ad357abcad6dd3c91cda809428937bb5915b48f71c961c603c78652c35452dc1286430fa59a54e47841a1ce1b9c5028
Match with:
Digest: 6ad357abcad6dd3c91cda809428937bb5915b48f71c961c603c78652c35452dc1286430fa59a54e47841a1ce1b9c5028