tpm2-tools/0009-fix-tpm2_send-validate-command_size-before-computing.patch
Štěpán Horáček 9983900131 Backport upstream fixes
Resolves: RHEL-164795

Signed-off-by: Štěpán Horáček <shoracek@redhat.com>
2026-05-30 03:05:41 +02:00

45 lines
1.8 KiB
Diff

From 5abee441971dcc8e98077748058704d71edcf0e1 Mon Sep 17 00:00:00 2001
From: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
Date: Sun, 15 Feb 2026 04:39:57 +0900
Subject: [PATCH 09/20] fix(tpm2_send): validate command_size before computing
data_size
Signed-off-by: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
---
tools/tpm2_send.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/tools/tpm2_send.c b/tools/tpm2_send.c
index 94936a0a..27f6dca1 100644
--- a/tools/tpm2_send.c
+++ b/tools/tpm2_send.c
@@ -47,15 +47,19 @@ static int read_command_from_file(FILE *f, tpm2_command_header **c,
tpm2_command_header *header = tpm2_command_header_from_bytes(buffer);
UINT32 command_size = tpm2_command_header_get_size(header, true);
- UINT32 data_size = tpm2_command_header_get_size(header, false);
-
- if (command_size > TPM2_MAX_SIZE || command_size < data_size) {
- LOG_ERR("Command buffer %"PRIu32" bytes cannot be smaller then the "
- "encapsulated data %"PRIu32" bytes, and can not be bigger than"
- " the maximum buffer size", command_size, data_size);
+ if (command_size < TPM2_COMMAND_HEADER_SIZE) {
+ LOG_ERR("Command buffer size %"PRIu32" is smaller than command header "
+ "size %zu", command_size, TPM2_COMMAND_HEADER_SIZE);
+ return -1;
+ }
+ if (command_size > TPM2_MAX_SIZE) {
+ LOG_ERR("Command buffer size %"PRIu32" exceeds maximum buffer size %u",
+ command_size, TPM2_MAX_SIZE);
return -1;
}
+ UINT32 data_size = tpm2_command_header_get_size(header, false);
+
tpm2_command_header *command = (tpm2_command_header *) malloc(command_size);
if (!command) {
LOG_ERR("oom");
--
2.54.0