lkml.org 
[lkml]   [2018]   [Dec]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v6 1/7] tpm: dynamically allocate the allocated_banks array
From
Date
On 12/5/2018 12:18 AM, Jarkko Sakkinen wrote:
> On Tue, Dec 04, 2018 at 09:21:32AM +0100, Roberto Sassu wrote:
>> tpm2_get_pcr_allocation() determines if a PCR bank is allocated by checking
>> the mask in the TPML_PCR_SELECTION structure returned by the TPM for
>> TPM2_Get_Capability(). One PCR bank with algorithm set to SHA1 is always
>> allocated for TPM 1.x.
>
> ...
>
>> + for (j = 0; j < pcr_selection.size_of_select; j++)
>> + if (pcr_selection.pcr_select[j])
>> + break;
>> +
>> + if (j < pcr_selection.size_of_select) {
>> + chip->allocated_banks[nr_alloc_banks] = hash_alg;
>> + nr_alloc_banks++;
>> + }
>> +
>
> Why was this needed? Can CAP_PCRS return completely unallocated banks?

This was discussed for patch v4 1/6:
---

Nayna wrote:

# /usr/local/bin/tssgetcapability -cap 5
2 PCR selections
hash TPM_ALG_SHA1
TPMS_PCR_SELECTION length 3
ff ff ff
hash TPM_ALG_SHA256
TPMS_PCR_SELECTION length 3
00 00 00

The pcr_select fields - "ff ff ff" and "00 00 00" - are bit masks for
the enabled PCRs. The SHA1 bank is enabled for all PCRs (0-23), while
the SHA256 bank is not enabled.
---

> Kind of out-of-context for the rest of the changes.
>
> Should this be a bug fix of its own because it looks like as this is a
> bug fix for existing code, and not a new feature? Just asking because
> I don't yet fully understand this change.

If we store in tpm_chip the possible banks, IMA would calculate more
digests unnecessarily. But this problem does not happen without my patch
set, because tpm_pcr_extend() only accepts a SHA1 digest.


> Anyway, I believe that you can streamline this by:
>
> /* Check that at least some of the PCRs have been allocated. This is
> * required because CAP_PCRS ...
> */
> if (memchr_inv(pcr_selection.pcr_select, 0, pcr_selection.size_of_select))
> nr_allocated_banks++;
>
> [yeah, comment would be awesome about CAP_PCRS. Did not finish up the
> comment because I don't know the answer]
>
> In addition, it would be consistent to call the local variable also
> nr_allocated_banks (not nr_alloc_banks).

Unfortunately, I exceed the limit of characters per line.

Roberto


> /Jarkko
>

--
HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Bo PENG, Jian LI, Yanli SHI

\
 
 \ /
  Last update: 2018-12-06 18:57    [W:0.071 / U:4.240 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site