Re: [PATCH v4 1/6] tpm: dynamically allocate active_banks array
From: Mimi Zohar <zohar@linux.ibm.com>
Date: 2018-11-07 12:07:43
Also in:
linux-integrity, lkml
From: Mimi Zohar <zohar@linux.ibm.com>
Date: 2018-11-07 12:07:43
Also in:
linux-integrity, lkml
On Wed, 2018-11-07 at 11:44 +0530, Nayna Jain wrote:
On 11/06/2018 08:31 PM, Roberto Sassu wrote:
quoted
@@ -878,11 +877,14 @@ static ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip) if (rc) goto out; - count = be32_to_cpup( + chip->nr_active_banks = be32_to_cpup( (__be32 *)&buf.data[TPM_HEADER_SIZE + 5]);As per my understanding, the count in the TPML_PCR_SELECTION represent the number of possible banks and not the number of active banks. TCG Structures Spec for TPM 2.0 - Table 102 mentions this as explanation of #TPM_RC_SIZE.
Instead of storing the result in a local variable, the only change here is saving the result in the chip info (nr_active_banks). Everything else remains the same.
quoted
- if (count > ARRAY_SIZE(chip->active_banks)) { - rc = -ENODEV; + chip->active_banks = kmalloc_array(chip->nr_active_banks, + sizeof(*chip->active_banks), + GFP_KERNEL);
With this change, the exact number of banks can be allocated, as done here. Nice! Mimi
quoted
+ if (!chip->active_banks) { + rc = -ENOMEM; goto out; }