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

TPM2/TPM1 support (testing and bug fixes needed through qemu-(fb)whiptail-tpm[1,2](-hotp) testing boards! #1292

Merged
merged 69 commits into from
Mar 13, 2023

Conversation

tlaurion
Copy link
Collaborator

@tlaurion tlaurion commented Jan 23, 2023

Integrates and adapts @hardenedvault's vaultboot's TPM2 codebase (hardenedvault/vaultboot@b2800fb)


TODOs:

  • libcurl cannot be built as a tpm2-tools dependency as of now not sure why. curl currently needs to be added in board config to be built not needed.
  • tpm-reset (master and here) needs some review, no handle of no tpm use case. Caller is responsible to not call it otherwise does nothing caller scripts does not call (config-gui, gui-init, oem-factory-reset all clean)
  • init tries to bind fd and fails currently
    • Dynamic, depends of bash (required for all boards but can be deactivated (legacy-flash boards)
  • Note: Check if whiptail is different of fbwhiptail in clearing screen. As of now every clear seems to be removed, still whiptail clears previous console output: fbwhiptail doesn't clear screen and is recommended to have more output on console
  • When no OS' /boot can be mounted, do not try to TPM reset (will fail)
  • TPM reset asks for TPM owner password multiple times
  • seal-hotpkey is not working properly ok
  • setting disk unlock key asks for TPM ownership passphrase (sealing in NV requires ownership, but text is misleading user as if reowning TPM) fixed.
    • We should cache input, feed tpm behind the scene and wipe passphrase and state clearly that this is TPM disk unlock kye passphrase. tpm reset still required after each commit
  • primary key from TPM2 is invalid most of the time from kexec-select-boot and verifying global hashes but is setuped correctly at disk unlock key setup fixed under kexec-save-default
  • would be nice to take advantage of bash function tracing to understand where we are for debugging purposes, code takes ash in consideration only : would still be nice, but we have TRACE and DEBUG calls now
  • tpmr says it implements nv calls but actually doesn't. Removing those falsely wrapped functions would help.
  • look into tpm2-tss to see precisely what algorithms are required on libcrypto
  • REVIEW TODOS IN CODE
  • READD CIRCLECI CONFIG

Current state:

  • TPM seal/unseal TOTP properly

  • TPM disk encryption key sealing/unsealing properly

  • coreboot support of TPM v2.0 (shared config for TPM2 support across all 4 previous variations)

  • swtpm set to be launched under TPM v2.0 mode under board config, which manufacture it correctly

  • Documentation file under each board.md softlinks to qemu-coreboot-fbwhiptail-tpm1.md (which has been generalized)

  • All qemu boards activate DEBUG and TRACE calls through board configuration settings to ease onboarding of understanding of both TPM1 and TPM2 internals, on screen and inside /tmp/debug.log, accessible through qemu launching console (Type Enter there to enter recovery shell when you want to access logs, knowing you will invalidate TPM measurements.)

  • size reduction of libcrypto by disabling unused algos

Limitations:

initrd/bin/kexec-seal-key Outdated Show resolved Hide resolved
initrd/bin/kexec-unseal-key Outdated Show resolved Hide resolved
initrd/bin/seal-hotpkey Outdated Show resolved Hide resolved
initrd/bin/tpmr Outdated Show resolved Hide resolved
initrd/bin/unseal-hotp Outdated Show resolved Hide resolved
initrd/bin/unseal-totp Outdated Show resolved Hide resolved
initrd/bin/x230-flash.init Outdated Show resolved Hide resolved
initrd/init Outdated Show resolved Hide resolved
@tlaurion tlaurion changed the title (WiP) Tpm2/TPM1 support (WiP) TPM2/TPM1 support (testing and bug fixes needed through qemu-(fb)whiptail-tpm[1,2](-hotp) testing boards!) Jan 23, 2023
@daringer
Copy link
Collaborator

daringer commented Feb 8, 2023

Did some tryouts with this PR, this was my way through (not looked into any code yet):

  • I use this docker env for building: Dockerfile
  • host has swtpm and libtpms installed
  • building qemu-coreboot-fbwhiptail-tpm2 went fine (using make BOARD=qemu-coreboot-fbwhiptail-tpm2)
  • creating a root image using make BOARD=qemu-coreboot-fbwhiptail-tpm2 INSTALL_IMG=.... run went ok ... I've been using https://cdimage.debian.org/cdimage/daily-builds/daily/arch-latest/amd64/iso-cd/debian-testing-amd64-netinst.iso
  • afterwards I ran make BOARD=qemu-coreboot-fbwhiptail-tpm2 TOKEN_USB=NitrokeyStorage run here especially usb-init did not work nicely, the attached (virtual) usb device did not mount, I had to work around this and run usb-init manually and mount it to /media
  • the inject_gpg target runs a re-build, this is not optimal (compared to run) as this forces me to run it from within the (debian) docker
  • the following steps (using the exported key) went find, including signing and tpm reset, nice
  • finally booting the debian-os does not work for me, the display does not init after control has been given to the debian kernel, cannot tell right now what the issue is here...

for now this leaves me with the following questions:

  • any idea why debian doesn't boot? This looks like this is my personal issue, maybe it would be worth providing a minimal system (cli only debian or something) so that skipping the INSTALL_IMG step could be omitted
  • usb init and saving the pub-key is very error prone, that's a one-timer I understand ... but is this expected? have you seen this?

Generally, this looks pretty good so far, will first have to solve the system boot, then I would also try the -hotp version.

@tlaurion
Copy link
Collaborator Author

tlaurion commented Feb 8, 2023

@daringer does Debian netinst work on real hardware? I ran my tests with debian-11-xfce with success, not in docker, under a qube (qemu not KVM)

As for usb-init, I didn't test this directly, where more recent merge to master works around issue of not having a partition table on raw device. As said I'm chat, this needs a rebase on master to get Purism fix.

On my side, I didn't test the whole Factory reset part, since injecting key to ROM is not working as of now (flashrom doesn't detect ski chip and qemu doesn't expose ROM image in a way that works to internally flash inside of qemu). This is why I suggested in doc to use inject_gpg. Passing INSTALL_IMG pointing to local iso works. Otherwise passing a raw IMG containing iso file would require fix that was merged in master, but not in this PR.

So basically, doing change in codebase and calling make with inject_gpg, then make run should build+inject specified public key, then run qemu pointing to "dirty" rom. Note that this process needs to be redone between each commit, otherwise qemu call will complain that corresponding rim image (for a commit) doesn't exist. Which would be true since make builds for a commit, and if not commited, appends dirty to it. All good to incrementally develop and commit incrementally prior of doing a PR.

I will rebase on master most probably tomorrow.

@tlaurion
Copy link
Collaborator Author

tlaurion commented Feb 8, 2023

<@insurgo:matrix.org> Best and easiest way to test is to

My usage for qemu is as simple as (when everything once installed):

  • make BOARD=qemu-coreboot-fbwhiptail-tpm1 PUBKEY_ASC=~/QubesIncoming/Insurgo/Insurgo_2023_pub.asc USB_TOKEN=NitrokeyStorage ROOT_DISK_IMG=~/QubesIncoming/heads-tests/root.qcow2 QEMU_MEMORY_SIZE=1G inject_gpg
  • make BOARD=qemu-coreboot-fbwhiptail-tpm1 PUBKEY_ASC=~/QubesIncoming/Insurgo/Insurgo_2023_pub.asc USB_TOKEN=NitrokeyStorage ROOT_DISK_IMG=~/QubesIncoming/heads-tests/root.qcow2 QEMU_MEMORY_SIZE=1G run

Adapt above for tpm2 board variants.

I would recommend to make it work for tpm1 variants. And then test tpm2 boards.

@tlaurion
Copy link
Collaborator Author

tlaurion commented Feb 8, 2023

@daringer thanks for the comments. I rebased and fixed one issue at unseal-totp (unsealing was not dying if failing).

  • the inject_gpg target runs a re-build, this is not optimal (compared to run) as this forces me to run it from within the (debian) docker

This will require flashrom+qemu fixes upstream. this is why as of now two builds are required, since one cannot persist settings; this requires adding public key externally in rom (inject_gpg) + run make targets.

  • afterwards I ran make BOARD=qemu-coreboot-fbwhiptail-tpm2 TOKEN_USB=NitrokeyStorage run here especially usb-init did not work nicely, the attached (virtual) usb device did not mount, I had to work around this and run usb-init manually and mount it to /media

This should now work since https://github.com/osresearch/heads/compare/fd00be3c6f8ef0c4e1b6b4a63a2cb7618e409096..c3d082dc856ee6743ef56312255448734229e840#diff-0fd54c445ad40620392abb0e6defb6974df6798254e326594d6300cc86058e24R162-R171 is in from master (rebased)

@tlaurion
Copy link
Collaborator Author

tlaurion commented Feb 8, 2023

Will redo a bunch of tests later, since it seems that the hacks applied by vaultboot might have depended on bash being available, and all prior failing tests for disk unlock key were non functional while init was not launching bash? To be confirmed infirmed later.

In current state, tpm2 boards use bash while tpm1 boards use busybox's ash (ash as bash per busybox config).
By the way, it would be reaaaaly useful to have bash to debug, since it would be possible to trace caller/callee functions.


Note to myself:
git diff 0cbc2eb 1e0847c > diff
should be applied on master prior of 0cbc2eb and 1e0847c rebased so that bash/busybox bash patch could be in seperate pull request to build upon it.

Copy link
Collaborator

@JonathonHall-Purism JonathonHall-Purism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the work on this @tlaurion , have given an initial read-through and will start testing today, then look into the TODO-list items. Still need to go through all the comments, wanted to take an unbiased look at the code first 😁 Deleted a bunch of my review comments though since they were already on your to-do list, so glad we have similar thoughts.

initrd/bin/kexec-seal-key Outdated Show resolved Hide resolved
initrd/bin/kexec-seal-key Outdated Show resolved Hide resolved
@@ -0,0 +1,40 @@
# GNU bash
modules-$(CONFIG_BASH) += bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about using bash always? Probably depends on exactly how much space it consumes, I know 8 MB boards are tight, will take a look.

Having to support both busybox ash and bash in every script seems like a recipe for disaster (script breakage, or worse, silent failure to do something important). We've discussed that ash is limiting in many was as well, in ways that force us to compromise UX or correctness.

Will check it out 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonathonHall-Purism : t420-hotp-maximized board is the most limitating as of today.

I do not think, even with current spooled efforts onto #590 (read from the bottom of that thread) we could really do much there to fit bash there. Will also see what can be done there, would love to see bash and I think ASH_IS_BASH and having bash binary overwrite busybox symlink is a nice trick that was done by @hardenedvault here. But yeah. Having bash would permit us to have debug calls everywhere and export that in board configs (qemu boards) and be really really happy developing. As well as being able to use bashisms which we all miss right now.


diff --git a/boards/t420-hotp-maximized/t420-hotp-maximized.config b/boards/t420-hotp-maximized/t420-hotp-maximized.config
index 7b0d9008..627c6e3a 100644
--- a/boards/t420-hotp-maximized/t420-hotp-maximized.config
+++ b/boards/t420-hotp-maximized/t420-hotp-maximized.config
@@ -28,6 +28,7 @@ CONFIG_UTIL_LINUX=y
 CONFIG_LVM2=y
 CONFIG_MBEDTLS=y
 CONFIG_PCIUTILS=y
+CONFIG_BASH=y

make BOARD=t420-hotp-maximized
[...]

2023-02-09 12:11:49-05:00 MAKE coreboot
tail /home/user/heads/build/x86/log/coreboot.log
-----
    CC         generated/ramstage.o
    CC         cbfs/fallback/ramstage.debug
Created CBFS (capacity = 7601624 bytes)
    CBFS       fallback/romstage
    CBFS       cpu_microcode_blob.bin
    CBFS       fallback/ramstage
    CBFS       config
    CBFS       revision
    CBFS       fallback/dsdt.aml
    CBFS       vbt.bin
    CBFS       cmos.default
    CBFS       cmos_layout.bin
    CBFS       fallback/postcar
    CBFS       fallback/payload
E: Could not add [/home/user/heads/build/x86/t420-hotp-maximized/bzImage, 7678919 bytes (7498 KB)@0x0]; too big?
E: Failed to add '/home/user/heads/build/x86/t420-hotp-maximized/bzImage' into ROM image.
E: Failed while operating on 'COREBOOT' region!
E: The image will be left unmodified.
make[1]: *** [Makefile.inc:1082: t420-hotp-maximized/coreboot.pre] Error 1
make[1]: Leaving directory '/home/user/heads/build/x86/coreboot-4.13'
make: *** [Makefile:412: /home/user/heads/build/x86/coreboot-4.13/t420-hotp-maximized/.build] Error 1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually.... If I merge other PRs this is non issue.

2023-02-09 12:20:48-05:00 DONE coreboot
# Use coreboot.rom, because custom output files might not be processed by cbfstool
"/home/user/heads/build/x86/coreboot-4.13/t420-hotp-maximized/cbfstool" "/home/user/heads/build/x86/coreboot-4.13/t420-hotp-maximized/coreboot.rom" print
FMAP REGION: COREBOOT
Name                           Offset     Type           Size   Comp
cbfs master header             0x0        cbfs header        32 none
fallback/romstage              0x80       stage           87756 none
cpu_microcode_blob.bin         0x157c0    microcode       26624 none
fallback/ramstage              0x1c040    stage          119325 none
config                         0x392c0    raw               925 none
revision                       0x396c0    raw               697 none
fallback/dsdt.aml              0x399c0    raw             14615 none
vbt.bin                        0x3d340    raw              1368 LZMA (3985 decompressed)
cmos.default                   0x3d900    cmos_default      256 none
cmos_layout.bin                0x3da40    cmos_layout      1992 none
fallback/postcar               0x3e240    stage           27288 none
fallback/payload               0x44d40    simple elf    7678919 none
(empty)                        0x797940   null           164952 none
bootblock                      0x7bfdc0   bootblock       65536 none
2023-02-09 12:20:48-05:00 INSTALL   build/x86/coreboot-4.13/t420-hotp-maximized/coreboot.rom => build/x86/t420-hotp-maximized/heads-t420-hotp-maximized-v0.2.0-1364-g0cbc2eb-dirty.rom
762466a46f1507b423c77ebd5537bb369881b0c37a3c51fcd674dd4a5589dd75  build/x86/t420-hotp-maximized/heads-t420-hotp-maximized-v0.2.0-1364-g0cbc2eb-dirty.rom
762466a46f1507b423c77ebd5537bb369881b0c37a3c51fcd674dd4a5589dd75  /home/user/heads/build/x86/t420-hotp-maximized/heads-t420-hotp-maximized-v0.2.0-1364-g0cbc2eb-dirty.rom
user@heads-tests:~/heads$ git diff
diff --git a/boards/t420-hotp-maximized/t420-hotp-maximized.config b/boards/t420-hotp-maximized/t420-hotp-maximized.config
index 7b0d9008..627c6e3a 100644
--- a/boards/t420-hotp-maximized/t420-hotp-maximized.config
+++ b/boards/t420-hotp-maximized/t420-hotp-maximized.config
@@ -28,6 +28,7 @@ CONFIG_UTIL_LINUX=y
 CONFIG_LVM2=y
 CONFIG_MBEDTLS=y
 CONFIG_PCIUTILS=y
+CONFIG_BASH=y
 
 #Remote attestation support
 #TPM based requirements
diff --git a/boards/x230-maximized/x230-maximized.config b/boards/x230-maximized/x230-maximized.config
index c2f4734f..7a584ed4 100644
--- a/boards/x230-maximized/x230-maximized.config
+++ b/boards/x230-maximized/x230-maximized.config
@@ -26,6 +26,7 @@ CONFIG_UTIL_LINUX=y
 CONFIG_LVM2=y
 CONFIG_MBEDTLS=y
 CONFIG_PCIUTILS=y
+CONFIG_BASH=y
 
 #Remote attestation support
 #TPM based requirements
diff --git a/config/coreboot-t420-hotp-maximized.config b/config/coreboot-t420-hotp-maximized.config
index cb455264..455aa803 100644
--- a/config/coreboot-t420-hotp-maximized.config
+++ b/config/coreboot-t420-hotp-maximized.config
@@ -3,7 +3,7 @@ CONFIG_USE_OPTION_TABLE=y
 CONFIG_STATIC_OPTION_TABLE=y
 CONFIG_VENDOR_LENOVO=y
 CONFIG_NO_POST=y
-CONFIG_CBFS_SIZE=0x750000
+CONFIG_CBFS_SIZE=0x7E7FFF
 CONFIG_IFD_BIN_PATH="@BLOB_DIR@/xx20/ifd.bin"
 CONFIG_ME_BIN_PATH="@BLOB_DIR@/xx20/me.bin"
 CONFIG_GBE_BIN_PATH="@BLOB_DIR@/xx20/gbe.bin"

Copy link
Collaborator Author

@tlaurion tlaurion Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With #1298, this is not a problem but for locally built x220/t420 boards (8mb) which don't necessarily include modified ifd + neutered me with freed space relocalized into ifd. mmmmmm

@JonathonHall-Purism : local tests above shows that t420-hotp-maximized is compiling correctly as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's awesome to hear @tlaurion 🤩 Looking forward to a new era with bash!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will depend on #1121 being merged. Diffoscope is taking forever to produce intended report prior of review there.

modules/bash Show resolved Hide resolved
@tlaurion
Copy link
Collaborator Author

tlaurion commented Feb 10, 2023

Note: binary is stripped inside of module even though global Makefile does it as well as part of initrd packing.
We want to see how suitable inclusion of bash in all board configurations would be a possible fit.

Without bash

# Use coreboot.rom, because custom output files might not be processed by cbfstool
"/home/user/heads/build/x86/coreboot-4.13/qemu-coreboot-fbwhiptail-tpm2/cbfstool" "/home/user/heads/build/x86/coreboot-4.13/qemu-coreboot-fbwhiptail-tpm2/coreboot.rom" print
FMAP REGION: COREBOOT
Name                           Offset     Type           Size   Comp
cbfs master header             0x0        cbfs header        32 none
fallback/romstage              0x80       stage           22660 none
fallback/ramstage              0x5980     stage           67916 none
fallback/dsdt.aml              0x16340    raw              6946 none
cmos_layout.bin                0x17ec0    cmos_layout       676 none
fallback/postcar               0x181c0    stage           23256 none
fallback/payload               0x1dd00    simple elf   10083187 none
(empty)                        0x9bb8c0   null          6423768 none
bootblock                      0xfdbdc0   bootblock       16384 none

With bash (Optimized for space -Os)

# Use coreboot.rom, because custom output files might not be processed by cbfstool
"/home/user/heads/build/x86/coreboot-4.13/qemu-coreboot-fbwhiptail-tpm2/cbfstool" "/home/user/heads/build/x86/coreboot-4.13/qemu-coreboot-fbwhiptail-tpm2/coreboot.rom" print
FMAP REGION: COREBOOT
Name                           Offset     Type           Size   Comp
cbfs master header             0x0        cbfs header        32 none
fallback/romstage              0x80       stage           22660 none
fallback/ramstage              0x5980     stage           67916 none
fallback/dsdt.aml              0x16340    raw              6946 none
cmos_layout.bin                0x17ec0    cmos_layout       676 none
fallback/postcar               0x181c0    stage           23256 none
fallback/payload               0x1dd00    simple elf   10461043 none
(empty)                        0xa17cc0   null          6045912 none
bootblock                      0xfdbdc0   bootblock       16384 none

With bash (Optimized for speed -O2)

default

# Use coreboot.rom, because custom output files might not be processed by cbfstool
"/home/user/heads/build/x86/coreboot-4.13/qemu-coreboot-fbwhiptail-tpm2/cbfstool" "/home/user/heads/build/x86/coreboot-4.13/qemu-coreboot-fbwhiptail-tpm2/coreboot.rom" print
FMAP REGION: COREBOOT
Name                           Offset     Type           Size   Comp
cbfs master header             0x0        cbfs header        32 none
fallback/romstage              0x80       stage           22660 none
fallback/ramstage              0x5980     stage           67916 none
fallback/dsdt.aml              0x16340    raw              6946 none
cmos_layout.bin                0x17ec0    cmos_layout       676 none
fallback/postcar               0x181c0    stage           23256 none
fallback/payload               0x1dd00    simple elf   10533747 none
(empty)                        0xa298c0   null          5973208 none
bootblock                      0xfdbdc0   bootblock       16384 none

So:

  • addition of bash with optimization for space (-Os) costs:
    • 6423768-6045912: 377856 bytes
  • addition of bash with optimization for speed (default) costs:
    • 6423768-5973208: 450560 bytes

Question is can we spare 377856? (We just added 0.4mb for xx30 and 0.5mb for xx20.)

@tlaurion
Copy link
Collaborator Author

tlaurion commented Feb 14, 2023

Question is can we spare 377856? (We just added 0.4mb for xx30 and 0.5mb for xx20.)

@JonathonHall-Purism I guess we could if really needed.

Other stalled work from top of my head freed 0.4 mb from -Os passed to all modules in another PR, where kernel built in modules reduction freed another 0.4 or more.

So maybe this is a migration needed, while my current tests for TPM disk unlock key seal/unseal are still not successful with current code base of this PR with/without bash.

Not sure how this code was even successful as is to be honest. Will take another shot in the next days

@JonathonHall-Purism
Copy link
Collaborator

@tlaurion Does this branch build for you right now? Does not build for me on Debian currently, looking into it.

rm -f test/rsa_complex
${LDCMD:-/home/jhall/workspace/pureboot-boards/qemu-tpm2/crossgcc/x86/bin/x86_64-linux-musl-gcc -fdebug-prefix-map=/home/jhall/workspace/pureboot-boards/qemu-tpm2=heads -gno-record-gcc-switches -D__MUSL__ -isystem /home/jhall/workspace/pureboot-boards/qemu-tpm2/install/x86/include -L/home/jhall/workspace/pureboot-boards/qemu-tpm2/install/x86/lib } -pthread -m64 -Wa,--noexecstack -Wall -O3 -L.  -L \
        -o test/rsa_complex test/rsa_complex.o \
         -ldl -pthread 
x86_64-linux-musl-gcc: error: test/rsa_complex: No such file or directory
make[2]: *** [Makefile:9020: test/rsa_complex] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/home/jhall/workspace/pureboot-boards/qemu-tpm2/build/x86/openssl-1_1_1h'
make[1]: *** [Makefile:183: build_programs] Error 2
make[1]: Leaving directory '/home/jhall/workspace/pureboot-boards/qemu-tpm2/build/x86/openssl-1_1_1h'
make: *** [Makefile:412: /home/jhall/workspace/pureboot-boards/qemu-tpm2/build/x86/openssl-1_1_1h/.build] Error 1

build/x86/openssl-1_1_1h/test/rsa_complex.o exists (and it's trying to place the output in the same directory), so I'm not sure what it's complaining about offhand. Going to see if openssl/curl are actually needed first.

These were still writing some debugging output containing flags and
PCRs even when debug was not enabled.  Use DEBUG.

Signed-off-by: Jonathon Hall <[email protected]>
tpm-reset is just a prompt for the password followed by tpmr reset.
oem-factory-reset already bypasses the prompt, just call tpmr reset
directly.

Signed-off-by: Jonathon Hall <[email protected]>
@JonathonHall-Purism
Copy link
Collaborator

We did some refactoring to the x230-legacy-flash and t430-legacy-flash boards that I lack the hardware to test. These are the only two boards that exclude bash (due to lack of space).

x230/t430 board owners, could we get a little help testing x230-legacy-flash / t430-legacy-flash?

x230: x230 (xx30): @tlaurion @osresearch @merge @jan23 @MrChromebox @shamen123 @eganonoa @bwachter @Thrilleratplay @jnscmns @doob85
t430: @Thrilleratplay @alexmaloteaux @lsafd @bwachter(iGPU) @shamen123 @eganonoa(iGPU) @nitrosimon @jans23 @icequbes1 (iGPU) @weyounsix (t430-dgpu)

Disable all optional algorithms except SM3.  (SHA and AES are not
optional.)  tpm2-tss uses SHA, AES, and SM3.  Reduces size of libcrypto
by almost 1 MB, saves about 140 KB in ROM.

Signed-off-by: Jonathon Hall <[email protected]>
@JonathonHall-Purism
Copy link
Collaborator

I disabled all optional algorithms in OpenSSL except SM3. tpm2-tss and tpm2-tools use AES, SHA, and SM3; AES/SHA are not optional in OpenSSL.

Saved about 140 KB of ROM.

Before:

FMAP REGION: COREBOOT
Name                           Offset     Type           Size   Comp
cbfs master header             0x0        cbfs header        32 none
fallback/romstage              0x80       stage           22628 none
fallback/ramstage              0x5980     stage           67923 none
fallback/dsdt.aml              0x16340    raw              6946 none
cmos_layout.bin                0x17ec0    cmos_layout       676 none
fallback/postcar               0x181c0    stage           23256 none
fallback/payload               0x1dd00    simple elf    9514867 none
(empty)                        0x930cc0   null          6992088 none
bootblock                      0xfdbdc0   bootblock       16384 none

$ ls -l ./libcrypto.so.3
-rwxr-xr-x 1 jhall jhall 4626904 Mar 10 16:05 ./libcrypto.so.3

After:

FMAP REGION: COREBOOT
Name                           Offset     Type           Size   Comp
cbfs master header             0x0        cbfs header        32 none
fallback/romstage              0x80       stage           22660 none
fallback/ramstage              0x5980     stage           67930 none
fallback/dsdt.aml              0x16340    raw              6946 none
cmos_layout.bin                0x17ec0    cmos_layout       676 none
fallback/postcar               0x181c0    stage           23256 none
fallback/payload               0x1dd00    simple elf    9374579 none
(empty)                        0x90e8c0   null          7132376 none
bootblock                      0xfdbdc0   bootblock       16384 none

$ ls -l install/x86/lib/libcrypto.so.3
-rwxr-xr-x 1 jhall jhall 3939120 Mar 10 17:02 install/x86/lib/libcrypto.so.3

Multiple traps overwrite each other.  While no tpmr functions have more
than one trap right now, it is fragile, and the quoting is complex due
to double expansion.  Use at_exit to add exit handlers that accumulate
and do not require special quoting.

Signed-off-by: Jonathon Hall <[email protected]>
init must use busybox ash because it is used on legacy-flash boards.
Change shebang, move needed functions to ash_functions.

Signed-off-by: Jonathon Hall <[email protected]>
These need to work on legacy-flash boards.

Signed-off-by: Jonathon Hall <[email protected]>
Fix `[ -a` to POSIX `[ -e`.  Only run cbfs-init, key-init on normal
boards with bash.

Signed-off-by: Jonathon Hall <[email protected]>
It's a no-op on TPM1, but provide it so init doesn't have to
distinguish TPM1/TPM2.

Signed-off-by: Jonathon Hall <[email protected]>
@tlaurion
Copy link
Collaborator Author

tlaurion commented Mar 13, 2023

Issues with flasher boards. co-working on it

They're the same other than a TRACE, combine them.  Use busybox
insmod since the insmod script uses bash, we don't need the TPM PCRs on
legacy-flash-boards.

Remove PCR4 extend, these boards lack TPM configuration.  Update ROM
example name.

Signed-off-by: Jonathon Hall <[email protected]>
TPM password must be 1-32 characters.  Loop if the password is not
valid or the repeated password doesn't match, so the user can try
again.

Move prompt_new_owner_password to functions and use in both gui-init
and tpm-reset.

Fixes linuxboot#1336

Signed-off-by: Jonathon Hall <[email protected]>
@tlaurion tlaurion changed the title (WiP) TPM2/TPM1 support (testing and bug fixes needed through qemu-(fb)whiptail-tpm[1,2](-hotp) testing boards!) TPM2/TPM1 support (testing and bug fixes needed through qemu-(fb)whiptail-tpm[1,2](-hotp) testing boards! Mar 13, 2023
@tlaurion
Copy link
Collaborator Author

Will reflash original rom backup + x230-legacy-flash from CircleCI then x230-hotp-legacy when roms are ready, but if x230-hotp-legacy fails, this should not be a blocker for this PR and should be seperate issue.

@tlaurion tlaurion mentioned this pull request Mar 13, 2023
This is unused, remove it.

Signed-off-by: Jonathon Hall <[email protected]>
No other TPM2 boards exist yet, so add a qemu TPM2 board as a build
test for TPM2.

Signed-off-by: Jonathon Hall <[email protected]>
@tlaurion
Copy link
Collaborator Author

Reminder that legacy boards show 175% percent flash output for full internal upgrade through flash.sh script output.

@tlaurion
Copy link
Collaborator Author

LGTM! Checking if last minutes needs before merging....

@tlaurion tlaurion merged commit d24def4 into linuxboot:master Mar 13, 2023
@tlaurion
Copy link
Collaborator Author

tlaurion commented Nov 1, 2023

Thanks for Nlnet for supporting this part of the work https://nlnet.nl/project/HEADS-TPM2.0/#ack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants