From patchwork Mon Mar 30 12:10:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 1263921 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48rWX33zb5z9sQt for ; Mon, 30 Mar 2020 23:11:15 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 48rWX24N7tzDqd1 for ; Mon, 30 Mar 2020 23:11:14 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=stefanb@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 48rWWJ5W1vzDqLs for ; Mon, 30 Mar 2020 23:10:36 +1100 (AEDT) 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 02UC3WGl095779; Mon, 30 Mar 2020 08:10:33 -0400 Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0b-001b2d01.pphosted.com with ESMTP id 30206x2wkb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 Mar 2020 08:10:33 -0400 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 02UCAGHi032364; Mon, 30 Mar 2020 12:10:32 GMT Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by ppma03dal.us.ibm.com with ESMTP id 301x774jjd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 Mar 2020 12:10:32 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 02UCAVK434144618 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 Mar 2020 12:10:31 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D12ECAE063; Mon, 30 Mar 2020 12:10:31 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C1E85AE062; Mon, 30 Mar 2020 12:10:31 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 30 Mar 2020 12:10:31 +0000 (GMT) From: Stefan Berger To: aik@ozlabs.ru, slof@lists.ozlabs.org Date: Mon, 30 Mar 2020 08:10:27 -0400 Message-Id: <20200330121029.866011-2-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200330121029.866011-1-stefanb@linux.vnet.ibm.com> References: <20200330121029.866011-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.645 definitions=2020-03-30_01:2020-03-27, 2020-03-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 spamscore=0 lowpriorityscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 phishscore=0 priorityscore=1501 mlxscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003300111 Subject: [SLOF] [PATCH v2 1/3] tcgbios: Only write logs for PCRs that are allocated X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Berger Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" From: Stefan Berger Only write the logs for those PCRs that are allocated in banks. Signed-off-by: Stefan Berger --- lib/libtpm/tcgbios.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c index fa2ab2b..81f351c 100644 --- a/lib/libtpm/tcgbios.c +++ b/lib/libtpm/tcgbios.c @@ -237,7 +237,7 @@ static int tpm20_build_digest(struct tpm_log_entry *le, const uint8_t *sha256, struct tpms_pcr_selection *sel; void *nsel, *end; void *dest = le->hdr.digests + sizeof(struct TPML_DIGEST_VALUES); - uint32_t count; + uint32_t count, numAlgs; struct TPMT_HA *v; struct TPML_DIGEST_VALUES *vs; @@ -245,7 +245,7 @@ static int tpm20_build_digest(struct tpm_log_entry *le, const uint8_t *sha256, end = (void *)tpm_state.tpm20_pcr_selection + tpm_state.tpm20_pcr_selection_size; - for (count = 0; + for (count = 0, numAlgs = 0; count < be32_to_cpu(tpm_state.tpm20_pcr_selection->count); count++) { int hsize; @@ -255,6 +255,12 @@ static int tpm20_build_digest(struct tpm_log_entry *le, const uint8_t *sha256, if (nsel > end) break; + /* PCR 0-7 unused ? -- skip */ + if (!sizeOfSelect || sel->pcrSelect[0] == 0) { + sel = nsel; + continue; + } + hsize = tpm20_get_hash_buffersize(be16_to_cpu(sel->hashAlg)); if (hsize < 0) { dprintf("TPM is using an unsupported hash: %d\n", @@ -280,6 +286,8 @@ static int tpm20_build_digest(struct tpm_log_entry *le, const uint8_t *sha256, dest += sizeof(*v) + hsize; sel = nsel; + + numAlgs++; } if (sel != end) { @@ -289,9 +297,9 @@ static int tpm20_build_digest(struct tpm_log_entry *le, const uint8_t *sha256, vs = (void*)le->hdr.digests; if (bigEndian) - vs->count = cpu_to_be32(count); + vs->count = cpu_to_be32(numAlgs); else - vs->count = cpu_to_le32(count); + vs->count = cpu_to_le32(numAlgs); return dest - (void*)le->hdr.digests; } @@ -643,13 +651,13 @@ static int tpm20_write_EfiSpecIdEventStruct(void) struct tpm_log_entry le = { .hdr.eventtype = cpu_to_log32(EV_NO_ACTION), }; - uint32_t count; + uint32_t count, numAlgs; sel = tpm_state.tpm20_pcr_selection->selections; end = (void*)tpm_state.tpm20_pcr_selection + tpm_state.tpm20_pcr_selection_size; - for (count = 0; + for (count = 0, numAlgs = 0; count < be32_to_cpu(tpm_state.tpm20_pcr_selection->count); count++) { int hsize; @@ -659,6 +667,12 @@ static int tpm20_write_EfiSpecIdEventStruct(void) if (nsel > end) break; + /* PCR 0-7 unused ? -- skip */ + if (!sizeOfSelect || sel->pcrSelect[0] == 0) { + sel = nsel; + continue; + } + hsize = tpm20_get_hash_buffersize(be16_to_cpu(sel->hashAlg)); if (hsize < 0) { dprintf("TPM is using an unsupported hash: %d\n", @@ -673,9 +687,10 @@ static int tpm20_write_EfiSpecIdEventStruct(void) return -1; } - event.hdr.digestSizes[count].algorithmId = + event.hdr.digestSizes[numAlgs].algorithmId = cpu_to_log16(be16_to_cpu(sel->hashAlg)); - event.hdr.digestSizes[count].digestSize = cpu_to_log16(hsize); + event.hdr.digestSizes[numAlgs].digestSize = cpu_to_log16(hsize); + numAlgs++; sel = nsel; } @@ -685,9 +700,9 @@ static int tpm20_write_EfiSpecIdEventStruct(void) return -1; } - event.hdr.numberOfAlgorithms = cpu_to_log32(count); + event.hdr.numberOfAlgorithms = cpu_to_log32(numAlgs); event_size = offset_of(struct TCG_EfiSpecIdEventStruct, - digestSizes[count]); + digestSizes[numAlgs]); vendorInfoSize = (void*)&event + event_size; *vendorInfoSize = 0; event_size += sizeof(*vendorInfoSize);