qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] tpm: Some fixes
@ 2020-07-06 22:13 Stefan Berger
  2020-07-06 22:13 ` [PATCH 1/2] tpm: tpm_spapr: Exit on TPM backend failures Stefan Berger
  2020-07-06 22:13 ` [PATCH 2/2] tests: Skip over first 14 bytes when comparing TPM PCRRead result Stefan Berger
  0 siblings, 2 replies; 3+ messages in thread
From: Stefan Berger @ 2020-07-06 22:13 UTC (permalink / raw)
  To: qemu-ppc, marcandre.lureau; +Cc: Stefan Berger, qemu-devel, david

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(-)

-- 
2.24.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] tpm: tpm_spapr: Exit on TPM backend failures
  2020-07-06 22:13 [PATCH 0/2] tpm: Some fixes Stefan Berger
@ 2020-07-06 22:13 ` Stefan Berger
  2020-07-06 22:13 ` [PATCH 2/2] tests: Skip over first 14 bytes when comparing TPM PCRRead result Stefan Berger
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Berger @ 2020-07-06 22:13 UTC (permalink / raw)
  To: qemu-ppc, marcandre.lureau
  Cc: Stefan Berger, Stefan Berger, qemu-devel, david

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

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
 hw/tpm/tpm_spapr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/hw/tpm/tpm_spapr.c b/hw/tpm/tpm_spapr.c
index cb4dfd1e6a..8288ab0a15 100644
--- a/hw/tpm/tpm_spapr.c
+++ b/hw/tpm/tpm_spapr.c
@@ -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)
-- 
2.24.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] tests: Skip over first 14 bytes when comparing TPM PCRRead result
  2020-07-06 22:13 [PATCH 0/2] tpm: Some fixes Stefan Berger
  2020-07-06 22:13 ` [PATCH 1/2] tpm: tpm_spapr: Exit on TPM backend failures Stefan Berger
@ 2020-07-06 22:13 ` Stefan Berger
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Berger @ 2020-07-06 22:13 UTC (permalink / raw)
  To: qemu-ppc, marcandre.lureau
  Cc: Stefan Berger, Stefan Berger, qemu-devel, david

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.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
 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(-)

diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
index a2f2838e15..8f6491a4b7 100644
--- a/tests/qtest/tpm-tests.c
+++ b/tests/qtest/tpm-tests.c
@@ -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);
diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c
index 34efae8f18..df85e23432 100644
--- a/tests/qtest/tpm-util.c
+++ b/tests/qtest/tpm-util.c
@@ -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)
diff --git a/tests/qtest/tpm-util.h b/tests/qtest/tpm-util.h
index 3b97d69017..d6f4c17218 100644
--- a/tests/qtest/tpm-util.h
+++ b/tests/qtest/tpm-util.h
@@ -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);
 
-- 
2.24.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-06 22:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-06 22:13 [PATCH 0/2] tpm: Some fixes Stefan Berger
2020-07-06 22:13 ` [PATCH 1/2] tpm: tpm_spapr: Exit on TPM backend failures Stefan Berger
2020-07-06 22:13 ` [PATCH 2/2] tests: Skip over first 14 bytes when comparing TPM PCRRead result Stefan Berger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).