> 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]> > Message-ID: <[email protected]> > > diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c > index 95d2de2f48b8..16ae44c8d722 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 a9f35ab7d606..8a4f8183c7c9 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 264bff22a91a..cdb7a4886104 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 {
I would rather use a switch/case than fallback > + 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 185869322571..3ab2fe693df1 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); > Reviewed-by: Marc-André Lureau <[email protected]> -- Marc-André Lureau <[email protected]>
