tpm2: Adjust min. buffer size and add comment about min and max sizes

The minimum buffer size was set to MAX_CONTEXT_SIZE + 128, which is fine
if the assumption that the actual biggest command or response buffer is
created by TPM2_ContextLoad/Save commands holds. If the assumption was
not holding, then the choice of the minimum buffer size would truncate
response sizes. Adjust this size to the sizeof(TPMS_CONTEXT), which is
80 bytes bigger than MAX_CONTEXT_SIZE but still related to
TPM2_ContextLoad/Save commands. Still add a generous additional 128 bytes
to it.

Add a comment about the maximum size and the sizes used by TIS and CRB.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2026-04-29 23:54:59 +00:00 committed by Stefan Berger
parent 8c10b23ce0
commit ca95df149e

View File

@ -459,7 +459,14 @@ static uint32_t TPM2_SetBufferSize(uint32_t wanted_size,
uint32_t *min_size,
uint32_t *max_size)
{
const uint32_t min = MAX_CONTEXT_SIZE + 128;
/*
* The maximum size is equivalent to the size of the buffer supported by
* TPM 2 TIS and SPAPR (= 4kb). The CRB only supports 3968 bytes. No command
* or response of the TPM 2 currently requires that many bytes. The maximum
* buffer size used for requests or responses is related to TPMS_CONTEXT
* (plus a generous 128 bytes) and the TPM_ContextLoad/Save commands.
*/
const uint32_t min = sizeof(TPMS_CONTEXT) + 128;
const uint32_t max = TPM_BUFFER_MAX;
if (min_size)