Open pridhiviraj opened 6 years ago
/ # cat /sys/firmware/opal/msglog | grep -i STB
[ 71.254280957,6] MEM: parsing reserved memory from node /ibm,hostboot/reserved-memory
[ 75.394363524,3] STB: container NOT VERIFIED, resource_id=4 secureboot not yet initialized
[ 76.000269556,5] STB: Found ibm,secureboot-v2
[ 76.001880905,5] STB: secure mode off
[ 76.004009987,6] STB: Found CVC @ 200ffd230000-200ffd23ffff
[ 76.004012317,6] STB: Found CVC-sha512 @ 200ffd230040, version=1
[ 76.004014213,6] STB: Found CVC-verify @ 200ffd230050, version=1
[ 76.004019031,5] STB: trusted mode on
[ 76.005463742,5] STB: Found tpm0,i2c_tpm_nuvoton evLogLen=2174 evLogSize=65536
[ 76.150282035,5] STB: IMA_CATALOG verified
[ 76.151990586,5] STB: IMA_CATALOG hash calculated
[ 76.197565954,5] STB: IMA_CATALOG measured on pcr2 (tpm0, evType 0x5, evLogLen 2257)
[ 76.347314490,5] STB: CAPP verified
[ 76.349226963,5] STB: CAPP hash calculated
[ 76.394079794,5] STB: CAPP measured on pcr2 (tpm0, evType 0x5, evLogLen 2333)
[ 84.112839822,5] STB: BOOTKERNEL verified
[ 84.175060791,5] STB: BOOTKERNEL hash calculated
[ 84.219955974,5] STB: BOOTKERNEL measured on pcr4 (tpm0, evType 0x5, evLogLen 2415)
[ 85.063476810,5] STB: EV_SEPARATOR measured on pcr0 (tpm0, evType 0x4, evLogLen 2491)
[ 85.110205265,5] STB: EV_SEPARATOR measured on pcr1 (tpm0, evType 0x4, evLogLen 2567)
[ 85.156551954,5] STB: EV_SEPARATOR measured on pcr2 (tpm0, evType 0x4, evLogLen 2643)
[ 85.203131811,5] STB: EV_SEPARATOR measured on pcr3 (tpm0, evType 0x4, evLogLen 2719)
[ 85.249990931,5] STB: EV_SEPARATOR measured on pcr4 (tpm0, evType 0x4, evLogLen 2795)
[ 85.296376140,5] STB: EV_SEPARATOR measured on pcr5 (tpm0, evType 0x4, evLogLen 2871)
[ 85.343028021,5] STB: EV_SEPARATOR measured on pcr6 (tpm0, evType 0x4, evLogLen 2947)
[ 85.389250243,5] STB: EV_SEPARATOR measured on pcr7 (tpm0, evType 0x4, evLogLen 3023)
[ 1069.077794447,5] STB: BOOTKERNEL verified
[ 1069.079405326,3] STB: BOOTKERNEL NOT MEASURED. Already exited from boot services
[ 1069.087727317,3] STB: EV_SEPARATOR (pcr0) NOT MEASURED. No TPM registered/enabled
[ 1069.091277930,3] STB: EV_SEPARATOR (pcr1) NOT MEASURED. No TPM registered/enabled
[ 1069.094830682,3] STB: EV_SEPARATOR (pcr2) NOT MEASURED. No TPM registered/enabled
[ 1069.099085602,3] STB: EV_SEPARATOR (pcr3) NOT MEASURED. No TPM registered/enabled
[ 1069.102637912,3] STB: EV_SEPARATOR (pcr4) NOT MEASURED. No TPM registered/enabled
[ 1069.106893031,3] STB: EV_SEPARATOR (pcr5) NOT MEASURED. No TPM registered/enabled
[ 1069.110445897,3] STB: EV_SEPARATOR (pcr6) NOT MEASURED. No TPM registered/enabled
[ 1069.113998405,3] STB: EV_SEPARATOR (pcr7) NOT MEASURED. No TPM registered/enabled
/ #
From the above messages now it is clear that, in first full IPL OPAL verified and measured proeprly, but on next fast-reboot OPAL just verified it but skipped measuring it.
diff --git a/core/fast-reboot.c b/core/fast-reboot.c
index 0fe16cc..86408f6 100644
--- a/core/fast-reboot.c
+++ b/core/fast-reboot.c
@@ -30,6 +30,8 @@
#include <ipmi.h>
#include <direct-controls.h>
#include <nvram.h>
+#include "libstb/trustedboot.h"
+#include "libstb/tpm_chip.h"
/* Flag tested by the OPAL entry code */
static volatile bool fast_boot_release;
@@ -330,6 +332,13 @@ void __noreturn fast_reboot_entry(void)
cpu_set_sreset_enable(true);
cpu_set_ipi_enable(true);
+ /* We are loading the BOOTKERNEL from PNOR, in order to function
+ * trusted_measure, do tpm_init and enable boot services flag
+ */
+ boot_services_exited = false;
+
+ tpm_init();
+
/* Start preloading kernel and ramdisk */
start_preload_kernel();
diff --git a/libstb/drivers/tpm_i2c_nuvoton.c b/libstb/drivers/tpm_i2c_nuvoton.c
index d18add9..ed50e07 100644
--- a/libstb/drivers/tpm_i2c_nuvoton.c
+++ b/libstb/drivers/tpm_i2c_nuvoton.c
@@ -534,7 +534,7 @@ void tpm_i2c_nuvoton_probe(void)
{
struct tpm_dev *tpm_device = NULL;
struct dt_node *node = NULL;
- struct i2c_bus *bus;
+ struct i2c_bus *bus = NULL;
dt_for_each_compatible(dt_root, node, "nuvoton,npct650") {
if (!dt_node_is_enabled(node))
@@ -578,7 +578,7 @@ void tpm_i2c_nuvoton_probe(void)
continue;
}
bus = i2c_find_bus_by_id(tpm_device->bus_id);
- assert(bus->check_quirk == NULL);
+ /* assert(bus->check_quirk == NULL); */
bus->check_quirk = nuvoton_tpm_quirk;
bus->check_quirk_data = tpm_device;
diff --git a/libstb/tpm_chip.c b/libstb/tpm_chip.c
index 2858caf..58e5f75 100644
--- a/libstb/tpm_chip.c
+++ b/libstb/tpm_chip.c
@@ -313,6 +313,7 @@ int tpm_extendl(TPM_Pcr pcr,
void tpm_add_status_property(void) {
struct tpm_chip *tpm;
list_for_each(&tpm_list, tpm, link) {
+ dt_check_del_prop(tpm->node, "status");
dt_add_property_string(tpm->node, "status",
tpm->enabled ? "okay" : "disabled");
}
diff --git a/libstb/trustedboot.c b/libstb/trustedboot.c
index 151e4e1..79e39a2 100644
--- a/libstb/trustedboot.c
+++ b/libstb/trustedboot.c
@@ -31,7 +31,7 @@
static bool trusted_mode = false;
static bool trusted_init = false;
-static bool boot_services_exited = false;
+bool boot_services_exited;
/*
* This maps a PCR for each resource we can measure. The PCR number is
diff --git a/libstb/trustedboot.h b/libstb/trustedboot.h
index 3003c80..bb4fcb6 100644
--- a/libstb/trustedboot.h
+++ b/libstb/trustedboot.h
@@ -19,6 +19,8 @@
#include <platform.h>
+extern bool boot_services_exited;
+
void trustedboot_init(void);
/**
With the above changes trusted_measure is functional in fast-reboot path. But i have commented the assert check for i2c bus quirk. it's giving me an assert in fast-reboot path.
[ 149.169253837,5] STB: Found tpm0,i2c_tpm_nuvoton evLogLen=3023 evLogSize=65536
[ 149.172504406,0] Assert fail: libstb/drivers/tpm_i2c_nuvoton.c:581:bus->check_quirk == ((void *)0)
[ 149.176768185,0] Aborting!
CPU 0818 Backtrace:
S: 0000000033c63b90 R: 000000003001367c .backtrace+0x48
S: 0000000033c63c20 R: 000000003001a314 ._abort+0x4c
S: 0000000033c63ca0 R: 000000003001a390 .assert_fail+0x34
S: 0000000033c63d20 R: 00000000300a5534 .tpm_i2c_nuvoton_probe+0x1f8
S: 0000000033c63df0 R: 00000000300a35c0 .tpm_init+0x3c
S: 0000000033c63e70 R: 0000000030025a30 .fast_reboot_entry+0x2d4
S: 0000000033c63f00 R: 0000000030002a2c fast_reset_entry+0x2c
[ 149.203762670,4] IPMI: Dropped eSEL: BMC code is buggy/missing
If i comment that line, it works fine. @stewart-ibm Why the bus->check_quirk function pointer is getting non-NULL in fast-reboot path.
After discussing with @stewart-ibm in internal slack we decided not to do tpm_init again, instead we are not un-registering the tpm chips. Send the fix to the mailing list https://lists.ozlabs.org/pipermail/skiboot/2018-March/010730.html
/ #
/ # cat /sys/firmware/opal/msglog | grep -i STB
[ 56.155311958,6] MEM: parsing reserved memory from node /ibm,hostboot/reserved-memory
[ 60.267505083,3] STB: container NOT VERIFIED, resource_id=4 secureboot not yet initialized
[ 60.376867311,5] STB: Found ibm,secureboot-v2
[ 60.378607730,5] STB: secure mode off
[ 60.380738237,6] STB: Found CVC @ 200ffd230000-200ffd23ffff
[ 60.380740108,6] STB: Found CVC-sha512 @ 200ffd230040, version=1
[ 60.380741958,6] STB: Found CVC-verify @ 200ffd230050, version=1
[ 60.380745879,5] STB: trusted mode on
[ 60.382188970,5] STB: Found tpm0,i2c_tpm_nuvoton evLogLen=2174 evLogSize=65536
[ 61.009958962,5] STB: IMA_CATALOG verified
[ 61.011798937,5] STB: IMA_CATALOG hash calculated
[ 61.056680325,5] STB: IMA_CATALOG measured on pcr2 (tpm0, evType 0x5, evLogLen 2257)
[ 61.203533454,5] STB: CAPP verified
[ 61.204873792,5] STB: CAPP hash calculated
[ 61.249634075,5] STB: CAPP measured on pcr2 (tpm0, evType 0x5, evLogLen 2333)
[ 68.071123345,5] STB: BOOTKERNEL verified
[ 68.132748898,5] STB: BOOTKERNEL hash calculated
[ 68.177780040,5] STB: BOOTKERNEL measured on pcr4 (tpm0, evType 0x5, evLogLen 2415)
[ 69.020288589,5] STB: EV_SEPARATOR measured on pcr0 (tpm0, evType 0x4, evLogLen 2491)
[ 69.067131504,5] STB: EV_SEPARATOR measured on pcr1 (tpm0, evType 0x4, evLogLen 2567)
[ 69.113500453,5] STB: EV_SEPARATOR measured on pcr2 (tpm0, evType 0x4, evLogLen 2643)
[ 69.160151478,5] STB: EV_SEPARATOR measured on pcr3 (tpm0, evType 0x4, evLogLen 2719)
[ 69.206314215,5] STB: EV_SEPARATOR measured on pcr4 (tpm0, evType 0x4, evLogLen 2795)
[ 69.252779324,5] STB: EV_SEPARATOR measured on pcr5 (tpm0, evType 0x4, evLogLen 2871)
[ 69.299546002,5] STB: EV_SEPARATOR measured on pcr6 (tpm0, evType 0x4, evLogLen 2947)
[ 69.345791575,5] STB: EV_SEPARATOR measured on pcr7 (tpm0, evType 0x4, evLogLen 3023)
[ 157.107870446,5] STB: BOOTKERNEL verified
[ 157.170144276,5] STB: BOOTKERNEL hash calculated
[ 157.220727126,5] STB: BOOTKERNEL measured on pcr4 (tpm0, evType 0x5, evLogLen 3105)
[ 157.271683286,5] STB: EV_SEPARATOR measured on pcr0 (tpm0, evType 0x4, evLogLen 3181)
[ 157.317878789,5] STB: EV_SEPARATOR measured on pcr1 (tpm0, evType 0x4, evLogLen 3257)
[ 157.364339706,5] STB: EV_SEPARATOR measured on pcr2 (tpm0, evType 0x4, evLogLen 3333)
[ 157.411026897,5] STB: EV_SEPARATOR measured on pcr3 (tpm0, evType 0x4, evLogLen 3409)
[ 157.457316137,5] STB: EV_SEPARATOR measured on pcr4 (tpm0, evType 0x4, evLogLen 3485)
[ 157.503873377,5] STB: EV_SEPARATOR measured on pcr5 (tpm0, evType 0x4, evLogLen 3561)
[ 158.038687091,5] STB: EV_SEPARATOR measured on pcr6 (tpm0, evType 0x4, evLogLen 3637)
[ 158.085073868,5] STB: EV_SEPARATOR measured on pcr7 (tpm0, evType 0x4, evLogLen 3713)
With this patch, now it measures the BOOTKERNEL partition in fast-reboot path as well.
After having a working V2 in place, but this really needs testing with fast-reboot torture testcase.
Sent a working V2 https://lists.ozlabs.org/pipermail/skiboot/2018-March/010738.html and survived 100 reboots.
In fast-reboot path STB not measuring BOOTKERNEL partition as trusted boot checks for
boot_services_exited
which is set to True during first full IPL. So only verification is happening at the moment not measurement.