Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp4858578ima; Tue, 5 Feb 2019 02:28:01 -0800 (PST) X-Google-Smtp-Source: AHgI3IZlxA7YDeGrb47V6ZdRZ8HCHEwj+UHdPYoGFe14VQqNfzuZgQ8LIcYC6Tzq4yaVzxVDH6Fs X-Received: by 2002:a63:200c:: with SMTP id g12mr3826009pgg.53.1549362480983; Tue, 05 Feb 2019 02:28:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549362480; cv=none; d=google.com; s=arc-20160816; b=qlbKMi0KZ14ohAtKqBmB7JsUlDiRNAKw40UG9Boa8XaALlICQqEbGlvv74WdSIu9ab CKTaWm6RiXtG2vM3lIOlwmpuqJiIgN8jHRWHAnw7Qt1RsjxZbV8fNv/fhVD9TA4l035X QqcZbdy3vbQfxcM3brU5yiuPnHI3xBtF4mGysN0kC2Y6NtBDWMFbYlufB9Oe9z8UQw0v byAthaVJlKck9dFGIDVP1dDFzX3QafIUrPX1KWOx9JRyQW0g5oWTkl4URs93hLUv0M/e 5uejYXx95uRi8Dg7fqB28UOD5o7yl31IGVOCsCA9lihNZDBd7rYAYexyDWDUa3UBB7sS VuqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=ndM+NcPPeiXnlooZXG5NXCrWGWlwzLg3e4zmbRradyM=; b=p8SAXnnKwTctpMMfNLOMr2esKLIUj8Oy8u7IYckCet2bxekTBte3JW4x0/myhL9Tyo BbAawXi59mEpQdzoSwK+a7DO6xuSaaEuusEhR1DMKXeJsAEp84YTWJdaFhBixY9mMAui ssIYn1nrtaf2uMkIyz0iILUHvGiszvO335HQUQemVOx2EgnyvfgIKEBcEyjaGOTsWVBn jc6KAVUEAFFWdhNC57OpxKJXgKROmmXhLlYdXElySV+wv/lGT0et7Lyquu7erpF1N8+u aTYxWxN9LuBADkS3O9zeL9iGW0IX4QtN9wjq1iAtEey3en3CG7KZu5WygvomA7Lxxojs Uznw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 37si2624853pgs.447.2019.02.05.02.27.44; Tue, 05 Feb 2019 02:28:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728855AbfBEKCt (ORCPT + 99 others); Tue, 5 Feb 2019 05:02:49 -0500 Received: from lhrrgout.huawei.com ([185.176.76.210]:32866 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726334AbfBEKCs (ORCPT ); Tue, 5 Feb 2019 05:02:48 -0500 Received: from LHREML711-CAH.china.huawei.com (unknown [172.18.7.106]) by Forcepoint Email with ESMTP id 392CDCD9A6337D8C23F2; Tue, 5 Feb 2019 10:02:47 +0000 (GMT) Received: from [10.204.65.155] (10.204.65.155) by smtpsuk.huawei.com (10.201.108.34) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 5 Feb 2019 10:02:37 +0000 Subject: Re: [PATCH v9 6/6] tpm: pass an array of tpm_extend_digest structures to tpm_pcr_extend() To: Mimi Zohar , , , , CC: , , , , References: <20190201100641.26936-1-roberto.sassu@huawei.com> <20190201100641.26936-7-roberto.sassu@huawei.com> <1549048506.6993.73.camel@linux.ibm.com> From: Roberto Sassu Message-ID: Date: Tue, 5 Feb 2019 11:02:36 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <1549048506.6993.73.camel@linux.ibm.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.204.65.155] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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