|
|
f4d944 |
From 9f740868fc36761de27df3935513bdebf8852d19 Mon Sep 17 00:00:00 2001
|
|
|
f4d944 |
From: Stefan Berger <stefanb@linux.ibm.com>
|
|
|
f4d944 |
Date: Wed, 16 Feb 2022 11:17:47 -0500
|
|
|
f4d944 |
Subject: [PATCH] swtpm: Check header size indicator against expected size (CID
|
|
|
f4d944 |
375869)
|
|
|
f4d944 |
|
|
|
f4d944 |
This fix addresses Coverity issue CID 375869.
|
|
|
f4d944 |
|
|
|
f4d944 |
Check the header size indicated in the header of the state against the
|
|
|
f4d944 |
expected size and return an error code in case the header size indicator
|
|
|
f4d944 |
is different. There was only one header size so far since blobheader was
|
|
|
f4d944 |
introduced, so we don't need to deal with different sizes.
|
|
|
f4d944 |
|
|
|
f4d944 |
Without this fix a specially craft header could have cause out-of-bounds
|
|
|
f4d944 |
accesses on the byte array containing the swtpm's state.
|
|
|
f4d944 |
|
|
|
f4d944 |
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
|
|
|
f4d944 |
---
|
|
|
f4d944 |
src/swtpm/swtpm_nvstore.c | 11 ++++++++++-
|
|
|
f4d944 |
1 file changed, 10 insertions(+), 1 deletion(-)
|
|
|
f4d944 |
|
|
|
f4d944 |
diff --git a/src/swtpm/swtpm_nvstore.c b/src/swtpm/swtpm_nvstore.c
|
|
|
f4d944 |
index 437088370e11..144d8975ec54 100644
|
|
|
f4d944 |
--- a/src/swtpm/swtpm_nvstore.c
|
|
|
f4d944 |
+++ b/src/swtpm/swtpm_nvstore.c
|
|
|
f4d944 |
@@ -1075,6 +1075,7 @@ SWTPM_NVRAM_CheckHeader(unsigned char *data, uint32_t length,
|
|
|
f4d944 |
uint8_t *hdrversion, bool quiet)
|
|
|
f4d944 |
{
|
|
|
f4d944 |
blobheader *bh = (blobheader *)data;
|
|
|
f4d944 |
+ uint16_t hdrsize;
|
|
|
f4d944 |
|
|
|
f4d944 |
if (length < sizeof(bh)) {
|
|
|
f4d944 |
if (!quiet)
|
|
|
f4d944 |
@@ -1100,8 +1101,16 @@ SWTPM_NVRAM_CheckHeader(unsigned char *data, uint32_t length,
|
|
|
f4d944 |
return TPM_BAD_VERSION;
|
|
|
f4d944 |
}
|
|
|
f4d944 |
|
|
|
f4d944 |
+ hdrsize = ntohs(bh->hdrsize);
|
|
|
f4d944 |
+ if (hdrsize != sizeof(blobheader)) {
|
|
|
f4d944 |
+ logprintf(STDERR_FILENO,
|
|
|
f4d944 |
+ "bad header size: %u != %zu\n",
|
|
|
f4d944 |
+ hdrsize, sizeof(blobheader));
|
|
|
f4d944 |
+ return TPM_BAD_DATASIZE;
|
|
|
f4d944 |
+ }
|
|
|
f4d944 |
+
|
|
|
f4d944 |
*hdrversion = bh->version;
|
|
|
f4d944 |
- *dataoffset = ntohs(bh->hdrsize);
|
|
|
f4d944 |
+ *dataoffset = hdrsize;
|
|
|
f4d944 |
*hdrflags = ntohs(bh->flags);
|
|
|
f4d944 |
|
|
|
f4d944 |
return TPM_SUCCESS;
|
|
|
f4d944 |
--
|
|
|
f4d944 |
2.34.1.428.gdcc0cd074f0c
|
|
|
f4d944 |
|