TrenchBoot / xen

Other
0 stars 0 forks source link

Support AMD SKINIT for Slaunch boot #10

Closed SergiiDmytruk closed 5 months ago

SergiiDmytruk commented 5 months ago

Moved some code into slaunch.c and slaunch.h to avoid putting AMD-specific things into files named intel_txt.* and stop putting too much into tpm.c. Better to review by commits.

Also had to work around limitations of early TPM code for getting SLRT pointer and determining CPU vendor.

SergiiDmytruk commented 5 months ago

Perhaps TIS and event log should be mapped separately from TXT/SKINIT specific ranges, these are common to both versions, especially since SLRT is now in common variable.

Good idea. Also moved dispatching to slaunch.c out of setup.c. https://github.com/TrenchBoot/xen/compare/0bac2f30b7bb5c9f4946a0ea27f5d9fc816e80a0..eb394884c439fca26cc5814cff59adfa10b21074

SergiiDmytruk commented 5 months ago

Now booting works all the way to dom0 starting, where it complains about E820 conflict (log.txt), which may be caused by SLB reservation.

No, it's TPM event log:

...
(XEN) SLAUNCH: reserving TPM event log (0x3284000 - 0x328c000)
...
(XEN)  Dom0 kernel: 64-bit, PAE, lsb, paddr 0x1000000 -> 0x5000000
...

Xen loads Dom0 kernel over a reserved area. I've changed how GRUB allocates the log in https://github.com/TrenchBoot/grub/commit/89e27febfd0fe8bb0a52fd81f79d930949b67b83 and was able to boot.

That line should actually stay SLAUNCH: reserving event log (not "TPM event log") to not break anti-evil-maid-dump-evt-log. Updated it in https://github.com/TrenchBoot/xen/compare/8ae81e157bfd4fa36c6bdb1dbf104d47edd5ce29..0186fd858e26497152cd9a27cb2a26c69217c156..

SergiiDmytruk commented 5 months ago

Sent https://github.com/TrenchBoot/grub/pull/19 for that GRUB change.

SergiiDmytruk commented 5 months ago

Looks like 0x1000000 is where Linux wants to get loaded:

readelf -l

``` Elf file type is EXEC (Executable file) Entry point 0x1000000 There are 5 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000200000 0xffffffff81000000 0x0000000001000000 0x0000000001b5d72c 0x0000000001b5d72c R E 0x200000 LOAD 0x0000000001e00000 0xffffffff82c00000 0x0000000002c00000 0x00000000008c4000 0x00000000008c4000 RW 0x200000 LOAD 0x0000000002800000 0x0000000000000000 0x00000000034c4000 0x0000000000035000 0x0000000000035000 RW 0x200000 LOAD 0x00000000028f9000 0xffffffff834f9000 0x00000000034f9000 0x0000000001b07000 0x0000000001b07000 RWE 0x200000 NOTE 0x0000000001d5d4e0 0xffffffff82b5d4e0 0x0000000002b5d4e0 0x000000000000024c 0x000000000000024c 0x8 Section to Segment mapping: Segment Sections... 00 .text .rodata .pci_fixup .tracedata .printk_index __ksymtab __ksymtab_gpl __ksymtab_strings __init_rodata __param __modver __ex_table .notes 01 .data __bug_table .orc_unwind_ip .orc_unwind .orc_lookup .vvar 02 .data..percpu 03 .init.text .altinstr_aux .init.data .x86_cpu_dev.init .parainstructions .retpoline_sites .return_sites .altinstructions .altinstr_replacement .apicdrivers .exit.text .smp_locks .bss .brk .init.scratch 04 .notes ```

So Xen can't do much here. It's weird that Linux checks for e820 overlaps instead of Xen, but whatever, event log just should be allocated high to avoid this problem.

krystian-hebel commented 5 months ago

Works (somewhat) with https://github.com/TrenchBoot/secure-kernel-loader/pull/17 and https://github.com/TrenchBoot/grub/commit/263639999fc9309ec721fd04cab0a053c98a6939. I've worked around the issue fixed with https://github.com/TrenchBoot/grub/pull/19 by calling slaunch_module /skl.bin before Xen and modules are loaded, which changed memory map sufficiently, I don't see how that fix can break anything so I'll merge it soon. I had to start with maxcpus=1, after which none of the sys-* VMs started due to timeouts. They wanted 2 vCPUs each, which was very inefficient with only one pCPU available. It was possible to start VMs manually after logging in through serial (remove plymouth.ignore-serial-consoles or something like that from Linux command line), one by one, after multiple tries.

Dumping event log works, but PCR 17 values don't match with event log. I'm not sure what's causing it, but I'm merging this PR as is. SMP issue will have to be resolved first, then we can worry about debugging PCR mismatches.

Logs ``` [user@dom0 ~]$ sudo anti-evil-maid-dump-evt-log Found event log at 0x4b8d000, size 0x8000 (32768) bytes 32768+0 records in 32768+0 records out 32768 bytes (33 kB, 32 KiB) copied, 1.29507 s, 25.3 kB/s Found 2 algorithms: ID 0x0004 size = 0x14 ID 0x000b size = 0x20 vendorInfoSize = 20 Entry 1: PCR: 17 Event Type: 0x502 Digests: SHA1: d3a60c696fd3be9d28916696c60a543265b69b87 SHA256: 28d7f9982f249def7215719ebed463166ab14e17f6e1e26865a70232e48b01e8 Event: SKINIT Entry 2: PCR: 17 Event Type: 0x502 Digests: SHA1: b34a6ceee3b376401e8cd1e21c735ccf60f3d216 SHA256: 14fe6be01fc9b0f31bd1bf98929f2e41f010ecb7d9ba42a9c82458745facd649 Event: DLME entry offset Entry 3: PCR: 17 Event Type: 0x502 Digests: SHA1: 21d3fd2a6e73a42e08ff9c554cd6ad2c9aef0b3a SHA256: ea2a4a1771e917547edf941daa49db0d29a6f986bed87c2fb9a71ddf8438d917 Event: DLME Entry 4: PCR: 18 Event Type: 0x502 Digests: SHA1: 4a00aca2a2ebbe387c4d685d04378e7b5928afa9 SHA256: b61608d7a64209f51f2ed04f1d7cf398d7d9a91ddf5ce63cb90d39dd0df0755d Event: Entry 5: PCR: 17 Event Type: 0x502 Digests: SHA1: c211668deab8c9b129a9e53b3b9c89274cee298f SHA256: 6d4e7be482a2383f2d94e11380a3b8b8b07222fc697c2aa830b2147b410d4ec0 Event: Measured MB2 module Entry 6: PCR: 17 Event Type: 0x502 Digests: SHA1: 8a89b4c3384c25287b2eb165b20e4f0ffb248295 SHA256: 52344d67244ac56d3409238f8759f5bd6944cebba1328838adebf19063a8fab8 Event: Measured MB2 module [user@dom0 ~]$ sudo tpm2_pcrread sha1: 0 : 0x3DCAEA25DC86554D94B94AA5BC8F735A49212AF8 1 : 0xB2A83B0EBF2F8374299A5B2BDFC31EA955AD7236 2 : 0x10BEA5C1802C8FF9AE280A100715B403A4F261FB 3 : 0xB2A83B0EBF2F8374299A5B2BDFC31EA955AD7236 4 : 0xB2A83B0EBF2F8374299A5B2BDFC31EA955AD7236 5 : 0xB2A83B0EBF2F8374299A5B2BDFC31EA955AD7236 6 : 0xB2A83B0EBF2F8374299A5B2BDFC31EA955AD7236 7 : 0x08309BBB39E011058F8B55F6AC6F5A8317B0D726 8 : 0x0000000000000000000000000000000000000000 9 : 0x0000000000000000000000000000000000000000 10: 0x9C1FCF0D800A677D0A27AF27FF4B157468DC4813 11: 0x0000000000000000000000000000000000000000 12: 0x0000000000000000000000000000000000000000 13: 0x0000000000000000000000000000000000000000 14: 0x0000000000000000000000000000000000000000 15: 0x0000000000000000000000000000000000000000 16: 0x0000000000000000000000000000000000000000 17: 0x027DE1FDA0835D5AF195358892B7BDD4C709AA7D 18: 0xFC534FF2A0B0863932B8AA715E812C42E4120DC6 19: 0x0000000000000000000000000000000000000000 20: 0x0000000000000000000000000000000000000000 21: 0x0000000000000000000000000000000000000000 22: 0x0000000000000000000000000000000000000000 23: 0x0000000000000000000000000000000000000000 sha256: 0 : 0x0000000000000000000000000000000000000000000000000000000000000000 1 : 0x0000000000000000000000000000000000000000000000000000000000000000 2 : 0x0000000000000000000000000000000000000000000000000000000000000000 3 : 0x0000000000000000000000000000000000000000000000000000000000000000 4 : 0x0000000000000000000000000000000000000000000000000000000000000000 5 : 0x0000000000000000000000000000000000000000000000000000000000000000 6 : 0x0000000000000000000000000000000000000000000000000000000000000000 7 : 0x0000000000000000000000000000000000000000000000000000000000000000 8 : 0x0000000000000000000000000000000000000000000000000000000000000000 9 : 0x0000000000000000000000000000000000000000000000000000000000000000 10: 0xBF0D858E3904704B36740BC2DDCF4820B93A9323C1098338B7C38E338735257B 11: 0x0000000000000000000000000000000000000000000000000000000000000000 12: 0x0000000000000000000000000000000000000000000000000000000000000000 13: 0xE70130ABD99D9920DA2698049EAB08F636A345B4D6E881E32CB1D1B05854BDF0 14: 0x0000000000000000000000000000000000000000000000000000000000000000 15: 0x0000000000000000000000000000000000000000000000000000000000000000 16: 0x0000000000000000000000000000000000000000000000000000000000000000 17: 0x402108CE794726A330FA50A4D956452E2A71A1F31781398363FDB26DFC031D4A 18: 0x92D91C6550557FAB751873FB3C6AB3D0CE83E89BAC58AA588ED09EB7A2DBE0C6 19: 0x0000000000000000000000000000000000000000000000000000000000000000 20: 0x0000000000000000000000000000000000000000000000000000000000000000 21: 0x0000000000000000000000000000000000000000000000000000000000000000 22: 0x0000000000000000000000000000000000000000000000000000000000000000 23: 0x0000000000000000000000000000000000000000000000000000000000000000 ```