linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roberto Sassu <roberto.sassu@huawei.com>
To: Mimi Zohar <zohar@linux.ibm.com>,
	<jarkko.sakkinen@linux.intel.com>, <david.safford@ge.com>,
	<monty.wiseman@ge.com>, <matthewgarrett@google.com>
Cc: <linux-integrity@vger.kernel.org>,
	<linux-security-module@vger.kernel.org>,
	<keyrings@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<silviu.vlasceanu@huawei.com>
Subject: Re: [PATCH v9 6/6] tpm: pass an array of tpm_extend_digest structures to tpm_pcr_extend()
Date: Tue, 5 Feb 2019 11:02:36 +0100	[thread overview]
Message-ID: <e3d41507-3a3e-2851-c887-ab53b3308558@huawei.com> (raw)
In-Reply-To: <1549048506.6993.73.camel@linux.ibm.com>

On 2/1/2019 8:15 PM, Mimi Zohar wrote:
> Hi Roberto,
> 
> Sorry for the delayed review.  A few comments inline below, minor
> suggestions.
> 
>> diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
>> index cc12f3449a72..e6b2dcb0846a 100644
>> --- a/security/integrity/ima/ima.h
>> +++ b/security/integrity/ima/ima.h
>> @@ -56,6 +56,7 @@ extern int ima_policy_flag;
>>   extern int ima_hash_algo;
>>   extern int ima_appraise;
>>   extern struct tpm_chip *ima_tpm_chip;
>> +extern struct tpm_digest *digests;
>>   
>>   /* IMA event related data */
>>   struct ima_event_data {
>> diff --git a/security/integrity/ima/ima_init.c b/security/integrity/ima/ima_init.c
>> index 6bb42a9c5e47..296a965b11ef 100644
>> --- a/security/integrity/ima/ima_init.c
>> +++ b/security/integrity/ima/ima_init.c
>> @@ -27,6 +27,7 @@
>>   /* name for boot aggregate entry */
>>   static const char boot_aggregate_name[] = "boot_aggregate";
>>   struct tpm_chip *ima_tpm_chip;
>> +struct tpm_digest *digests;
> 
> "digests" is used in the new ima_init_digests() and in
> ima_pcr_extend().  It's nice that the initialization routines are
> grouped together here in ima_init.c, but wouldn't it better to define
> "digests" in ima_queued.c, where it is currently being used?
>   "digests" could then be defined as static.
> 
>>   
>>   /* Add the boot aggregate to the IMA measurement list and extend
>>    * the PCR register.
>> @@ -104,6 +105,24 @@ void __init ima_load_x509(void)
>>   }
>>   #endif
>>   
>> +int __init ima_init_digests(void)
>> +{
>> +	int i;
>> +
>> +	if (!ima_tpm_chip)
>> +		return 0;
>> +
>> +	digests = kcalloc(ima_tpm_chip->nr_allocated_banks, sizeof(*digests),
>> +			  GFP_NOFS);
>> +	if (!digests)
>> +		return -ENOMEM;
>> +
>> +	for (i = 0; i < ima_tpm_chip->nr_allocated_banks; i++)
>> +		digests[i].alg_id = ima_tpm_chip->allocated_banks[i].alg_id;
>> +
>> +	return 0;
>> +}
>> +
>>   int __init ima_init(void)
>>   {
>>   	int rc;
>> @@ -125,6 +144,9 @@ int __init ima_init(void)
>>   
>>   	ima_load_kexec_buffer();
>>   
>> +	rc = ima_init_digests();
> 
> Ok. Getting the tpm chip is at the beginning of this function.
>   Deferring allocating "digests" to here, avoids having to free memory
> on failure.

If I understood the code correctly, ima_init() does not undo the actions
of previous functions. For example, if ima_init_template() fails,
ima_shash_tfm is not freed.

Probably, this can be improved later.

Roberto


> ima_load_kexec_buffer() restores prior measurements, but doesn't
> extend the TPM.  For anyone reading the code, a short comment above
> ima_load_kexec_buffer() would make sense.
> 
> Mimi
>     
>> +	if (rc != 0)
>> +		return rc;
>>   	rc = ima_add_boot_aggregate();	/* boot aggregate must be first entry */
>>   	if (rc != 0)
>>   		return rc;
>> diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
>> index 0e41dc1df1d4..719e88ca58f6 100644
>> --- a/security/integrity/ima/ima_queue.c
>> +++ b/security/integrity/ima/ima_queue.c
>> @@ -140,11 +140,15 @@ unsigned long ima_get_binary_runtime_size(void)
>>   static int ima_pcr_extend(const u8 *hash, int pcr)
>>   {
>>   	int result = 0;
>> +	int i;
>>   
>>   	if (!ima_tpm_chip)
>>   		return result;
>>   
>> -	result = tpm_pcr_extend(ima_tpm_chip, pcr, hash);
>> +	for (i = 0; i < ima_tpm_chip->nr_allocated_banks; i++)
>> +		memcpy(digests[i].digest, hash, TPM_DIGEST_SIZE);
>> +
>> +	result = tpm_pcr_extend(ima_tpm_chip, pcr, digests);
>>   	if (result != 0)
>>   		pr_err("Error Communicating to TPM chip, result: %d\n", result);
>>   	return result;
>>
> 

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

      parent reply	other threads:[~2019-02-05 10:02 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-01 10:06 [PATCH v9 0/6] tpm: retrieve digest size of unknown algorithms from TPM Roberto Sassu
2019-02-01 10:06 ` [PATCH v9 1/6] tpm: dynamically allocate the allocated_banks array Roberto Sassu
2019-02-01 13:34   ` Jarkko Sakkinen
2019-02-01 10:06 ` [PATCH v9 2/6] tpm: rename and export tpm2_digest and tpm2_algorithms Roberto Sassu
2019-02-01 13:36   ` Jarkko Sakkinen
2019-02-01 10:06 ` [PATCH v9 3/6] tpm: retrieve digest size of unknown algorithms with PCR read Roberto Sassu
2019-02-01 10:06 ` [PATCH v9 4/6] tpm: move tpm_chip definition to include/linux/tpm.h Roberto Sassu
2019-02-01 13:38   ` Jarkko Sakkinen
2019-02-04  8:58   ` kbuild test robot
2019-02-01 10:06 ` [PATCH v9 5/6] KEYS: trusted: explicitly use tpm_chip structure from tpm_default_chip() Roberto Sassu
2019-02-01 13:39   ` Jarkko Sakkinen
2019-02-01 10:06 ` [PATCH v9 6/6] tpm: pass an array of tpm_extend_digest structures to tpm_pcr_extend() Roberto Sassu
2019-02-01 13:39   ` Jarkko Sakkinen
2019-02-01 13:41     ` Jarkko Sakkinen
2019-02-01 14:33       ` Mimi Zohar
2019-02-01 17:33         ` Jarkko Sakkinen
2019-02-01 17:42           ` Jarkko Sakkinen
2019-02-01 19:15   ` Mimi Zohar
2019-02-04  9:14     ` Roberto Sassu
2019-02-04 12:07       ` Jarkko Sakkinen
2019-02-04 12:59         ` Mimi Zohar
2019-02-04 13:21         ` Roberto Sassu
2019-02-04 23:26           ` Jarkko Sakkinen
2019-02-04 23:30             ` Jarkko Sakkinen
2019-02-05 10:02     ` Roberto Sassu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e3d41507-3a3e-2851-c887-ab53b3308558@huawei.com \
    --to=roberto.sassu@huawei.com \
    --cc=david.safford@ge.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=matthewgarrett@google.com \
    --cc=monty.wiseman@ge.com \
    --cc=silviu.vlasceanu@huawei.com \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).