Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3836093ybt; Tue, 23 Jun 2020 11:56:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLpI5Ze5WSSh2gckwuEbu9JHsc1Z+9EL9yE+rfar5yGenjQCk9vu/QU6P5y4iCC6hH/mwU X-Received: by 2002:a17:906:d93c:: with SMTP id rn28mr22984883ejb.190.1592938564908; Tue, 23 Jun 2020 11:56:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592938564; cv=none; d=google.com; s=arc-20160816; b=cKMy1/24tIvCAxjdHMYesI55/51S+gUEbX3sOKD7Hu/vs2drtgUVacNHNL1fdJfoag fSHwd1Dw9zlTiNuYRjJvvZmDKmXHC2dvJ8Kmg2AFeD0qae0U3VEmwSI6sNvjTH6g8Yq8 N9SxJDvGYlbd4tkN4MtluNRR3jEkFYEtdDA94V5NnqJi/zluXlvxb5gNzKs4GOjK1fwc 8/8D//NMiOgXAldR9ZN8k7DxogLfOEWfLyUn1Avr4BI5tdC9t59eNcP6bKeCWm85OPQY 3BK0FbuYAXWwhSQQfLtP5Frbacp5Zrj1BaHKlE6cMaE/zCxtWQzaDQ5IXRLXnl1BgoFe Ia8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:in-reply-to :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=3nSi1zETIGlAkjRMSn7k5XllL026D0zQEnDLfZ6KCh4=; b=I5QyRQNjMQxsYF4anqV7wqRnM5clP1Ir/tRrU2b7nc5hekjaFmEKFIv0yU3mKFUv7t qux00yUwYEP5VCHi29ztymLIBMz6q6tzOMKAGl/j46JIZnPtC1/WLGitkorZtT+licOI Ax/lsh90YIB079MilGVXbpPEhFim2nm1jbUL9avZAtL99y3Pi4IiBn6m1CiGF5kiQMFv G/PX+aUsa0U0iXpf7KdrRcY4s6n9Yyj2B6h8cqBD9eePQfIS0SQWE96qS3wjQbv5B2T7 eqje8jViJcPWfB5Bqak9kUrnCZ1B7/wxjVJPqN2eBINTAUsq2/wIzi8xzLmrrm7+jh3b bFjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TTs+NYTU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt8si1671233ejc.466.2020.06.23.11.55.41; Tue, 23 Jun 2020 11:56:04 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TTs+NYTU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733236AbgFWSxO (ORCPT + 99 others); Tue, 23 Jun 2020 14:53:14 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:57397 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1733218AbgFWSxN (ORCPT ); Tue, 23 Jun 2020 14:53:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592938392; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3nSi1zETIGlAkjRMSn7k5XllL026D0zQEnDLfZ6KCh4=; b=TTs+NYTU+pSV1yjm27iuob+MJKty/p6kKHZN4P4SAx0jjaSQ+8ED3G0k37BeYUdWfaap8z EY/tx+QDj0OAGhSSnb1NTlwq2OOlsWn5Uuza++TLemQZ5yEqXOXGf1nFv2KrP92yrk6ckh MnT6ioBqFaM6f8/D8jZKchx7ubGx0Ew= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-493-nhT-KQwFMOaBe6CR_NjNkQ-1; Tue, 23 Jun 2020 14:53:04 -0400 X-MC-Unique: nhT-KQwFMOaBe6CR_NjNkQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C6528031CB; Tue, 23 Jun 2020 18:53:02 +0000 (UTC) Received: from localhost (ovpn-116-11.gru2.redhat.com [10.97.116.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id B559060CD3; Tue, 23 Jun 2020 18:53:01 +0000 (UTC) Date: Tue, 23 Jun 2020 15:53:00 -0300 From: Bruno Meneguele To: Maurizio Drocco Cc: zohar@linux.ibm.com, 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, mdrocco@linux.vnet.ibm.com, roberto.sassu@huawei.com, serge@hallyn.com Subject: Re: [PATCH v4] ima: extend boot_aggregate with kernel measurements Message-ID: <20200623185300.GD4983@glitch> References: <1592920990.5437.15.camel@linux.ibm.com> <20200623155732.105-1-maurizio.drocco@ibm.com> MIME-Version: 1.0 In-Reply-To: <20200623155732.105-1-maurizio.drocco@ibm.com> X-PGP-Key: http://keys.gnupg.net/pks/lookup?op=get&search=0x3823031E4660608D X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="8w3uRX/HFJGApMzv" Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --8w3uRX/HFJGApMzv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jun 23, 2020 at 11:57:32AM -0400, Maurizio Drocco wrote: > 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 should be > only included in non-SHA1 digests to avoid ambiguity. >=20 > Signed-off-by: Maurizio Drocco > --- > Changelog: > v4: > - Reworded comments: PCRs 8 & 9 are always included in non-sha1 digests > v3: > - Limit including PCRs 8 & 9 to non-sha1 hashes > v2: > - Minor comment improvements > v1: > - Include non zero PCRs 8 & 9 in the boot_aggregate >=20 > security/integrity/ima/ima.h | 2 +- > security/integrity/ima/ima_crypto.c | 15 ++++++++++++++- > 2 files changed, 15 insertions(+), 2 deletions(-) >=20 > 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 @@ > =20 > enum ima_show_type { IMA_SHOW_BINARY, IMA_SHOW_BINARY_NO_FIELD_LEN, > =09=09 IMA_SHOW_BINARY_OLD_STRING_FMT, IMA_SHOW_ASCII }; > -enum tpm_pcrs { TPM_PCR0 =3D 0, TPM_PCR8 =3D 8 }; > +enum tpm_pcrs { TPM_PCR0 =3D 0, TPM_PCR8 =3D 8, TPM_PCR10 =3D 10 }; > =20 > /* digest size for IMA, fits SHA1 or MD5 */ > #define IMA_DIGEST_SIZE=09=09SHA1_DIGEST_SIZE > diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima= /ima_crypto.c > index 220b14920c37..011c3c76af86 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, > =09if (rc !=3D 0) > =09=09return rc; > =20 > -=09/* cumulative sha1 over tpm registers 0-7 */ > +=09/* cumulative digest over TPM registers 0-7 */ > =09for (i =3D TPM_PCR0; i < TPM_PCR8; i++) { > =09=09ima_pcrread(i, &d); > =09=09/* now accumulate with current aggregate */ > =09=09rc =3D crypto_shash_update(shash, d.digest, > =09=09=09=09=09 crypto_shash_digestsize(tfm)); > =09} > +=09/* > +=09 * Extend cumulative digest over TPM registers 8-9, which contain > +=09 * measurement for the kernel command line (reg. 8) and image (reg. 9= ) > +=09 * in a typical PCR allocation. Registers 8-9 are only included in > +=09 * non-SHA1 boot_aggregate digests to avoid ambiguity. > +=09 */ > +=09if (alg_id !=3D TPM_ALG_SHA1) { > +=09=09for (i =3D TPM_PCR8; i < TPM_PCR10; i++) { > +=09=09=09ima_pcrread(i, &d); > +=09=09=09rc =3D crypto_shash_update(shash, d.digest, > +=09=09=09=09=09=09crypto_shash_digestsize(tfm)); > +=09=09} > +=09} > =09if (!rc) > =09=09crypto_shash_final(shash, digest); > =09return rc; > --=20 > 2.17.1 >=20 Reviewed-by: Bruno Meneguele I've tested this patch with both TPM 1.2 and TPM 2.0 + ima-evm-utils support patch. Everything seems fine. Thanks. --=20 bmeneg=20 PGP Key: http://bmeneg.com/pubkey.txt --8w3uRX/HFJGApMzv Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEdWo6nTbnZdbDmXutYdRkFR+RokMFAl7yT4wACgkQYdRkFR+R okN1EAgApl7aO6m1nHUaan+Iu9VccMELoK4mnHb3gCgwKZc16uXp1p+fxxwvIViJ honMESymPNb6656OK5VYAAA7x9EXQIdd6vZDSpcFVy+0RMxBPxlPR3JGciQSWsnu YqJcum3u2MPaRv0xmqrz7pCuHJ5fFVju5ouaS8oHrdpB9q3LsTgqL2L6mBd4qBoD 9PG68MQOTEUoArQ+IIXTn4lBFGPHl4wM/my5lsO6zAZ7MPmqtoJQwwWbb3Qr/DUn IivKJlivRrnGkVFI4m6fcBYRshyVHmFii2RjVPUVrMdNpq3Je6CA8bdLxvQ6tw6m Kjs+LH+RbK6w2wJ3L7CW8ZgxPG+tmQ== =9sj9 -----END PGP SIGNATURE----- --8w3uRX/HFJGApMzv--