tpm2: Check against unreasonably large datasize value from stream

Check the read datasize against an unreasonably large value and
log in case we encounter a bad value. This particular value cannot
be larger than 64k and a few bytes.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
This commit is contained in:
Stefan Berger 2018-03-27 18:07:46 -04:00
parent 03d2b4f718
commit f19bf6c6dc

View File

@ -4108,6 +4108,14 @@ USER_NVRAM_Unmarshal(BYTE **buffer, INT32 *size)
if (rc == TPM_RC_SUCCESS) {
rc = UINT32_Unmarshal(&datasize, buffer, size);
}
if (rc == TPM_RC_SUCCESS) {
/* datasize cannot exceed 64k + a few bytes */
if (datasize > (0x10000 + 0x100)) {
TPMLIB_LogTPM2Error("datasize for NV_INDEX too "
"large: %u\n", datasize);
rc = TPM_RC_SIZE;
}
}
if (rc == TPM_RC_SUCCESS &&
o + offset + datasize > array_size) {
o += offset + datasize;