Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3120902yba; Sat, 18 May 2019 09:41:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxtlyJyHT25XIhR3sGQSEr4ijrzQyb72yMoWeN3aryQzEhjZJNwJjffvUS95oI8Q0PrSqRQ X-Received: by 2002:a17:902:46a:: with SMTP id 97mr36633277ple.66.1558197692435; Sat, 18 May 2019 09:41:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558197692; cv=none; d=google.com; s=arc-20160816; b=AZ9mD9aR0/ywGSer5F8NDrk/lWJL7X9vem5kyAuMyyH8cHMjGOVN7tf1sEo2DIpuvO erlWI2WnPczA1Bv9UH+Bg01AWmUGQhyE/iLkSI8XzU2jrRNfRsR3wkkOR6nuW2Tx7raK ioUT3+/WVmctGkN4q5nXhgD+xXqcKt16t7MFsurTHWLPUMhU+ZqQ6z5tPpU2pOZv30vg b3pv3gUQvAHbxN2PnWRj4JtxrCi0A9wLNBOfVttXK8PYxQAjZknVuRE8VUZEZKEYxwe6 FP+Ieb35itDUstHBe2RcRu58kFkEiCG19PHeD0BTJRWlapDLGrGwaJ8yJOb4nxAtSDv3 gHrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=NUYaBpI7HtM+jFnabamgjA4IxjSWFzxdWp6kmm3cyvc=; b=rjX8blcjkCIiIS1FtOPZ96jWIgv4BFIABPPg3riXLjgNAfZuOwqWZz3vncf8/k5Kkh JMVROGcRTc4P2qOeKvV9ElLg6GQ7p+d28LpKQf9++D2TEl0QYjWf6sAid/OwSfQnIS/l o8Kz4WKIkmpPW5Pg0Y1IRJQEGYs1CjRQsnWdIMJZbBolwU2Q3f1RuX6+/nnwMZiCEwc0 HyDxE3mTzxnErwMz8rr8iMXA7qBWDi1XhjRrEEK3+hvZRSXhvd4x4lCGVuLbV41fCRDF hXTeJ/iQjkuE/MkGy7XxqWJtSV5kFsmC4JaVAgFwehr22wjPpl1LMV68WIsY14owokz3 KTVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mIEuqgFs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s1si4865846pgs.62.2019.05.18.09.41.17; Sat, 18 May 2019 09:41:32 -0700 (PDT) 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; dkim=pass header.i=@linaro.org header.s=google header.b=mIEuqgFs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729584AbfERQMn (ORCPT + 99 others); Sat, 18 May 2019 12:12:43 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:37616 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729515AbfERQMm (ORCPT ); Sat, 18 May 2019 12:12:42 -0400 Received: by mail-it1-f196.google.com with SMTP id m140so16801662itg.2 for ; Sat, 18 May 2019 09:12:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NUYaBpI7HtM+jFnabamgjA4IxjSWFzxdWp6kmm3cyvc=; b=mIEuqgFsXiDW3fTmdpRG+x6vjSNL10IgQt/XYQCA3tvAVqhB7QGkBxHPCI8wxwDhNd LKhT/cUnMNci9N1bDfqzL1yn8/f8bRZj27gZzeRWqddEubo6SN4yvRpclKXOZMz5xKUq 5Jy0L71fygPiUrbWvc/eNo4ajwTAUj4ROThEKRkR+Wv3qIFs2Yax6JCqkAcALdbSrrhk WixeukZ6A7rXQIIZ9adTcNBIRr66Pun66C+sC6rAy6XWix2BA/oWWbHiorYXcrJmzbUr 5C07cBiMW18gR75dHA5Mn8Jww09N2/+p29DRtnNsM/qqTrha/L3WWKTRqa3+fK63gTJd qIcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NUYaBpI7HtM+jFnabamgjA4IxjSWFzxdWp6kmm3cyvc=; b=It4g6CJWtYR/89xQIRduHO3S2Rs8q6s7XBJuiA5YNqgcpBZyYdNhOUawo7JXZmfscF zgUAqSmwFmfekICBm/QlUxoYxwBaO927AmZFZoFTgCD+pnSaF5SJG7pr8HIvAND16cZF U23qKtpBn2Hu6+kC4iwXvBBDJ3l9WxxN43RlaoArN1BWgYLumTdfbjPQm8ORPnUbSISw LHC4iFtgtrPhNJ082OrIVvl83pG/ZLnX+/7hyXOjxjSrsLqYobUEZxJfci0GCV0owAJk E1nZeK4QTKZqWVl5XGI9R+jkMcjTiwB8VIUxW0cBPrQ/f+QbCbXAO9mz1/WyL05bVLRa ql8g== X-Gm-Message-State: APjAAAVUyFHFMzTz2YZ3YftgC1P8peHpTu0DU99F77n5WDCP3fP2Dkc/ u0RVj9NVFJj/uVkbCv7GvgFmC6gm7eFjoDs9fDdP7g== X-Received: by 2002:a24:ca84:: with SMTP id k126mr4027300itg.104.1558195961792; Sat, 18 May 2019 09:12:41 -0700 (PDT) MIME-Version: 1.0 References: <20190517213918.26045-1-matthewgarrett@google.com> <20190517213918.26045-5-matthewgarrett@google.com> In-Reply-To: <20190517213918.26045-5-matthewgarrett@google.com> From: Ard Biesheuvel Date: Sat, 18 May 2019 18:12:29 +0200 Message-ID: Subject: Re: [PATCH V6 4/4] efi: Attempt to get the TCG2 event log in the boot stub To: Matthew Garrett Cc: linux-integrity , =?UTF-8?Q?Peter_H=C3=BCwe?= , Jarkko Sakkinen , Jason Gunthorpe , Roberto Sassu , linux-efi , linux-security-module , Linux Kernel Mailing List , Thiebaud Weksteen , Bartosz Szczepanek , Matthew Garrett Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 17 May 2019 at 23:39, Matthew Garrett wrote: > > From: Matthew Garrett > > Right now we only attempt to obtain the SHA1-only event log. The > protocol also supports a crypto agile log format, which contains digests > for all algorithms in use. Attempt to obtain this first, and fall back > to obtaining the older format if the system doesn't support it. This is > lightly complicated by the event sizes being variable (as we don't know > in advance which algorithms are in use), and the interface giving us > back a pointer to the start of the final entry rather than a pointer to > the end of the log - as a result, we need to parse the final entry to > figure out its length in order to know how much data to copy up to the > OS. > > Signed-off-by: Matthew Garrett > Tested-by: Jarkko Sakkinen > Reviewed-by: Jarkko Sakkinen > Signed-off-by: Jarkko Sakkinen This signoff doesn't belong here I think? > --- > drivers/firmware/efi/libstub/tpm.c | 57 ++++++++++++++++++++---------- > 1 file changed, 39 insertions(+), 18 deletions(-) > > diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/libstub/tpm.c > index 5bd04f75d8d6..b3f30448e454 100644 > --- a/drivers/firmware/efi/libstub/tpm.c > +++ b/drivers/firmware/efi/libstub/tpm.c > @@ -8,8 +8,13 @@ > * Thiebaud Weksteen > */ > #include > -#include > #include > +/* > + * KASAN redefines memcpy() in a way that isn't available in the EFI stub. > + * We need to include asm/efi.h before linux/tpm_eventlog.h in order to avoid > + * the wrong memcpy() being referenced. > + */ > +#include > Please drop this hunk. I just sent out a patch to fix this properly. > #include "efistub.h" > > @@ -57,7 +62,7 @@ void efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg) > > #endif > > -static void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg) > +void efi_retrieve_tpm2_eventlog(efi_system_table_t *sys_table_arg) > { > efi_guid_t tcg2_guid = EFI_TCG2_PROTOCOL_GUID; > efi_guid_t linux_eventlog_guid = LINUX_EFI_TPM_EVENT_LOG_GUID; > @@ -67,6 +72,7 @@ static void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg) > unsigned long first_entry_addr, last_entry_addr; > size_t log_size, last_entry_size; > efi_bool_t truncated; > + int version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_2; > void *tcg2_protocol = NULL; > > status = efi_call_early(locate_protocol, &tcg2_guid, NULL, > @@ -74,14 +80,20 @@ static void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg) > if (status != EFI_SUCCESS) > return; > > - status = efi_call_proto(efi_tcg2_protocol, get_event_log, tcg2_protocol, > - EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2, > - &log_location, &log_last_entry, &truncated); > - if (status != EFI_SUCCESS) > - return; > + status = efi_call_proto(efi_tcg2_protocol, get_event_log, > + tcg2_protocol, version, &log_location, > + &log_last_entry, &truncated); > + > + if (status != EFI_SUCCESS || !log_location) { > + version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2; > + status = efi_call_proto(efi_tcg2_protocol, get_event_log, > + tcg2_protocol, version, &log_location, > + &log_last_entry, &truncated); > + if (status != EFI_SUCCESS || !log_location) > + return; > + > + } > > - if (!log_location) > - return; > first_entry_addr = (unsigned long) log_location; > > /* > @@ -96,8 +108,23 @@ static void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg) > * We need to calculate its size to deduce the full size of > * the logs. > */ > - last_entry_size = sizeof(struct tcpa_event) + > - ((struct tcpa_event *) last_entry_addr)->event_size; > + if (version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) { > + /* > + * The TCG2 log format has variable length entries, > + * and the information to decode the hash algorithms > + * back into a size is contained in the first entry - > + * pass a pointer to the final entry (to calculate its > + * size) and the first entry (so we know how long each > + * digest is) > + */ > + last_entry_size = > + __calc_tpm2_event_size((void *)last_entry_addr, > + (void *)(long)log_location, > + false); > + } else { > + last_entry_size = sizeof(struct tcpa_event) + > + ((struct tcpa_event *) last_entry_addr)->event_size; > + } > log_size = log_last_entry - log_location + last_entry_size; > } > > @@ -114,7 +141,7 @@ static void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg) > > memset(log_tbl, 0, sizeof(*log_tbl) + log_size); > log_tbl->size = log_size; > - log_tbl->version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2; > + log_tbl->version = version; > memcpy(log_tbl->log, (void *) first_entry_addr, log_size); > > status = efi_call_early(install_configuration_table, > @@ -126,9 +153,3 @@ static void efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg) > err_free: > efi_call_early(free_pool, log_tbl); > } > - > -void efi_retrieve_tpm2_eventlog(efi_system_table_t *sys_table_arg) > -{ > - /* Only try to retrieve the logs in 1.2 format. */ > - efi_retrieve_tpm2_eventlog_1_2(sys_table_arg); > -} > -- > 2.21.0.1020.gf2820cf01a-goog >