All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arun Menon <armenon@redhat.com>
To: Stefan Berger <stefanb@linux.ibm.com>
Cc: qemu-devel@nongnu.org, marcandre.lureau@gmail.com
Subject: Re: [PATCH v3 01/10] tpm_util: Pass TPMVersion to function writing fatal error response
Date: Sun, 4 Oct 2026 22:49:46 +0530	[thread overview]
Message-ID: <asKKsnshHBhGoWx2@fedora> (raw)
In-Reply-To: <20261002142516.2063735-2-stefanb@linux.ibm.com>

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 <stefanb@linux.ibm.com>
> ---
>  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 <armenon@redhat.com>



  reply	other threads:[~2026-10-04 17:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02 14:25 [PATCH v3 00/10] Fix a couple of issues in TPM related code Stefan Berger
2026-10-02 14:25 ` [PATCH v3 01/10] tpm_util: Pass TPMVersion to function writing fatal error response Stefan Berger
2026-10-04 17:19   ` Arun Menon [this message]
2026-10-02 14:25 ` [PATCH v3 02/10] tpm_emulator: Reject TPM responses whose size is too small Stefan Berger
2026-10-02 14:25 ` [PATCH v3 03/10] tpm_emulator: Reject sending commands smaller than the request header Stefan Berger
2026-10-02 14:25 ` [PATCH v3 04/10] hw/tpm: tis: Only read from response buffer if rw_offset < len Stefan Berger
2026-10-02 14:25 ` [PATCH v3 05/10] hw/tpm: tis: Use uint32_t for len to avoid truncating size of command Stefan Berger
2026-10-02 14:25 ` [PATCH v3 06/10] hw/tpm: crb: Do not clear internal buffers when backend is busy Stefan Berger
2026-10-04 16:36   ` Arun Menon
2026-10-02 14:25 ` [PATCH v3 07/10] hw/tpm: crb: Avoid potential integer underflow Stefan Berger
2026-10-02 14:25 ` [PATCH v3 08/10] hw/tpm: crb: Implement tpm_ppi_uninit and use it in tpm_crb_unrealize Stefan Berger
2026-10-04 17:32   ` Arun Menon
2026-10-02 14:25 ` [PATCH v3 09/10] hw/tpm: crb: Consider response_buffer->len of received response Stefan Berger
2026-10-02 14:25 ` [PATCH v3 10/10] tests: Add tests with commands with bad length Stefan Berger

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=asKKsnshHBhGoWx2@fedora \
    --to=armenon@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=qemu-devel@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 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.