From: Stefan Berger <stefanb@linux.ibm.com>
To: qemu-devel@nongnu.org
Cc: armenon@redhat.com, marcandre.lureau@gmail.com,
Stefan Berger <stefanb@linux.ibm.com>
Subject: [PATCH 01/10] tpm_util: Pass TPMVersion to function writing fatal error response
Date: Wed, 23 Sep 2026 21:25:18 -0400 [thread overview]
Message-ID: <20260924012527.858527-2-stefanb@linux.ibm.com> (raw)
In-Reply-To: <20260924012527.858527-1-stefanb@linux.ibm.com>
Have tpm_util_write_fatal_error_response write a TPM version specific
error response with error code TPM_FAIL for a TPM 1.2 and TPM_RC_FAILURE
for a TPM 2. Adjust the callers.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
backends/tpm/tpm_emulator.c | 3 ++-
backends/tpm/tpm_passthrough.c | 2 +-
backends/tpm/tpm_util.c | 12 +++++++++---
include/system/tpm_util.h | 3 ++-
4 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c
index 95d2de2f48..16ae44c8d7 100644
--- a/backends/tpm/tpm_emulator.c
+++ b/backends/tpm/tpm_emulator.c
@@ -270,7 +270,8 @@ static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd *cmd,
tpm_emulator_unix_tx_bufs(tpm_emu, cmd->in, cmd->in_len,
cmd->out, cmd->out_len,
&cmd->selftest_done, errp) < 0) {
- tpm_util_write_fatal_error_response(cmd->out, cmd->out_len);
+ tpm_util_write_fatal_error_response(cmd->out, cmd->out_len,
+ TPM_EMULATOR(tb)->tpm_version);
}
}
diff --git a/backends/tpm/tpm_passthrough.c b/backends/tpm/tpm_passthrough.c
index a9f35ab7d6..8a4f8183c7 100644
--- a/backends/tpm/tpm_passthrough.c
+++ b/backends/tpm/tpm_passthrough.c
@@ -118,7 +118,7 @@ static void tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt,
err_exit:
if (ret < 0) {
- tpm_util_write_fatal_error_response(out, out_len);
+ tpm_util_write_fatal_error_response(out, out_len, tpm_pt->tpm_version);
}
tpm_pt->tpm_executing = false;
diff --git a/backends/tpm/tpm_util.c b/backends/tpm/tpm_util.c
index 264bff22a9..cdb7a48861 100644
--- a/backends/tpm/tpm_util.c
+++ b/backends/tpm/tpm_util.c
@@ -87,12 +87,18 @@ const PropertyInfo qdev_prop_tpm = {
/*
* Write an error message in the given output buffer.
*/
-void tpm_util_write_fatal_error_response(uint8_t *out, uint32_t out_len)
+void tpm_util_write_fatal_error_response(uint8_t *out, uint32_t out_len,
+ TPMVersion tpm_version)
{
if (out_len >= sizeof(struct tpm_resp_hdr)) {
- tpm_cmd_set_tag(out, TPM_TAG_RSP_COMMAND);
+ if (tpm_version == TPM_VERSION_1_2) {
+ tpm_cmd_set_tag(out, TPM_TAG_RSP_COMMAND);
+ tpm_cmd_set_error(out, TPM_FAIL);
+ } else {
+ tpm_cmd_set_tag(out, TPM2_ST_NO_SESSIONS);
+ tpm_cmd_set_error(out, TPM_RC_FAILURE);
+ }
tpm_cmd_set_size(out, sizeof(struct tpm_resp_hdr));
- tpm_cmd_set_error(out, TPM_FAIL);
}
}
diff --git a/include/system/tpm_util.h b/include/system/tpm_util.h
index 1858693225..3ab2fe693d 100644
--- a/include/system/tpm_util.h
+++ b/include/system/tpm_util.h
@@ -25,7 +25,8 @@
#include "system/tpm.h"
#include "qemu/bswap.h"
-void tpm_util_write_fatal_error_response(uint8_t *out, uint32_t out_len);
+void tpm_util_write_fatal_error_response(uint8_t *out, uint32_t out_len,
+ TPMVersion tpm_version);
bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len);
--
2.55.0
next prev parent reply other threads:[~2026-09-24 1:27 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 1:25 [PATCH 00/10] Fix a couple of issues in TPM related code Stefan Berger
2026-09-24 1:25 ` Stefan Berger [this message]
2026-09-24 7:41 ` [PATCH 01/10] tpm_util: Pass TPMVersion to function writing fatal error response marcandre.lureau
2026-09-24 13:23 ` Stefan Berger
2026-09-24 1:25 ` [PATCH 02/10] tpm_emulator: Reject TPM responses whose size is too small Stefan Berger
2026-09-24 7:41 ` marcandre.lureau
2026-09-24 1:25 ` [PATCH 03/10] tpm_emulator: Reject sending commands smaller than the request header Stefan Berger
2026-09-24 7:41 ` marcandre.lureau
2026-09-24 13:24 ` Stefan Berger
2026-09-24 1:25 ` [PATCH 04/10] hw/tpm: tis: Only read from response buffer if rw_offset < len Stefan Berger
2026-09-24 7:41 ` marcandre.lureau
2026-09-24 13:34 ` Stefan Berger
2026-09-24 1:25 ` [PATCH 05/10] hw/tpm: tis: Use uint32_t for len to avoid truncating size of command Stefan Berger
2026-09-24 7:41 ` marcandre.lureau
2026-09-24 1:25 ` [PATCH 06/10] hw/tpm: crb: Do not clear internal buffers when backend is busy Stefan Berger
2026-09-24 7:41 ` marcandre.lureau
2026-09-24 13:50 ` Stefan Berger
2026-09-24 1:25 ` [PATCH 07/10] hw/tpm: crb: Avoid potential integer underflow Stefan Berger
2026-09-24 7:41 ` marcandre.lureau
2026-09-24 1:25 ` [PATCH 08/10] hw/tpm: crb: Free ppi.buf in tpm_crb_unrealize Stefan Berger
2026-09-24 7:41 ` marcandre.lureau
2026-09-24 1:25 ` [PATCH 09/10] hw/tpm: crb: Consider response_buffer->len of received response Stefan Berger
2026-09-24 7:41 ` marcandre.lureau
2026-09-24 1:25 ` [PATCH 10/10] tests: Add tests with commands with bad length Stefan Berger
2026-09-24 7:41 ` marcandre.lureau
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=20260924012527.858527-2-stefanb@linux.ibm.com \
--to=stefanb@linux.ibm.com \
--cc=armenon@redhat.com \
--cc=marcandre.lureau@gmail.com \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.