Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3138446ybt; Mon, 22 Jun 2020 16:16:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuvkuU40mJxLN3Bc2R1VSIINMym0KPzApjLCxRS8500sv3m/pI64D8JonWJMF+1Pi2Qg2e X-Received: by 2002:a17:906:3154:: with SMTP id e20mr18471727eje.171.1592867787506; Mon, 22 Jun 2020 16:16:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592867787; cv=none; d=google.com; s=arc-20160816; b=tZeE61fHC9D472BJrz4dFkXUJwtzpzbfpqUAqUCPUqLGgzWZKWYp//5wRYld6bsNGq /cdtpn5Z0eKPGy6SN6R1blTjt9ChUFsx6evb4xZolNx8bYn9Pc+WTk8qqRA+8FsXziZr G1QvlfGs06BYGA98uD4i9ggbkbs9i305pr/smuQuHBpB55WlKOrZe1+Q2OXRA+gsK+Bj UWs+lpMWMioRQ3CkLnVV6/SxTAtE8boQ+k8q8vHjwBhijwv770TPd2uKK9E/SSHe23br RPyYi44uOTL/Kq1RKTdkKNYjiFnyBrIguGX1dGMTEFS0XqjR/k3hg+ZGK9Y+kHr0Mvtb nEYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=tqEW0/CpLYpFF4moxjeUC9j/lcP4au62iIwSe6RdBBk=; b=wps9vVc6mmHKKmZGDAF/6ot5+mnQ26WVnT+OGZq6bYDQu8CgyiC/mIs0uIIRrRXdhO Y40gY56woOeKr0FytOP1LqyV2PCXz0gteW4AGGHsvI5oIQLtFfy5DQKuQTJoQSsavuf1 tTIsgxCExsRJbSuT7UhKtHT4ni7/y7Q4s4/pueSVSWubG//RxivcTdy8KZh2Bz2fK5RZ TuxToBEPbd+OxJ+eiAh2R5GyHVcIKKCf8wB2WqPr5p0WVovPvSOoYjw+2dxR7r4ES4h6 Pk5T3TF1HquvrEH/hw69/3aNfUZX8jmNTKVZu+acgu5LZZaIXHz4DPAHPXM5ca7pjy9J XEBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r26si10505880edl.255.2020.06.22.16.16.02; Mon, 22 Jun 2020 16:16:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731075AbgFVXOP (ORCPT + 99 others); Mon, 22 Jun 2020 19:14:15 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:47566 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730985AbgFVXOO (ORCPT ); Mon, 22 Jun 2020 19:14:14 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05MN1AJi056068; Mon, 22 Jun 2020 19:14:00 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 31tyrxk9fn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 19:14:00 -0400 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 05MN1v4N059847; Mon, 22 Jun 2020 19:13:59 -0400 Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0b-001b2d01.pphosted.com with ESMTP id 31tyrxk9ff-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 19:13:59 -0400 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 05MMk4Zo005614; Mon, 22 Jun 2020 22:49:00 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma05wdc.us.ibm.com with ESMTP id 31sa38jynt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jun 2020 22:49:00 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 05MMmxx528770752 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jun 2020 22:48:59 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 82C77C6055; Mon, 22 Jun 2020 22:48:59 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4A083C6057; Mon, 22 Jun 2020 22:48:58 +0000 (GMT) Received: from DESKTOP-AV6EVPG.localdomain (unknown [9.160.111.155]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 22 Jun 2020 22:48:58 +0000 (GMT) From: Maurizio Drocco To: zohar@linux.ibm.com Cc: Silviu.Vlasceanu@huawei.com, dmitry.kasatkin@gmail.com, jejb@linux.ibm.com, jmorris@namei.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, maurizio.drocco@ibm.com, mdrocco@linux.vnet.ibm.com, roberto.sassu@huawei.com, serge@hallyn.com Subject: [PATCH] ima: extend boot_aggregate with kernel measurements Date: Mon, 22 Jun 2020 00:50:19 -0400 Message-Id: <20200622045019.1636-1-maurizio.drocco@ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <1592856871.4987.21.camel@linux.ibm.com> References: <1592856871.4987.21.camel@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-22_15:2020-06-22,2020-06-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 phishscore=0 spamscore=0 mlxscore=0 impostorscore=0 cotscore=-2147483648 suspectscore=1 mlxlogscore=999 clxscore=1015 priorityscore=1501 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2006220148 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org IMA is not considering TPM registers 8-9 when calculating the boot aggregate. When registers 8-9 are used to store measurements of the kernel and its command line (e.g., grub2 bootloader with tpm module enabled), IMA should include them in the boot aggregate. Registers 8-9 are only included in non-SHA1 boot_aggregate digests to avoid ambiguity. Signed-off-by: Maurizio Drocco --- security/integrity/ima/ima.h | 2 +- security/integrity/ima/ima_crypto.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index df93ac258e01..9d94080bdad8 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -30,7 +30,7 @@ enum ima_show_type { IMA_SHOW_BINARY, IMA_SHOW_BINARY_NO_FIELD_LEN, IMA_SHOW_BINARY_OLD_STRING_FMT, IMA_SHOW_ASCII }; -enum tpm_pcrs { TPM_PCR0 = 0, TPM_PCR8 = 8 }; +enum tpm_pcrs { TPM_PCR0 = 0, TPM_PCR8 = 8, TPM_PCR10 = 10 }; /* digest size for IMA, fits SHA1 or MD5 */ #define IMA_DIGEST_SIZE SHA1_DIGEST_SIZE diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c index 220b14920c37..d02917d85033 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -823,13 +823,26 @@ static int ima_calc_boot_aggregate_tfm(char *digest, u16 alg_id, if (rc != 0) return rc; - /* cumulative sha1 over tpm registers 0-7 */ + /* cumulative digest over tpm registers 0-7 */ for (i = TPM_PCR0; i < TPM_PCR8; i++) { ima_pcrread(i, &d); /* now accumulate with current aggregate */ rc = crypto_shash_update(shash, d.digest, crypto_shash_digestsize(tfm)); } + /* + * extend cumulative digest over tpm registers 8-9, which contain + * measurement for the kernel command line (reg. 8) and image (reg. 9) + * in a typical PCR allocation. Registers 8-9 are only included in + * non-SHA1 boot_aggregate digests to avoid ambiguity. + */ + if (alg_id != TPM_ALG_SHA1) { + for (i = TPM_PCR8; i < TPM_PCR10; i++) { + ima_pcrread(i, &d); + rc = crypto_shash_update(shash, d.digest, + crypto_shash_digestsize(tfm)); + } + } if (!rc) crypto_shash_final(shash, digest); return rc; -- 2.17.1