Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3741054ybl; Mon, 27 Jan 2020 09:30:48 -0800 (PST) X-Google-Smtp-Source: APXvYqyq04x1sN7j0Sa8C2sNmEh7foqvsvNlZlWYYVzzgRp/JKqgW2qPDWoYuy0FmQjzsAuU49Br X-Received: by 2002:a9d:6184:: with SMTP id g4mr6632192otk.223.1580146247990; Mon, 27 Jan 2020 09:30:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580146247; cv=none; d=google.com; s=arc-20160816; b=BRJCzAXl3lAllrszWGfROP/3SE5ErX8KkpGTPnNfM6EhZbCFatbN+jQlh2wHBZDlm9 T9WjbEV2JtZEBPJIm18Ty3thYQnMrZZJk9V8Qo1SiqfSTdRSbl2MnNikYz2tvo4qRVE7 dSCeVEML0jThAdQEGnC+rzbapUV8cqRRMRivn7ynjJL/FmkI3GTivZMOBVkDi9mhsSqD rNHfSfBeWOsqlVMV5dIJNhxSbCqioFFicTsISex/64YuBlvSIk1XeCpYuWxlG4Eedp9U NFQitVttz/E4WNOlZYnK+taGjPvQ5nSjH+7Aopw9B3kNdRs44bQWvy4KJsql7H1ZjCdv BX0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=hS5lZ5AkIHd5wP9cxnFLyfleP7azVcHj/RbEUHvCwwI=; b=SGtHSuoGMv9JDrq2R6R6AcChEt5itYFkpXzkfVf5+sDqhneKYI6Fgj4JiNQwHfvciB GMOP2yo81vlhf4F+/O/thmH6NBj60cfqyZpbSXpBTKG5wfg+KvvNJsNmhLPyqO34GF9G 4t3axUUrfE6WSZIyZax/XxM6ondk5OLy4fy0ggxmxT8nNqyVvkkzVUMoSlx+F9p8qdEa Z2F8lXXYQv1q8ePyNlyy1b138/CNDP0UCMPzdmsgudm/QHkW0gcsLXrOFXZXnKD8tTV2 ZQYYtcYUul+opqUKT5kZenxrNl8wuaT4gsNQPLE91aebsfHOIAYMOo+Z2Ewae5kba+pK Kzpg== 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 x68si3729621oia.227.2020.01.27.09.30.35; Mon, 27 Jan 2020 09:30:47 -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 S1726099AbgA0R3i convert rfc822-to-8bit (ORCPT + 99 others); Mon, 27 Jan 2020 12:29:38 -0500 Received: from lhrrgout.huawei.com ([185.176.76.210]:2310 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725907AbgA0R3i (ORCPT ); Mon, 27 Jan 2020 12:29:38 -0500 Received: from LHREML714-CAH.china.huawei.com (unknown [172.18.7.106]) by Forcepoint Email with ESMTP id AE045A5854A2C70C7BF5; Mon, 27 Jan 2020 17:29:36 +0000 (GMT) Received: from fraeml701-chm.china.huawei.com (10.206.15.50) by LHREML714-CAH.china.huawei.com (10.201.108.37) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 27 Jan 2020 17:29:35 +0000 Received: from fraeml714-chm.china.huawei.com (10.206.15.33) by fraeml701-chm.china.huawei.com (10.206.15.50) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Mon, 27 Jan 2020 18:29:35 +0100 Received: from fraeml714-chm.china.huawei.com ([10.206.15.33]) by fraeml714-chm.china.huawei.com ([10.206.15.33]) with mapi id 15.01.1713.004; Mon, 27 Jan 2020 18:29:36 +0100 From: Roberto Sassu To: "zohar@linux.ibm.com" , "jarkko.sakkinen@linux.intel.com" , "james.bottomley@hansenpartnership.com" , "linux-integrity@vger.kernel.org" CC: "linux-security-module@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Silviu Vlasceanu Subject: RE: [PATCH 6/8] ima: calculate and extend PCR with digests in ima_template_entry Thread-Topic: [PATCH 6/8] ima: calculate and extend PCR with digests in ima_template_entry Thread-Index: AQHV1TQzib8f0iknEECfOoz/Jg91LKf+w3NA Date: Mon, 27 Jan 2020 17:29:35 +0000 Message-ID: References: <20200127170443.21538-1-roberto.sassu@huawei.com> <20200127170443.21538-7-roberto.sassu@huawei.com> In-Reply-To: <20200127170443.21538-7-roberto.sassu@huawei.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.220.96.108] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > -----Original Message----- > From: Roberto Sassu > Sent: Monday, January 27, 2020 6:05 PM > To: zohar@linux.ibm.com; jarkko.sakkinen@linux.intel.com; > james.bottomley@hansenpartnership.com; linux-integrity@vger.kernel.org > Cc: linux-security-module@vger.kernel.org; linux-kernel@vger.kernel.org; > Silviu Vlasceanu ; Roberto Sassu > > Subject: [PATCH 6/8] ima: calculate and extend PCR with digests in > ima_template_entry > > This patch modifies ima_calc_field_array_hash() to calculate a template > digest for each allocated PCR bank and SHA1. It also passes the tpm_digest > array of the template entry to ima_pcr_extend() or in case of a violation, > the pre-initialized digests array filled with 0xff. > > Padding with zeros is still done if the mapping between TPM algorithm ID > and crypto ID is unknown. > > This patch calculates again the template digest when a measurement list is > restored. Copying only the SHA1 digest (due to the limitation of the > current measurement list format) is not sufficient, as hash collision > detection will be done on the digest calculated with the default IMA hash > algorithm. > > Signed-off-by: Roberto Sassu > --- > security/integrity/ima/ima_crypto.c | 26 ++++++++++++++++++++++- > security/integrity/ima/ima_queue.c | 30 ++++++++++++++++----------- > security/integrity/ima/ima_template.c | 14 +++++++++++-- > 3 files changed, 55 insertions(+), 15 deletions(-) > > diff --git a/security/integrity/ima/ima_crypto.c > b/security/integrity/ima/ima_crypto.c > index 63fb4bdf80b0..786340feebbb 100644 > --- a/security/integrity/ima/ima_crypto.c > +++ b/security/integrity/ima/ima_crypto.c > @@ -610,9 +610,33 @@ static int ima_calc_field_array_hash_tfm(struct > ima_field_data *field_data, > int ima_calc_field_array_hash(struct ima_field_data *field_data, > struct ima_template_entry *entry) > { > - int rc; > + u16 alg_id; > + int rc, i; > > rc = ima_calc_field_array_hash_tfm(field_data, entry, > ima_sha1_idx); > + if (rc) > + return rc; > + > + entry->digests[ima_sha1_idx].alg_id = TPM_ALG_SHA1; > + > + for (i = 0; i < ima_tpm_chip->nr_allocated_banks + 1; i++) { > + if (i == ima_sha1_idx) > + continue; > + > + alg_id = ima_tpm_chip->allocated_banks[i].alg_id; The line above should be executed for i < ima_tpm_chip->nr_allocated_banks. I will fix in the next version of the patch set. Roberto HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063 Managing Director: Li Peng, Li Jian, Shi Yanli