* [PATCH v3 00/10] Fix a couple of issues in TPM related code
@ 2026-10-02 14:25 Stefan Berger
2026-10-02 14:25 ` [PATCH v3 01/10] tpm_util: Pass TPMVersion to function writing fatal error response Stefan Berger
` (9 more replies)
0 siblings, 10 replies; 14+ messages in thread
From: Stefan Berger @ 2026-10-02 14:25 UTC (permalink / raw)
To: qemu-devel; +Cc: armenon, marcandre.lureau, Stefan Berger
This series of patches fixes various issues in TPM-related code, such as
memory leaks, potential integer underflows, clearing of buffers while they
are in use, and the proper handling of sizes of commands or responses.
Regards,
Stefan
v3:
- 6/10: Remove call to clearing of buffers
v2:
- Address issues pointed out by Marc-André
Stefan Berger (10):
tpm_util: Pass TPMVersion to function writing fatal error response
tpm_emulator: Reject TPM responses whose size is too small
tpm_emulator: Reject sending commands smaller than the request header
hw/tpm: tis: Only read from response buffer if rw_offset < len
hw/tpm: tis: Use uint32_t for len to avoid truncating size of command
hw/tpm: crb: Do not clear internal buffers when backend is busy
hw/tpm: crb: Avoid potential integer underflow
hw/tpm: crb: Implement tpm_ppi_uninit and use it in tpm_crb_unrealize
hw/tpm: crb: Consider response_buffer->len of received response
tests: Add tests with commands with bad length
backends/tpm/tpm_emulator.c | 12 ++++--
backends/tpm/tpm_passthrough.c | 2 +-
backends/tpm/tpm_util.c | 17 ++++++--
hw/tpm/tpm_crb.c | 21 +++++++---
hw/tpm/tpm_ppi.c | 10 +++++
hw/tpm/tpm_ppi.h | 10 +++++
hw/tpm/tpm_tis_common.c | 8 ++--
include/system/tpm_util.h | 3 +-
tests/qtest/tpm-crb-swtpm-test.c | 10 +++++
tests/qtest/tpm-tests.c | 56 +++++++++++++++++++++++++
tests/qtest/tpm-tests.h | 8 ++++
tests/qtest/tpm-tis-device-swtpm-test.c | 10 +++++
tests/qtest/tpm-tis-swtpm-test.c | 10 +++++
tests/qtest/tpm-util.c | 55 ++++++++++++++++++++++++
tests/qtest/tpm-util.h | 3 ++
15 files changed, 219 insertions(+), 16 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 01/10] tpm_util: Pass TPMVersion to function writing fatal error response
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 ` Stefan Berger
2026-10-04 17:19 ` Arun Menon
2026-10-02 14:25 ` [PATCH v3 02/10] tpm_emulator: Reject TPM responses whose size is too small Stefan Berger
` (8 subsequent siblings)
9 siblings, 1 reply; 14+ messages in thread
From: Stefan Berger @ 2026-10-02 14:25 UTC (permalink / raw)
To: qemu-devel; +Cc: armenon, marcandre.lureau, Stefan Berger
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);
}
}
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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 02/10] tpm_emulator: Reject TPM responses whose size is too small
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-02 14:25 ` Stefan Berger
2026-10-02 14:25 ` [PATCH v3 03/10] tpm_emulator: Reject sending commands smaller than the request header Stefan Berger
` (7 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Stefan Berger @ 2026-10-02 14:25 UTC (permalink / raw)
To: qemu-devel
Cc: armenon, marcandre.lureau, Stefan Berger, Marc-André Lureau
Reject a response from the TPM emulator whose size field indicates that the
response is smaller than the size of the header.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
backends/tpm/tpm_emulator.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c
index 16ae44c8d7..9c95b4d878 100644
--- a/backends/tpm/tpm_emulator.c
+++ b/backends/tpm/tpm_emulator.c
@@ -202,13 +202,13 @@ static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_emu,
* size)
*/
to_read = tpm_cmd_get_size(out);
- if (to_read > out_len) {
+ if (to_read > out_len || to_read < sizeof(struct tpm_resp_hdr)) {
if (qio_channel_shutdown(tpm_emu->data_ioc, QIO_CHANNEL_SHUTDOWN_BOTH,
&local_err) < 0) {
error_report_err(local_err);
}
error_setg(errp, "tpm-emulator: Disconnected after receiving "
- "unacceptable large response (%u > %u)",
+ "unacceptable response size (%u max: %u)",
to_read, out_len);
return -1;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 03/10] tpm_emulator: Reject sending commands smaller than the request header
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-02 14:25 ` [PATCH v3 02/10] tpm_emulator: Reject TPM responses whose size is too small Stefan Berger
@ 2026-10-02 14:25 ` 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
` (6 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Stefan Berger @ 2026-10-02 14:25 UTC (permalink / raw)
To: qemu-devel
Cc: armenon, marcandre.lureau, Stefan Berger, Marc-André Lureau
Reject any TPM request from being sent to the TPM emulator that is shorter
than the size of the request header.
Fixes: f4ede81eed29 ("tpm: Added support for TPM emulator")
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
backends/tpm/tpm_emulator.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c
index 9c95b4d878..0c9e32f36a 100644
--- a/backends/tpm/tpm_emulator.c
+++ b/backends/tpm/tpm_emulator.c
@@ -181,6 +181,11 @@ static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_emu,
uint32_t to_read;
ssize_t ret;
+ if (in_len < sizeof(struct tpm_req_hdr)) {
+ error_setg(errp, "tpm-emulator: invalid request size %u", in_len);
+ return -1;
+ }
+
if (selftest_done) {
*selftest_done = false;
is_selftest = tpm_util_is_selftest(in, in_len);
--
2.55.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 04/10] hw/tpm: tis: Only read from response buffer if rw_offset < len
2026-10-02 14:25 [PATCH v3 00/10] Fix a couple of issues in TPM related code Stefan Berger
` (2 preceding siblings ...)
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 ` 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
` (5 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Stefan Berger @ 2026-10-02 14:25 UTC (permalink / raw)
To: qemu-devel
Cc: armenon, marcandre.lureau, Stefan Berger, Marc-André Lureau
Only read a byte from the response buffer, if the rw_offset < len.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
hw/tpm/tpm_tis_common.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/hw/tpm/tpm_tis_common.c b/hw/tpm/tpm_tis_common.c
index a134d5c205..4ba228116b 100644
--- a/hw/tpm/tpm_tis_common.c
+++ b/hw/tpm/tpm_tis_common.c
@@ -273,13 +273,15 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_t locty)
len = MIN(tpm_cmd_get_size(&s->buffer),
s->be_buffer_size);
- ret = s->buffer[s->rw_offset++];
+ if (s->rw_offset < len) {
+ ret = s->buffer[s->rw_offset++];
+ trace_tpm_tis_data_read(ret, s->rw_offset - 1);
+ }
if (s->rw_offset >= len) {
/* got last byte */
tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID);
tpm_tis_raise_irq(s, locty, TPM_TIS_INT_STS_VALID);
}
- trace_tpm_tis_data_read(ret, s->rw_offset - 1);
}
return ret;
--
2.55.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 05/10] hw/tpm: tis: Use uint32_t for len to avoid truncating size of command
2026-10-02 14:25 [PATCH v3 00/10] Fix a couple of issues in TPM related code Stefan Berger
` (3 preceding siblings ...)
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 ` 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
` (4 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Stefan Berger @ 2026-10-02 14:25 UTC (permalink / raw)
To: qemu-devel
Cc: armenon, marcandre.lureau, Stefan Berger, Marc-André Lureau
To avoid truncating the uint32_t return value from tpm_cmd_get_size()
declare len as uint32_t rather than uint16_t.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
hw/tpm/tpm_tis_common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/tpm/tpm_tis_common.c b/hw/tpm/tpm_tis_common.c
index 4ba228116b..8fa1bee771 100644
--- a/hw/tpm/tpm_tis_common.c
+++ b/hw/tpm/tpm_tis_common.c
@@ -481,7 +481,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
uint8_t locty = tpm_tis_locality_from_addr(addr);
uint8_t active_locty, l;
int c, set_new_locty = 1;
- uint16_t len;
+ uint32_t len;
uint32_t mask = (size == 1) ? 0xff : ((size == 2) ? 0xffff : ~0);
trace_tpm_tis_mmio_write(size, addr, val);
--
2.55.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 06/10] hw/tpm: crb: Do not clear internal buffers when backend is busy
2026-10-02 14:25 [PATCH v3 00/10] Fix a couple of issues in TPM related code Stefan Berger
` (4 preceding siblings ...)
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 ` 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
` (3 subsequent siblings)
9 siblings, 1 reply; 14+ messages in thread
From: Stefan Berger @ 2026-10-02 14:25 UTC (permalink / raw)
To: qemu-devel
Cc: armenon, marcandre.lureau, Stefan Berger, Marc-André Lureau
While the backend (thread) is accessing the request and response buffers,
do not clear those buffers upon a command cancellation. Also, per CRB spec
the TPM is expected to either return a normal command response (command
could not be cancelled) or an error response indicating TPM_RC_CANCELED.
So the response buffer must be able to receive a response as normal.
Fixes: 29315d22b259 ("hw/tpm: Add internal buffer state for chunking")
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
hw/tpm/tpm_crb.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/hw/tpm/tpm_crb.c b/hw/tpm/tpm_crb.c
index 54fa2042b5..daf451aa56 100644
--- a/hw/tpm/tpm_crb.c
+++ b/hw/tpm/tpm_crb.c
@@ -219,7 +219,6 @@ static void tpm_crb_mmio_write(void *opaque, hwaddr addr,
if (s->regs[R_CRB_CTRL_START] & CRB_START_INVOKE) {
tpm_backend_cancel_cmd(s->tpmbe);
}
- tpm_crb_clear_internal_buffers(s);
}
break;
case A_CRB_CTRL_START:
--
2.55.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 07/10] hw/tpm: crb: Avoid potential integer underflow
2026-10-02 14:25 [PATCH v3 00/10] Fix a couple of issues in TPM related code Stefan Berger
` (5 preceding siblings ...)
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-02 14:25 ` 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
` (2 subsequent siblings)
9 siblings, 0 replies; 14+ messages in thread
From: Stefan Berger @ 2026-10-02 14:25 UTC (permalink / raw)
To: qemu-devel
Cc: armenon, marcandre.lureau, Stefan Berger, Marc-André Lureau
Avoid a potential integer underflow in tpm_crb_fill_command_response
that could occur if s->response_offset > s->response_buffer->len and
the function's call sites were to change.
tpm_crb_fill_command_response currently has 3 callers that either test
that 's->response_offset < s->response_buffer->len' is true or ensure that
s->response_offset = 0 and s->response_buffer->len >= 0. Therefore, the
integer underflow cannot currently occur. In the worst case the subtraction
would lead to a '0'.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
hw/tpm/tpm_crb.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/hw/tpm/tpm_crb.c b/hw/tpm/tpm_crb.c
index daf451aa56..cd46b2e888 100644
--- a/hw/tpm/tpm_crb.c
+++ b/hw/tpm/tpm_crb.c
@@ -180,10 +180,17 @@ static void tpm_crb_fill_command_response(CRBState *s)
* to the linux guest in chunks by writing it back to MMIO region.
*/
void *mem = memory_region_get_ram_ptr(&s->cmdmem);
- uint32_t remaining = s->response_buffer->len - s->response_offset;
- uint32_t to_copy = MIN(CRB_CTRL_CMD_SIZE, remaining);
+ uint32_t remaining = 0;
+ uint32_t to_copy;
- memcpy(mem, s->response_buffer->data + s->response_offset, to_copy);
+ if (s->response_offset < s->response_buffer->len) {
+ remaining = s->response_buffer->len - s->response_offset;
+ }
+ to_copy = MIN(CRB_CTRL_CMD_SIZE, remaining);
+
+ if (to_copy) {
+ memcpy(mem, s->response_buffer->data + s->response_offset, to_copy);
+ }
if (to_copy < CRB_CTRL_CMD_SIZE) {
memset((guint8 *)mem + to_copy, 0, CRB_CTRL_CMD_SIZE - to_copy);
--
2.55.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 08/10] hw/tpm: crb: Implement tpm_ppi_uninit and use it in tpm_crb_unrealize
2026-10-02 14:25 [PATCH v3 00/10] Fix a couple of issues in TPM related code Stefan Berger
` (6 preceding siblings ...)
2026-10-02 14:25 ` [PATCH v3 07/10] hw/tpm: crb: Avoid potential integer underflow Stefan Berger
@ 2026-10-02 14:25 ` 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
9 siblings, 1 reply; 14+ messages in thread
From: Stefan Berger @ 2026-10-02 14:25 UTC (permalink / raw)
To: qemu-devel; +Cc: armenon, marcandre.lureau, Stefan Berger
Implement tpm_ppi_uninit and use it for proper teardown of the PPI in
tpm_crb_unrealize.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
hw/tpm/tpm_crb.c | 3 +++
hw/tpm/tpm_ppi.c | 10 ++++++++++
hw/tpm/tpm_ppi.h | 10 ++++++++++
3 files changed, 23 insertions(+)
diff --git a/hw/tpm/tpm_crb.c b/hw/tpm/tpm_crb.c
index cd46b2e888..5c50a79936 100644
--- a/hw/tpm/tpm_crb.c
+++ b/hw/tpm/tpm_crb.c
@@ -16,6 +16,7 @@
#include "qemu/osdep.h"
+#include "qemu/memalign.h"
#include "qemu/module.h"
#include "qemu/error-report.h"
#include "qapi/error.h"
@@ -527,6 +528,8 @@ static void tpm_crb_unrealize(DeviceState *dev)
if (s->migration_blocker) {
migrate_del_blocker(&s->migration_blocker);
}
+
+ tpm_ppi_uninit(&s->ppi, get_system_memory(), OBJECT(s));
}
static void tpm_crb_class_init(ObjectClass *klass, const void *data)
diff --git a/hw/tpm/tpm_ppi.c b/hw/tpm/tpm_ppi.c
index f0c34291dc..35baa083f2 100644
--- a/hw/tpm/tpm_ppi.c
+++ b/hw/tpm/tpm_ppi.c
@@ -57,3 +57,13 @@ void tpm_ppi_init(TPMPPI *tpmppi, MemoryRegion *m,
memory_region_add_subregion(m, addr, &tpmppi->ram);
}
+
+void tpm_ppi_uninit(TPMPPI *tpmppi, MemoryRegion *m, Object *obj)
+{
+ memory_region_del_subregion(m, &tpmppi->ram);
+
+ vmstate_unregister_ram(&tpmppi->ram, DEVICE(obj));
+
+ qemu_vfree(tpmppi->buf);
+ tpmppi->buf = NULL;
+}
diff --git a/hw/tpm/tpm_ppi.h b/hw/tpm/tpm_ppi.h
index 88f316ee95..c173889033 100644
--- a/hw/tpm/tpm_ppi.h
+++ b/hw/tpm/tpm_ppi.h
@@ -32,6 +32,16 @@ typedef struct TPMPPI {
void tpm_ppi_init(TPMPPI *tpmppi, MemoryRegion *m,
hwaddr addr, Object *obj);
+/**
+ * tpm_ppi_uninit:
+ * @tpmppi: a TPMPPI
+ * @m: the address-space / MemoryRegion to use
+ * @obj: the owner object
+ *
+ * Function to unregister the TPM PPI region.
+ */
+void tpm_ppi_uninit(TPMPPI *tpmppi, MemoryRegion *m, Object *obj);
+
/**
* tpm_ppi_reset:
* @tpmppi: a TPMPPI
--
2.55.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 09/10] hw/tpm: crb: Consider response_buffer->len of received response
2026-10-02 14:25 [PATCH v3 00/10] Fix a couple of issues in TPM related code Stefan Berger
` (7 preceding siblings ...)
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-02 14:25 ` Stefan Berger
2026-10-02 14:25 ` [PATCH v3 10/10] tests: Add tests with commands with bad length Stefan Berger
9 siblings, 0 replies; 14+ messages in thread
From: Stefan Berger @ 2026-10-02 14:25 UTC (permalink / raw)
To: qemu-devel
Cc: armenon, marcandre.lureau, Stefan Berger, Marc-André Lureau
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")
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
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 5c50a79936..78db220520 100644
--- a/hw/tpm/tpm_crb.c
+++ b/hw/tpm/tpm_crb.c
@@ -323,13 +323,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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 10/10] tests: Add tests with commands with bad length
2026-10-02 14:25 [PATCH v3 00/10] Fix a couple of issues in TPM related code Stefan Berger
` (8 preceding siblings ...)
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 ` Stefan Berger
9 siblings, 0 replies; 14+ messages in thread
From: Stefan Berger @ 2026-10-02 14:25 UTC (permalink / raw)
To: qemu-devel
Cc: armenon, marcandre.lureau, Stefan Berger, Marc-André Lureau
Add two test cases with commands with bad length:
- Send a command that indicates a very large size (0x10000 bytes) to the
TPM. This will only work with the CRB interface since the TIS wants
to receive all the bytes indicated by the command header.
- Send a command that indicates that its size is only 9 bytes, which is
too short to be valid since the command header alone is 10 bytes.
This test only works with the TIS. The CRB silently rejects commands
that are shorter than the command header.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
tests/qtest/tpm-crb-swtpm-test.c | 10 +++++
tests/qtest/tpm-tests.c | 56 +++++++++++++++++++++++++
tests/qtest/tpm-tests.h | 8 ++++
tests/qtest/tpm-tis-device-swtpm-test.c | 10 +++++
tests/qtest/tpm-tis-swtpm-test.c | 10 +++++
tests/qtest/tpm-util.c | 55 ++++++++++++++++++++++++
tests/qtest/tpm-util.h | 3 ++
7 files changed, 152 insertions(+)
diff --git a/tests/qtest/tpm-crb-swtpm-test.c b/tests/qtest/tpm-crb-swtpm-test.c
index 050c7b0c1f..0e83a5325f 100644
--- a/tests/qtest/tpm-crb-swtpm-test.c
+++ b/tests/qtest/tpm-crb-swtpm-test.c
@@ -33,6 +33,14 @@ static void tpm_crb_swtpm_test(const void *data)
"tpm-crb", NULL);
}
+static void tpm_crb_short_write_swtpm_test(const void *data)
+{
+ const TestState *ts = data;
+
+ tpm_test_short_write_swtpm_test(ts->src_tpm_path, tpm_util_crb_transfer,
+ "tpm-crb", NULL);
+}
+
static void tpm_crb_chunk_swtpm_test(const void *data)
{
const TestState *ts = data;
@@ -62,6 +70,8 @@ int main(int argc, char **argv)
g_test_init(&argc, &argv, NULL);
qtest_add_data_func("/tpm/crb-swtpm/test", &ts, tpm_crb_swtpm_test);
+ qtest_add_data_func("/tpm/crb-short-write-swtpm/test", &ts,
+ tpm_crb_short_write_swtpm_test);
qtest_add_data_func("/tpm/crb-chunk-swtpm/test", &ts,
tpm_crb_chunk_swtpm_test);
qtest_add_data_func("/tpm/crb-swtpm-migration/test", &ts,
diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
index 1b4f932b0c..74b22c43aa 100644
--- a/tests/qtest/tpm-tests.c
+++ b/tests/qtest/tpm-tests.c
@@ -79,6 +79,62 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
qapi_free_SocketAddress(addr);
}
+/* Setup the TPM and send a command by calling a passed function */
+static void
+tpm_test_simple_cmd_swtpm_test(const char *src_tpm_path, tx_func *tx,
+ const char *ifmodel,
+ const char *machine_options,
+ void (*test_func)(QTestState *, tx_func))
+{
+ char *args = NULL;
+ QTestState *s;
+ SocketAddress *addr = NULL;
+ gboolean succ;
+ GPid swtpm_pid;
+ GError *error = NULL;
+
+ if (tpm_test_swtpm_skip()) {
+ return;
+ }
+
+ succ = tpm_util_swtpm_start(src_tpm_path, &swtpm_pid, &addr, &error);
+ g_assert_true(succ);
+
+ args = g_strdup_printf(
+ "%s "
+ "-chardev socket,id=chr,path=%s "
+ "-tpmdev emulator,id=tpm0,chardev=chr "
+ "-device %s,tpmdev=tpm0",
+ machine_options ? : "", addr->u.q_unix.path, ifmodel);
+
+ s = qtest_start(args);
+ g_free(args);
+
+ test_func(s, tx);
+
+ qtest_end();
+ tpm_util_swtpm_kill(swtpm_pid);
+
+ g_unlink(addr->u.q_unix.path);
+ qapi_free_SocketAddress(addr);
+}
+
+void tpm_test_short_write_swtpm_test(const char *src_tpm_path, tx_func *tx,
+ const char *ifmodel,
+ const char *machine_options)
+{
+ tpm_test_simple_cmd_swtpm_test(src_tpm_path, tx, ifmodel, machine_options,
+ tpm_util_short_write);
+}
+
+void tpm_test_too_short_cmd_swtpm_test(const char *src_tpm_path, tx_func *tx,
+ const char *ifmodel,
+ const char *machine_options)
+{
+ tpm_test_simple_cmd_swtpm_test(src_tpm_path, tx, ifmodel, machine_options,
+ tpm_util_too_short_cmd);
+}
+
void tpm_test_swtpm_migration_test(const char *src_tpm_path,
const char *dst_tpm_path,
const char *uri, tx_func *tx,
diff --git a/tests/qtest/tpm-tests.h b/tests/qtest/tpm-tests.h
index 07ba60d26e..7684abf8f4 100644
--- a/tests/qtest/tpm-tests.h
+++ b/tests/qtest/tpm-tests.h
@@ -18,6 +18,14 @@
void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
const char *ifmodel, const char *machine_options);
+void tpm_test_short_write_swtpm_test(const char *src_tpm_path, tx_func *tx,
+ const char *ifmodel,
+ const char *machine_options);
+
+void tpm_test_too_short_cmd_swtpm_test(const char *src_tpm_path, tx_func *tx,
+ const char *ifmodel,
+ const char *machine_options);
+
void tpm_test_swtpm_migration_test(const char *src_tpm_path,
const char *dst_tpm_path,
const char *uri, tx_func *tx,
diff --git a/tests/qtest/tpm-tis-device-swtpm-test.c b/tests/qtest/tpm-tis-device-swtpm-test.c
index 517a077005..48a7389306 100644
--- a/tests/qtest/tpm-tis-device-swtpm-test.c
+++ b/tests/qtest/tpm-tis-device-swtpm-test.c
@@ -38,6 +38,14 @@ static void tpm_tis_swtpm_test(const void *data)
"tpm-tis-device", MACHINE_OPTIONS);
}
+static void tpm_tis_too_short_cmd_swtpm_test(const void *data)
+{
+ const TestState *ts = data;
+
+ tpm_test_too_short_cmd_swtpm_test(ts->src_tpm_path, tpm_tis_transfer,
+ "tpm-tis-device", MACHINE_OPTIONS);
+}
+
static void tpm_tis_swtpm_migration_test(const void *data)
{
const TestState *ts = data;
@@ -62,6 +70,8 @@ int main(int argc, char **argv)
g_test_init(&argc, &argv, NULL);
qtest_add_data_func("/tpm/tis-swtpm/test", &ts, tpm_tis_swtpm_test);
+ qtest_add_data_func("/tpm/tis-too-short-cmd-swtpm/test", &ts,
+ tpm_tis_too_short_cmd_swtpm_test);
qtest_add_data_func("/tpm/tis-swtpm-migration/test", &ts,
tpm_tis_swtpm_migration_test);
ret = g_test_run();
diff --git a/tests/qtest/tpm-tis-swtpm-test.c b/tests/qtest/tpm-tis-swtpm-test.c
index 105e42e21d..14b4cbce21 100644
--- a/tests/qtest/tpm-tis-swtpm-test.c
+++ b/tests/qtest/tpm-tis-swtpm-test.c
@@ -36,6 +36,14 @@ static void tpm_tis_swtpm_test(const void *data)
"tpm-tis", NULL);
}
+static void tpm_tis_too_short_cmd_swtpm_test(const void *data)
+{
+ const TestState *ts = data;
+
+ tpm_test_too_short_cmd_swtpm_test(ts->src_tpm_path, tpm_tis_transfer,
+ "tpm-tis", NULL);
+}
+
static void tpm_tis_swtpm_migration_test(const void *data)
{
const TestState *ts = data;
@@ -57,6 +65,8 @@ int main(int argc, char **argv)
g_test_init(&argc, &argv, NULL);
qtest_add_data_func("/tpm/tis-swtpm/test", &ts, tpm_tis_swtpm_test);
+ qtest_add_data_func("/tpm/tis-too-short-cmd-swtpm/test", &ts,
+ tpm_tis_too_short_cmd_swtpm_test);
qtest_add_data_func("/tpm/tis-swtpm-migration/test", &ts,
tpm_tis_swtpm_migration_test);
ret = g_test_run();
diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c
index 151002ea24..d2042ed5df 100644
--- a/tests/qtest/tpm-util.c
+++ b/tests/qtest/tpm-util.c
@@ -194,6 +194,61 @@ void tpm_util_pcrread(QTestState *s, tx_func *tx,
&exp_resp[14], exp_resp_size - 14);
}
+/*
+ * Write a TPM command with too large length indicator
+ * The CRB will send the command to the TPM.
+ * The TIS will never send the command since it wants to receive the number of
+ * bytes indicate in the command.
+ */
+void tpm_util_short_write(QTestState *s, tx_func *tx)
+{
+ unsigned char buffer[1024] = { 0 };
+ static const unsigned char tpm_bad_command[] = {
+ 0x80, 0x01,
+ 0x00, 0x01, 0x00, 0x00, /* length = 0x10000 */
+ 0x00, 0x00, 0x01, 0x7e,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x0b, 0x03, 0x00, 0x04, 0x00
+ };
+
+ tx(s, tpm_bad_command, sizeof(tpm_bad_command), buffer, sizeof(buffer));
+
+ static const unsigned char tpm_error_resp[] = {
+ 0x80, 0x01,
+ 0x00, 0x00, 0x00, 0x0a,
+ 0x00, 0x00, 0x01, 0x42, /* TPM_RC_COMMAND_SIZE */
+ };
+
+ g_assert_cmpmem(buffer, sizeof(tpm_error_resp),
+ tpm_error_resp, sizeof(tpm_error_resp));
+}
+
+/*
+ * Write a TPM command that is shorter than the header.
+ * The CRB will not send this command.
+ * The TIS will send the command to the backend (needs to be at least
+ * 6 bytes).
+ */
+void tpm_util_too_short_cmd(QTestState *s, tx_func *tx)
+{
+ unsigned char buffer[1024] = { 0 };
+ static const unsigned char tpm_bad_command[] = {
+ 0x80, 0x01,
+ 0x00, 0x00, 0x00, 0x09, /* 9 bytes command is too short */
+ 0x00, 0x00, 0x01,
+ };
+
+ tx(s, tpm_bad_command, sizeof(tpm_bad_command), buffer, sizeof(buffer));
+
+ static const unsigned char tpm_error_resp[] = {
+ 0x80, 0x01,
+ 0x00, 0x00, 0x00, 0x0a,
+ 0x00, 0x00, 0x01, 0x01, /* TPM_RC_FAILURE from tpm_emulator.c */
+ };
+
+ g_assert_cmpmem(buffer, sizeof(tpm_error_resp),
+ tpm_error_resp, sizeof(tpm_error_resp));
+}
+
bool tpm_util_swtpm_has_tpm2(void)
{
bool has_tpm2 = false;
diff --git a/tests/qtest/tpm-util.h b/tests/qtest/tpm-util.h
index 681544e7d8..70c2fc09c6 100644
--- a/tests/qtest/tpm-util.h
+++ b/tests/qtest/tpm-util.h
@@ -38,6 +38,9 @@ void tpm_util_pcrextend(QTestState *s, tx_func *tx);
void tpm_util_pcrread(QTestState *s, tx_func *tx,
const unsigned char *exp_resp, size_t exp_resp_size);
+void tpm_util_short_write(QTestState *s, tx_func *tx);
+void tpm_util_too_short_cmd(QTestState *s, tx_func *tx);
+
bool tpm_util_swtpm_has_tpm2(void);
gboolean tpm_util_swtpm_start(const char *path, GPid *pid,
--
2.55.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v3 06/10] hw/tpm: crb: Do not clear internal buffers when backend is busy
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
0 siblings, 0 replies; 14+ messages in thread
From: Arun Menon @ 2026-10-04 16:36 UTC (permalink / raw)
To: Stefan Berger; +Cc: qemu-devel, marcandre.lureau, Marc-André Lureau
On Fri, Oct 02, 2026 at 10:25:12AM -0400, Stefan Berger wrote:
> While the backend (thread) is accessing the request and response buffers,
> do not clear those buffers upon a command cancellation. Also, per CRB spec
> the TPM is expected to either return a normal command response (command
> could not be cancelled) or an error response indicating TPM_RC_CANCELED.
> So the response buffer must be able to receive a response as normal.
>
> Fixes: 29315d22b259 ("hw/tpm: Add internal buffer state for chunking")
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
> hw/tpm/tpm_crb.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/hw/tpm/tpm_crb.c b/hw/tpm/tpm_crb.c
> index 54fa2042b5..daf451aa56 100644
> --- a/hw/tpm/tpm_crb.c
> +++ b/hw/tpm/tpm_crb.c
> @@ -219,7 +219,6 @@ static void tpm_crb_mmio_write(void *opaque, hwaddr addr,
> if (s->regs[R_CRB_CTRL_START] & CRB_START_INVOKE) {
> tpm_backend_cancel_cmd(s->tpmbe);
> }
> - tpm_crb_clear_internal_buffers(s);
> }
> break;
> case A_CRB_CTRL_START:
> --
> 2.55.0
>
Reviewed-by: Arun Menon <armenon@redhat.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 01/10] tpm_util: Pass TPMVersion to function writing fatal error response
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
0 siblings, 0 replies; 14+ messages in thread
From: Arun Menon @ 2026-10-04 17:19 UTC (permalink / raw)
To: Stefan Berger; +Cc: qemu-devel, marcandre.lureau
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>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 08/10] hw/tpm: crb: Implement tpm_ppi_uninit and use it in tpm_crb_unrealize
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
0 siblings, 0 replies; 14+ messages in thread
From: Arun Menon @ 2026-10-04 17:32 UTC (permalink / raw)
To: Stefan Berger; +Cc: qemu-devel, marcandre.lureau
On Fri, Oct 02, 2026 at 10:25:14AM -0400, Stefan Berger wrote:
> Implement tpm_ppi_uninit and use it for proper teardown of the PPI in
> tpm_crb_unrealize.
>
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
> hw/tpm/tpm_crb.c | 3 +++
> hw/tpm/tpm_ppi.c | 10 ++++++++++
> hw/tpm/tpm_ppi.h | 10 ++++++++++
> 3 files changed, 23 insertions(+)
>
> diff --git a/hw/tpm/tpm_crb.c b/hw/tpm/tpm_crb.c
> index cd46b2e888..5c50a79936 100644
> --- a/hw/tpm/tpm_crb.c
> +++ b/hw/tpm/tpm_crb.c
> @@ -16,6 +16,7 @@
>
> #include "qemu/osdep.h"
>
> +#include "qemu/memalign.h"
> #include "qemu/module.h"
> #include "qemu/error-report.h"
> #include "qapi/error.h"
> @@ -527,6 +528,8 @@ static void tpm_crb_unrealize(DeviceState *dev)
> if (s->migration_blocker) {
> migrate_del_blocker(&s->migration_blocker);
> }
> +
> + tpm_ppi_uninit(&s->ppi, get_system_memory(), OBJECT(s));
> }
>
> static void tpm_crb_class_init(ObjectClass *klass, const void *data)
> diff --git a/hw/tpm/tpm_ppi.c b/hw/tpm/tpm_ppi.c
> index f0c34291dc..35baa083f2 100644
> --- a/hw/tpm/tpm_ppi.c
> +++ b/hw/tpm/tpm_ppi.c
> @@ -57,3 +57,13 @@ void tpm_ppi_init(TPMPPI *tpmppi, MemoryRegion *m,
>
> memory_region_add_subregion(m, addr, &tpmppi->ram);
> }
> +
> +void tpm_ppi_uninit(TPMPPI *tpmppi, MemoryRegion *m, Object *obj)
> +{
> + memory_region_del_subregion(m, &tpmppi->ram);
> +
> + vmstate_unregister_ram(&tpmppi->ram, DEVICE(obj));
> +
> + qemu_vfree(tpmppi->buf);
> + tpmppi->buf = NULL;
> +}
> diff --git a/hw/tpm/tpm_ppi.h b/hw/tpm/tpm_ppi.h
> index 88f316ee95..c173889033 100644
> --- a/hw/tpm/tpm_ppi.h
> +++ b/hw/tpm/tpm_ppi.h
> @@ -32,6 +32,16 @@ typedef struct TPMPPI {
> void tpm_ppi_init(TPMPPI *tpmppi, MemoryRegion *m,
> hwaddr addr, Object *obj);
>
> +/**
> + * tpm_ppi_uninit:
> + * @tpmppi: a TPMPPI
> + * @m: the address-space / MemoryRegion to use
> + * @obj: the owner object
> + *
> + * Function to unregister the TPM PPI region.
> + */
> +void tpm_ppi_uninit(TPMPPI *tpmppi, MemoryRegion *m, Object *obj);
> +
> /**
> * tpm_ppi_reset:
> * @tpmppi: a TPMPPI
> --
> 2.55.0
>
Reviewed-by: Arun Menon <armenon@redhat.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2026-10-04 17:32 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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.