mirror of
https://github.com/stefanberger/libtpms
synced 2026-08-07 02:46:31 +00:00
tpm2: Use marshalled size of OBJECT to see whether it fits into NVRAM
Use the marshalled size of an OBJECT to check whether it still fits into NVRAM rather than using the size of the OBJECT (sizeof(obj), which is much bigger. Using the marshalled size also handles the case where the OBJECT is still copied into NVRAM using memcpy for the NULL profile case of libtpms v0.9. This should have been converted once NvObjectToBuffer() was started to be called there. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
parent
5098f2cefe
commit
77104fbfbd
@ -4976,12 +4976,10 @@ USER_NVRAM_Unmarshal(BYTE **buffer, INT32 *size)
|
||||
break;
|
||||
case TPM_HT_PERSISTENT:
|
||||
if (rc == TPM_RC_SUCCESS &&
|
||||
o + offset + sizeof(TPM_HANDLE) + sizeof(obj) >
|
||||
array_size) {
|
||||
o += offset + sizeof(TPM_HANDLE) + sizeof(obj);
|
||||
o + offset + sizeof(TPM_HANDLE) > array_size) {
|
||||
o += offset + sizeof(TPM_HANDLE);
|
||||
goto exit_size;
|
||||
}
|
||||
|
||||
if (rc == TPM_RC_SUCCESS) {
|
||||
BYTE objBuffer[MAX_MARSHALLED_OBJECT_SIZE];
|
||||
UINT32 marshalledObjectSize;
|
||||
@ -4994,6 +4992,11 @@ USER_NVRAM_Unmarshal(BYTE **buffer, INT32 *size)
|
||||
pAssert(rc == TPM_RC_SUCCESS);
|
||||
// convert the OBJECT into a buffer to copy into NVRAM
|
||||
marshalledObjectSize = NvObjectToBuffer(&obj, objBuffer, sizeof(objBuffer));
|
||||
|
||||
if (o + offset + marshalledObjectSize > array_size) {
|
||||
o += offset + marshalledObjectSize;
|
||||
goto exit_size;
|
||||
}
|
||||
NvWrite(entryRef + o + offset, marshalledObjectSize, objBuffer);
|
||||
offset += marshalledObjectSize;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user