qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@linux.vnet.ibm.com>
To: qemu-ppc@nongnu.org, marcandre.lureau@redhat.com
Cc: Stefan Berger <stefanb@linux.ibm.com>,
	Stefan Berger <stefanb@linux.vnet.ibm.com>,
	qemu-devel@nongnu.org, david@gibson.dropbear.id.au
Subject: [PATCH 2/2] tests: Skip over first 14 bytes when comparing TPM PCRRead result
Date: Mon,  6 Jul 2020 18:13:27 -0400	[thread overview]
Message-ID: <20200706221327.3914491-3-stefanb@linux.vnet.ibm.com> (raw)
In-Reply-To: <20200706221327.3914491-1-stefanb@linux.vnet.ibm.com>

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



      parent reply	other threads:[~2020-07-06 22:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200706221327.3914491-3-stefanb@linux.vnet.ibm.com \
    --to=stefanb@linux.vnet.ibm.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=stefanb@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).