All of lore.kernel.org
 help / color / mirror / Atom feed
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 09/10] hw/tpm: crb: Consider response_buffer->len of received response
Date: Wed, 23 Sep 2026 21:25:26 -0400	[thread overview]
Message-ID: <20260924012527.858527-10-stefanb@linux.ibm.com> (raw)
In-Reply-To: <20260924012527.858527-1-stefanb@linux.ibm.com>

When the CRB receives a TPM reponse from the backend, then reject responses
that are shorter than the TPM_HEADER_SIZE. When determining the size of the
reponse, also consider the length of the response_buffer as being possibly
shorter than the negotiated backend buffer size or the size indicated in
the response itself.

Fixes: 2a660ad67d15 ("hw/tpm: Implement TPM CRB chunking logic")
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
 hw/tpm/tpm_crb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/tpm/tpm_crb.c b/hw/tpm/tpm_crb.c
index 4bd1919952..6ae2261b43 100644
--- a/hw/tpm/tpm_crb.c
+++ b/hw/tpm/tpm_crb.c
@@ -325,13 +325,15 @@ static void tpm_crb_request_completed(TPMIf *ti, int ret)
     CRBState *s = CRB(ti);
 
     ARRAY_FIELD_DP32(s->regs, CRB_CTRL_START, Start, 0);
-    if (ret != 0) {
+    if (ret != 0 || s->response_buffer->len < TPM_HEADER_SIZE) {
         ARRAY_FIELD_DP32(s->regs, CRB_CTRL_STS,
                          tpmSts, 1); /* fatal error */
         tpm_crb_clear_internal_buffers(s);
     } else {
         uint32_t actual_resp_size = tpm_cmd_get_size(s->response_buffer->data);
         uint32_t total_resp_size = MIN(actual_resp_size, s->be_buffer_size);
+
+        total_resp_size = MIN(total_resp_size, s->response_buffer->len);
         g_byte_array_set_size(s->response_buffer, total_resp_size);
         s->response_offset = 0;
     }
-- 
2.55.0



  parent reply	other threads:[~2026-09-24  1:26 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 ` [PATCH 01/10] tpm_util: Pass TPMVersion to function writing fatal error response Stefan Berger
2026-09-24  7:41   ` 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 ` Stefan Berger [this message]
2026-09-24  7:41   ` [PATCH 09/10] hw/tpm: crb: Consider response_buffer->len of received response 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-10-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.