|
|
ffd936 |
From 3f67c46626b4fcf523f27890388dbfc5e4a53987 Mon Sep 17 00:00:00 2001
|
|
|
ffd936 |
From: rpm-build <rpm-build>
|
|
|
ffd936 |
Date: Tue, 31 Aug 2021 19:44:22 +0400
|
|
|
ffd936 |
Subject: [PATCH] tpm2: NVMarshal: Handle index orderly RAM without 0-sized
|
|
|
ffd936 |
terminating node
|
|
|
ffd936 |
MIME-Version: 1.0
|
|
|
ffd936 |
Content-Type: text/plain; charset=UTF-8
|
|
|
ffd936 |
Content-Transfer-Encoding: 8bit
|
|
|
ffd936 |
|
|
|
ffd936 |
The NVRAM entries in s_indexOrderlyRam array do not need to contain a
|
|
|
ffd936 |
0-sized terminating node. Instead, the entries may fill up this 512
|
|
|
ffd936 |
byte array so that no NV_RAM_HEADER structure fits anymore. The fact
|
|
|
ffd936 |
that no more NV_RAM_HEADER structure fits is also an indicator for the
|
|
|
ffd936 |
last entry. We need to account for this in the code marshalling and
|
|
|
ffd936 |
unmarshalling the entries so that we stop marshalling the entries
|
|
|
ffd936 |
then and similarly stop unmarshalling.
|
|
|
ffd936 |
|
|
|
ffd936 |
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
|
|
|
ffd936 |
[ backport with misc conflict fixes ]
|
|
|
ffd936 |
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
ffd936 |
---
|
|
|
ffd936 |
src/tpm2/NVMarshal.c | 15 +++++++++++++++
|
|
|
ffd936 |
1 file changed, 15 insertions(+)
|
|
|
ffd936 |
|
|
|
ffd936 |
diff --git a/src/tpm2/NVMarshal.c b/src/tpm2/NVMarshal.c
|
|
|
ffd936 |
index ae7d247..02c60ac 100644
|
|
|
ffd936 |
--- a/src/tpm2/NVMarshal.c
|
|
|
ffd936 |
+++ b/src/tpm2/NVMarshal.c
|
|
|
ffd936 |
@@ -4036,6 +4036,12 @@ INDEX_ORDERLY_RAM_Marshal(void *array, size_t array_size,
|
|
|
ffd936 |
datasize, buffer, size);
|
|
|
ffd936 |
}
|
|
|
ffd936 |
offset += nrh->size;
|
|
|
ffd936 |
+ if (offset + sizeof(NV_RAM_HEADER) > array_size) {
|
|
|
ffd936 |
+ /* nothing will fit anymore and there won't be a 0-sized
|
|
|
ffd936 |
+ * terminating node (@1).
|
|
|
ffd936 |
+ */
|
|
|
ffd936 |
+ break;
|
|
|
ffd936 |
+ }
|
|
|
ffd936 |
}
|
|
|
ffd936 |
|
|
|
ffd936 |
written += BLOCK_SKIP_WRITE_PUSH(TRUE, buffer, size);
|
|
|
ffd936 |
@@ -4073,6 +4079,15 @@ INDEX_ORDERLY_RAM_Unmarshal(void *array, size_t array_size,
|
|
|
ffd936 |
|
|
|
ffd936 |
while (rc == TPM_RC_SUCCESS) {
|
|
|
ffd936 |
nrh = array + offset;
|
|
|
ffd936 |
+ if (offset + sizeof(NV_RAM_HEADER) > sourceside_size) {
|
|
|
ffd936 |
+ /* this case can occur with the previous entry filling up the
|
|
|
ffd936 |
+ * space; in this case there will not be a 0-sized terminating
|
|
|
ffd936 |
+ * node (see @1 above). We clear the rest of our space.
|
|
|
ffd936 |
+ */
|
|
|
ffd936 |
+ if (array_size > offset)
|
|
|
ffd936 |
+ memset(nrh, 0, array_size - offset);
|
|
|
ffd936 |
+ break;
|
|
|
ffd936 |
+ }
|
|
|
ffd936 |
/* write the NVRAM header;
|
|
|
ffd936 |
nrh->size holds the complete size including data;
|
|
|
ffd936 |
nrh->size = 0 indicates the end */
|
|
|
ffd936 |
--
|
|
|
ffd936 |
2.33.0.113.g6c40894d24
|
|
|
ffd936 |
|