Hi Stefan, On Fri, Oct 02, 2026 at 10:25:07AM -0400, Stefan Berger wrote: > 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 <[email protected]> > --- > backends/tpm/tpm_emulator.c | 3 ++- > backends/tpm/tpm_passthrough.c | 2 +- > backends/tpm/tpm_util.c | 17 ++++++++++++++--- > include/system/tpm_util.h | 3 ++- > 4 files changed, 19 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); nitpick, + tpm_util_write_fatal_error_response(cmd->out, cmd->out_len, + tpm_emu->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..7019f7fd3e 100644 > --- a/backends/tpm/tpm_util.c > +++ b/backends/tpm/tpm_util.c > @@ -87,12 +87,23 @@ 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); > + switch (tpm_version) { > + case TPM_VERSION_1_2: > + tpm_cmd_set_tag(out, TPM_TAG_RSP_COMMAND); > + tpm_cmd_set_error(out, TPM_FAIL); > + break; > + case TPM_VERSION_2_0: > + tpm_cmd_set_tag(out, TPM2_ST_NO_SESSIONS); > + tpm_cmd_set_error(out, TPM_RC_FAILURE); > + break; > + default: > + g_assert_not_reached(); > + } > 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 >
Reviewed-by: Arun Menon <[email protected]>
