Skip to content

Commit 4199bd8

Browse files
committed
WiP: staging changes (TPM1 regression fixes for LOG/DEBUG on quiet mode)
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent c14a3ad commit 4199bd8

4 files changed

Lines changed: 131 additions & 16 deletions

File tree

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Configuration for building a coreboot ROM that works in
2+
# the qemu emulator in console mode thanks to Whiptail
3+
#
4+
# TPM can be used with a qemu software TPM (TIS, 1.2). A Librem Key or
5+
# Nitrokey Pro can also be used by forwarding the USB device from the host to
6+
# the VM.
7+
export CONFIG_COREBOOT=y
8+
export CONFIG_COREBOOT_VERSION=24.02.01
9+
export CONFIG_LINUX_VERSION=6.1.8
10+
11+
CONFIG_COREBOOT_CONFIG=config/coreboot-qemu-tpm1-prod.config
12+
CONFIG_LINUX_CONFIG=config/linux-qemu.config
13+
14+
#Enable only one RESTRICTED/BASIC boot modes below to test them manually (we cannot inject config under QEMU (no internal flashing)
15+
#export CONFIG_RESTRICTED_BOOT=y
16+
#export CONFIG_BASIC=y
17+
18+
#Enable HAVE_GPG_KEY_BACKUP to test GPG key backup drive (we cannot inject config under QEMU (no internal flashing))
19+
#export CONFIG_HAVE_GPG_KEY_BACKUP=y
20+
21+
#Enable DEBUG output
22+
#export CONFIG_DEBUG_OUTPUT=y
23+
#export CONFIG_ENABLE_FUNCTION_TRACING_OUTPUT=y
24+
#Enable TPM2 pcap output under /tmp
25+
#export CONFIG_TPM2_CAPTURE_PCAP=y
26+
27+
#Enable quiet mode: technical information logged under /tmp/debug.log
28+
export CONFIG_QUIET_MODE=y
29+
30+
#On-demand hardware support (modules.cpio)
31+
CONFIG_LINUX_USB=y
32+
CONFIG_LINUX_E1000=y
33+
#CONFIG_MOBILE_TETHERING=y
34+
#Runtime on-demand additional hardware support (modules.cpio)
35+
export CONFIG_LINUX_USB_COMPANION_CONTROLLER=y
36+
37+
38+
39+
#Modules packed into tools.cpio
40+
ifeq "$(CONFIG_UROOT)" "y"
41+
CONFIG_BUSYBOX=n
42+
else
43+
#Modules packed into tools.cpio
44+
CONFIG_CRYPTSETUP2=y
45+
CONFIG_FLASHPROG=y
46+
CONFIG_FLASHTOOLS=y
47+
CONFIG_GPG2=y
48+
CONFIG_KEXEC=y
49+
CONFIG_UTIL_LINUX=y
50+
CONFIG_LVM2=y
51+
CONFIG_MBEDTLS=y
52+
CONFIG_PCIUTILS=y
53+
#Runtime tools to write to MSR
54+
#CONFIG_MSRTOOLS=y
55+
#Remote attestation support
56+
# TPM2 requirements
57+
#CONFIG_TPM2_TSS=y
58+
#CONFIG_OPENSSL=y
59+
#Remote Attestation common tools
60+
CONFIG_POPT=y
61+
CONFIG_QRENCODE=y
62+
CONFIG_TPMTOTP=y
63+
#HOTP based remote attestation for supported USB Security dongle
64+
#With/Without TPM support
65+
CONFIG_HOTPKEY=y
66+
#Nitrokey Storage admin tool (deprecated)
67+
#CONFIG_NKSTORECLI=n
68+
#GUI Support
69+
#Console based Whiptail support(Console based, no FB):
70+
#CONFIG_SLANG=y
71+
#CONFIG_NEWT=y
72+
#FBWhiptail based (Graphical):
73+
CONFIG_CAIRO=y
74+
CONFIG_FBWHIPTAIL=y
75+
#Additional tools (tools.cpio):
76+
#SSH server (requires ethernet drivers, eg: CONFIG_LINUX_E1000E)
77+
CONFIG_DROPBEAR=y
78+
endif
79+
80+
#Runtime configuration
81+
#Automatically boot if HOTP is valid
82+
export CONFIG_AUTO_BOOT_TIMEOUT=5
83+
#TPM2 requirements
84+
#export CONFIG_TPM2_TOOLS=y
85+
#export CONFIG_PRIMARY_KEY_TYPE=ecc
86+
#TPM1 requirements
87+
export CONFIG_TPM=y
88+
export CONFIG_BOOTSCRIPT=/bin/gui-init
89+
#text-based original init:
90+
#export CONFIG_BOOTSCRIPT=/bin/generic-init
91+
export CONFIG_BOOT_REQ_HASH=n
92+
export CONFIG_BOOT_REQ_ROLLBACK=n
93+
export CONFIG_BOOT_RECOVERY_SERIAL="/dev/ttyS0"
94+
export CONFIG_BOOT_KERNEL_ADD="console=ttyS0 console=tty systemd.zram=0"
95+
export CONFIG_BOOT_KERNEL_REMOVE="quiet rhgb splash"
96+
export CONFIG_BOARD_NAME="qemu-coreboot-fbwhiptail-tpm1-hotp"
97+
#export CONFIG_FLASH_OPTIONS="flashprog --progress --programmer internal"
98+
export CONFIG_AUTO_BOOT_TIMEOUT=5
99+
100+
BOARD_TARGETS := qemu

initrd/bin/kexec-select-boot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ verify_global_hashes() {
113113
}
114114

115115
verify_rollback_counter() {
116+
TRACE_FUNC
116117
TPM_COUNTER=$(grep counter $TMP_ROLLBACK_FILE | cut -d- -f2)
117118
if [ -z "$TPM_COUNTER" ]; then
118119
die "$TMP_ROLLBACK_FILE: TPM counter not found?"

initrd/bin/tpmr

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,18 @@ tpm1_counter_create() {
306306
# other parameters for TPM1 are passed directly, and TPM2 mimics the
307307
# TPM1 interface.
308308
prompt_tpm_owner_password
309-
if ! tpm counter_create -pwdo "$(cat "/tmp/secret/tpm_owner_password")" "$@" >/dev/null 2>&1; then
309+
TMP_ERR_FILE=$(mktemp)
310+
if ! tpm counter_create -pwdo "$(cat "/tmp/secret/tpm_owner_password")" "$@" 2>"$TMP_ERR_FILE"; then
310311
DEBUG "Failed to create counter from tpm1_counter_create. Wiping /tmp/secret/tpm_owner_password"
311312
shred -n 10 -z -u /tmp/secret/tpm_owner_password
313+
# Log the contents of the temporary error file
314+
while IFS= read -r line; do
315+
DEBUG "tpm1 stderr: $line"
316+
done <"$TMP_ERR_FILE"
317+
rm -f "$TMP_ERR_FILE"
312318
die "Unable to create counter from tpm1_counter_create"
313319
fi
320+
rm -f "$TMP_ERR_FILE"
314321
}
315322

316323
tpm2_counter_create() {
@@ -608,16 +615,16 @@ tpm2_unseal() {
608615
# stderr. We capture the unsealed data to $file, but still log the errors for quiet mode.
609616
# In case of unseal error, caller will also report on TOTP not being able to be unsealed.
610617
TMP_ERR_FILE=$(mktemp)
611-
if ! tpm2 unseal -Q -c "$handle" -p "session:$POLICY_SESSION$UNSEAL_PASS_SUFFIX" \
612-
-S "$ENC_SESSION_FILE" >"$file" 2>"$TMP_ERR_FILE"; then
613-
# Log the contents of the temporary error file
614-
while IFS= read -r line; do
615-
LOG "tpm2 stderr: $line"
616-
done <"$TMP_ERR_FILE"
617-
rm -f "$TMP_ERR_FILE"
618-
die "Unable to unseal secret from TPM NVRAM with tpm2 unseal"
619-
fi
620-
rm -f "$TMP_ERR_FILE"
618+
if ! tpm2 unseal -Q -c "$handle" -p "session:$POLICY_SESSION$UNSEAL_PASS_SUFFIX" \
619+
-S "$ENC_SESSION_FILE" >"$file" 2>"$TMP_ERR_FILE"; then
620+
# Log the contents of the temporary error file
621+
while IFS= read -r line; do
622+
LOG "tpm2 stderr: $line"
623+
done <"$TMP_ERR_FILE"
624+
rm -f "$TMP_ERR_FILE"
625+
die "Unable to unseal secret from TPM NVRAM with tpm2 unseal"
626+
fi
627+
rm -f "$TMP_ERR_FILE"
621628
}
622629

623630
tpm1_unseal() {
@@ -715,7 +722,7 @@ tpm1_reset() {
715722
tpm physicalpresence -s >/dev/null 2>&1 || LOG "Unable to assert physical presence"
716723
tpm physicalenable >/dev/null 2>&1 || LOG "Unable to enable TPM"
717724
tpm physicalsetdeactivated -c >/dev/null 2>&1 || LOG "Unable to deactivate TPM"
718-
tpm forceclear -pwdo "$tpm_owner_password" >/dev/null 2>&1 || LOG "Unable to clear TPM"
725+
tpm forceclear >/dev/null 2>&1 || LOG "Unable to clear TPM"
719726
tpm physicalenable >/dev/null 2>&1 || LOG "Unable to enable TPM"
720727
tpm takeown -pwdo "$tpm_owner_password" >/dev/null 2>&1 || LOG "Unable to take ownership of TPM"
721728

@@ -787,7 +794,7 @@ if [ "$CONFIG_TPM2_TOOLS" != "y" ]; then
787794
tpm1_destroy "$@"
788795
;;
789796
extend)
790-
#check if we extend with a hash or a file
797+
# Check if we extend with a hash or a file
791798
if [ "$4" = "-if" ]; then
792799
DEBUG "TPM: Will extend PCR[$3] hash content of file $5"
793800
hash="$(sha1sum "$5" | cut -d' ' -f1)"
@@ -799,7 +806,14 @@ if [ "$CONFIG_TPM2_TOOLS" != "y" ]; then
799806

800807
TRACE_FUNC
801808
LOG "TPM: Extending PCR[$3] with hash $hash"
802-
DO_WITH_DEBUG exec tpm "$@"
809+
810+
# Redirect the output of DO_WITH_DEBUG to a temporary file so we can LOG it in quiet mode
811+
TMP_DEBUG_FILE=$(mktemp)
812+
DO_WITH_DEBUG exec tpm "$@" >"$TMP_DEBUG_FILE" 2>&1
813+
while IFS= read -r line; do
814+
LOG "$line"
815+
done <"$TMP_DEBUG_FILE"
816+
rm -f "$TMP_DEBUG_FILE"
803817
;;
804818
seal)
805819
shift

initrd/etc/functions

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ check_tpm_counter() {
372372
tpmr counter_create \
373373
-pwdc '' \
374374
-la $LABEL |
375-
tee /tmp/counter ||
375+
tee /tmp/counter > /dev/null 2>&1 ||
376376
die "Unable to create TPM counter"
377377
TPM_COUNTER=$(cut -d: -f1 </tmp/counter)
378378
fi
@@ -391,7 +391,7 @@ read_tpm_counter() {
391391
increment_tpm_counter() {
392392
TRACE_FUNC
393393
tpmr counter_increment -ix "$1" -pwdc '' |
394-
tee /tmp/counter-$1 ||
394+
tee /tmp/counter-$1 > /dev/null 2>&1 ||
395395
die "TPM counter increment failed for rollback prevention. Please reset the TPM"
396396
}
397397

0 commit comments

Comments
 (0)