Skip to contentSkip to conversation

tpm: Some fixes

PATCH Superseded Stefan Berger 1 participant 3 messages Jul 6, 2020

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover tpm: Some fixes

This series of patches fixes the TPM SPAPR device model so that it reacts in the same way as the other device models do when the backend device did not start up properly. It now calls exit(1).

Also, due to a change in the TPM 2 code, the pcrUpdate counter now returns a different value than before. So it's better to skip the first 14 bytes of of the TPM 2 response when comparing the responses.

Stefan

Stefan Berger (2):
tpm: tpm_spapr: Exit on TPM backend failures
tests: Skip over first 14 bytes when comparing TPM PCRRead result

 hw/tpm/tpm_spapr.c      | 5 ++++-
 tests/qtest/tpm-tests.c | 6 +++---
 tests/qtest/tpm-util.c  | 6 ++++--
 tests/qtest/tpm-util.h  | 3 ++-
 4 files changed, 13 insertions(+), 7 deletions(-)
Signature · 1 line
2.24.1
#1 lore raw

PATCH 1/2 tpm: tpm_spapr: Exit on TPM backend failures

Exit on TPM backend failures in the same way as the TPM CRB and TIS device models do.

---
 hw/tpm/tpm_spapr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/tpm/tpm_spapr.c +4 -1
index cb4dfd1e6a..8288ab0a15 100644
@@ -306,7 +306,10 @@ static void tpm_spapr_reset(SpaprVioDevice *dev)
                             TPM_SPAPR_BUFFER_MAX);
 
     tpm_backend_reset(s->be_driver);
-    tpm_spapr_do_startup_tpm(s, s->be_buffer_size);
+
+    if (tpm_spapr_do_startup_tpm(s, s->be_buffer_size) < 0) {
+        exit(1);
+    }
 }
 
 static enum TPMVersion tpm_spapr_get_version(TPMIf *ti)
Signature · 1 line
2.24.1
#2 lore raw

PATCH 2/2 tests: Skip over first 14 bytes when comparing TPM PCRRead result

In reply to Stefan Berger

Due to a change in the TPM 2 code the pcrUpdate counter in the PCRRead response is now different. The easiest way is to skip over the first 14 bytes and only compare the tail of the response.

---
 tests/qtest/tpm-tests.c | 6 +++---
 tests/qtest/tpm-util.c  | 6 ++++--
 tests/qtest/tpm-util.h  | 3 ++-
 3 files changed, 9 insertions(+), 6 deletions(-)
tests/qtest/tpm-tests.c +3 -3
index a2f2838e15..8f6491a4b7 100644
@@ -65,7 +65,7 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
         "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
         "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
     tpm_util_pcrread(s, tx, tpm_pcrread_resp,
-                     sizeof(tpm_pcrread_resp));
+                     sizeof(tpm_pcrread_resp), 14);
 
     qtest_end();
     tpm_util_swtpm_kill(swtpm_pid);
@@ -113,13 +113,13 @@ void tpm_test_swtpm_migration_test(const char *src_tpm_path,
         "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
         "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
     tpm_util_pcrread(src_qemu, tx, tpm_pcrread_resp,
-                     sizeof(tpm_pcrread_resp));
+                     sizeof(tpm_pcrread_resp), 14);
 
     tpm_util_migrate(src_qemu, uri);
     tpm_util_wait_for_migration_complete(src_qemu);
 
     tpm_util_pcrread(dst_qemu, tx, tpm_pcrread_resp,
-                     sizeof(tpm_pcrread_resp));
+                     sizeof(tpm_pcrread_resp), 14);
 
     qtest_quit(dst_qemu);
     qtest_quit(src_qemu);
tests/qtest/tpm-util.c +4 -2
index 34efae8f18..df85e23432 100644
@@ -130,7 +130,8 @@ void tpm_util_pcrextend(QTestState *s, tx_func *tx)
 }
 
 void tpm_util_pcrread(QTestState *s, tx_func *tx,
-                      const unsigned char *exp_resp, size_t exp_resp_size)
+                      const unsigned char *exp_resp, size_t exp_resp_size,
+                      off_t offset)
 {
     unsigned char buffer[1024];
     unsigned char tpm_pcrread[] =
@@ -139,7 +140,8 @@ void tpm_util_pcrread(QTestState *s, tx_func *tx,
 
     tx(s, tpm_pcrread, sizeof(tpm_pcrread), buffer, sizeof(buffer));
 
-    g_assert_cmpmem(buffer, exp_resp_size, exp_resp, exp_resp_size);
+    g_assert_cmpmem(&buffer[offset], exp_resp_size - offset,
+                    &exp_resp[offset], exp_resp_size - offset);
 }
 
 bool tpm_util_swtpm_has_tpm2(void)
tests/qtest/tpm-util.h +2 -1
index 3b97d69017..d6f4c17218 100644
@@ -34,7 +34,8 @@ void tpm_util_tis_transfer(QTestState *s,
 void tpm_util_startup(QTestState *s, tx_func *tx);
 void tpm_util_pcrextend(QTestState *s, tx_func *tx);
 void tpm_util_pcrread(QTestState *s, tx_func *tx,
-                      const unsigned char *exp_resp, size_t exp_resp_size);
+                      const unsigned char *exp_resp, size_t exp_resp_size,
+                      off_t offset);
 
 bool tpm_util_swtpm_has_tpm2(void);
 
Signature · 1 line
2.24.1