Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1m5x4y-0007Zj-21 for mharc-grub-devel@gnu.org; Tue, 20 Jul 2021 17:15:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46350) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5x4u-0007Wb-Um for grub-devel@gnu.org; Tue, 20 Jul 2021 17:15:00 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:45600) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5x4s-0001t8-N1 for grub-devel@gnu.org; Tue, 20 Jul 2021 17:15:00 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16KL2reb195025; Tue, 20 Jul 2021 17:14:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : mime-version; s=pp1; bh=YWD4gG7xLLuuGp27qP2USM/jzocIYgCQyhPeaRapkeQ=; b=d4Im38Rpxtz29Z8tPdvS+gRRStfeFUkfwNU4QwsAideHoHWwWdKqKwCdFCnO5OEFVM4Y 0VBKf6nefcTKYx9cv/9AVzKhYWkR6O/VpQWCRXZWmsukswmCtSP0mcYiOHH6KKVjEm/C 4q1gAFjfT0busDvPDCykldIWeyqEF9dgGKo96M3ihdl0yXHadVel/WQCeeT5xo/sUGJ7 8T1DwWHt1d4UlVAB1SMsLvRKtFl0gbzEivFpx2Ewko/SpvDikfdv/n1O2hVk2t4R7og7 emTS5ezNzyP220APPzaBqC6rhA2S+YOiqOnmotzVFDfhF/Dv63f+3Y4oiT8ynF6dHYWB EA== Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com with ESMTP id 39x0p72pr0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Jul 2021 17:14:54 -0400 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 16KLCGUE004014; Tue, 20 Jul 2021 21:14:53 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 39upubgwwf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Jul 2021 21:14:53 +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 16KLEq1424183262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Jul 2021 21:14:52 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6B326C605D; Tue, 20 Jul 2021 21:14:52 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1D97DC6059; Tue, 20 Jul 2021 21:14:52 +0000 (GMT) Received: from sbct-2.. (unknown [9.47.158.152]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 20 Jul 2021 21:14:52 +0000 (GMT) From: Stefan Berger To: grub-devel@gnu.org Cc: dkiper@net-space.pl, Stefan Berger , Eric Snowberg Subject: [PATCH v2 4/4] ibmvtpm: Add support for trusted boot using a vTPM 2.0 Date: Tue, 20 Jul 2021 17:14:49 -0400 Message-Id: <20210720211449.572356-5-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210720211449.572356-1-stefanb@linux.vnet.ibm.com> References: <20210720211449.572356-1-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: u0ynRcMTKJAir00il1tHjiNB1txwFylT X-Proofpoint-GUID: u0ynRcMTKJAir00il1tHjiNB1txwFylT Content-Transfer-Encoding: 8bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-20_13:2021-07-19, 2021-07-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 impostorscore=0 malwarescore=0 clxscore=1011 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107200131 Received-SPF: none client-ip=148.163.158.5; envelope-from=stefanb@linux.vnet.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Jul 2021 21:15:01 -0000 From: Stefan Berger Add support for trusted boot using a vTPM 2.0 on the IBM IEEE1275 PowerPC platform. With this patch grub now measures text and binary data into the TPM's PCRs 8 and 9 in the same way as the x86_64 platform does. Cc: Eric Snowberg Signed-off-by: Stefan Berger --- docs/grub.texi | 3 +- grub-core/Makefile.core.def | 7 ++ grub-core/commands/ieee1275/ibmvtpm.c | 169 ++++++++++++++++++++++++++ 3 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 grub-core/commands/ieee1275/ibmvtpm.c diff --git a/docs/grub.texi b/docs/grub.texi index f8b4b3b21..23d2f2d90 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -6023,7 +6023,8 @@ tpm module is loaded. As such it is recommended that the tpm module be built into @file{core.img} in order to avoid a potential gap in measurement between @file{core.img} being loaded and the tpm module being loaded. -Measured boot is currently only supported on EFI platforms. +Measured boot is currently only supported on EFI and IBM IEEE1275 PowerPC +platforms. @node Lockdown @section Lockdown when booting on a secure setup diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 8022e1c0a..e6ac50704 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1118,6 +1118,13 @@ module = { enable = powerpc_ieee1275; }; +module = { + name = tpm; + common = commands/tpm.c; + ieee1275 = commands/ieee1275/ibmvtpm.c; + enable = powerpc_ieee1275; +}; + module = { name = terminal; common = commands/terminal.c; diff --git a/grub-core/commands/ieee1275/ibmvtpm.c b/grub-core/commands/ieee1275/ibmvtpm.c new file mode 100644 index 000000000..d61cb111a --- /dev/null +++ b/grub-core/commands/ieee1275/ibmvtpm.c @@ -0,0 +1,169 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2021 Free Software Foundation, Inc. + * Copyright (C) 2021 IBM Corporation + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + * + * IBM vTPM support code. + */ + +#include +#include +#include +#include +#include +#include + +struct tpm_2hash_ext_log +{ + struct grub_ieee1275_common_hdr common; + grub_ieee1275_cell_t method; + grub_ieee1275_cell_t ihandle; + grub_ieee1275_cell_t size; + grub_ieee1275_cell_t buf; + grub_ieee1275_cell_t description_size; + grub_ieee1275_cell_t description; + grub_ieee1275_cell_t eventtype; + grub_ieee1275_cell_t pcrindex; + grub_ieee1275_cell_t catch_result; + grub_ieee1275_cell_t rc; +}; + +#define IEEE1275_CELL_TRUE ((grub_ieee1275_cell_t) -1) + +static grub_ieee1275_ihandle_t tpm_ihandle; +static grub_uint8_t tpm_version; + +static grub_ieee1275_ihandle_t +tpm_init (void) +{ + static int init_called = 0; + + if (!init_called) + { + init_called = 1; + grub_ieee1275_open ("/vdevice/vtpm", &tpm_ihandle); + } + + return tpm_ihandle; +} + +static void +tpm_get_tpm_version (void) +{ + static int version_probed = 0; + grub_ieee1275_phandle_t vtpm; + char buffer[20]; + grub_ssize_t buffer_size; + + if (!version_probed) + { + version_probed = 1; + if (!grub_ieee1275_finddevice ("/vdevice/vtpm", &vtpm) && + !grub_ieee1275_get_property (vtpm, "compatible", buffer, + sizeof buffer, &buffer_size) && + !grub_strcmp (buffer, "IBM,vtpm20")) + { + tpm_version = 2; + } + } +} + +static grub_err_t +tpm_handle_find (grub_ieee1275_ihandle_t *tpm_handle) +{ + *tpm_handle = tpm_init (); + if (*tpm_handle == 0) + return GRUB_ERR_UNKNOWN_DEVICE; + + tpm_get_tpm_version (); + + return GRUB_ERR_NONE; +} + +static int +ibmvtpm_2hash_ext_log (grub_uint32_t ihandle, + grub_uint8_t pcrindex, + grub_uint32_t eventtype, + const char *description, + grub_size_t description_size, + void *buf, grub_size_t size) +{ + struct tpm_2hash_ext_log args; + + INIT_IEEE1275_COMMON (&args.common, "call-method", 8, 2); + args.method = (grub_ieee1275_cell_t) "2hash-ext-log"; + args.ihandle = ihandle; + args.pcrindex = pcrindex; + args.eventtype = eventtype; + args.description = (grub_ieee1275_cell_t) description; + args.description_size = description_size; + args.buf = (grub_ieee1275_cell_t) buf; + args.size = (grub_ieee1275_cell_t) size; + + if (IEEE1275_CALL_ENTRY_FN (&args) == -1) + return -1; + + /* + * catch_result is set if firmware does not support 2hash-ext-log + * rc is TRUE (-1) on success + */ + if ((args.catch_result) || args.rc != IEEE1275_CELL_TRUE) + return -1; + + return 0; +} + +static grub_err_t +tpm2_log_event (grub_ieee1275_ihandle_t tpm_handle, unsigned char *buf, + grub_size_t size, grub_uint8_t pcr, + const char *description) +{ + static int error_displayed; + int err; + + err = ibmvtpm_2hash_ext_log (tpm_handle, + pcr, EV_IPL, + description, + grub_strlen(description) + 1, + buf, size); + if (err && error_displayed < 1) + { + error_displayed++; + grub_error (GRUB_ERR_BAD_DEVICE, + "2HASH-EXT-LOG failed: Firmware is likely too old.\n"); + } + + return GRUB_ERR_NONE; +} + +grub_err_t +grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr, + const char *description) +{ + grub_ieee1275_ihandle_t tpm_handle; + + /* Absence of a TPM isn't a failure. */ + if (tpm_handle_find (&tpm_handle) != GRUB_ERR_NONE) + return GRUB_ERR_NONE; + + grub_dprintf ("tpm", "log_event, pcr = %d, size = 0x%" PRIxGRUB_SIZE ", %s\n", + pcr, size, description); + + if (tpm_version == 2) + return tpm2_log_event (tpm_handle, buf, size, pcr, description); + + return GRUB_ERR_NONE; +} -- 2.25.1