Received: by 10.213.65.68 with SMTP id h4csp187800imn; Tue, 13 Mar 2018 00:25:48 -0700 (PDT) X-Google-Smtp-Source: AG47ELvkfVfmytcHZKFrg4BRDxYmv/NnBs/jv8ArpAJF7tzbs3H0bBpOPkWwMgv8y2MyQCmyeyl6 X-Received: by 10.99.164.25 with SMTP id c25mr8952112pgf.235.1520925948035; Tue, 13 Mar 2018 00:25:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520925947; cv=none; d=google.com; s=arc-20160816; b=NU8+jPuFK/VfJxfboNbg57E/EgMQ9ecg9GJrxsiqYHEZ9kFJYovfAe+znzhMOzQtOq 70gnxJAhMgAeQNsRe5Ut1wTuIBtkjCUDxz4jspO2oZDS3ks3cntZSXBQA5FREyFtGnI2 28KfnXMgehz9kBEu+3TEZWjf7G84Lq0sGYgq9nAfqFXstBdOr9iLo5jIjtOkmoYzTOlB WoBvgtugJCgB/G9M5qG3wB8qkLBJudQARjCUgxmuyHwb9vT+8RmCBExmZgjwqsRB9gs7 e9rwApuk8fp34nJ7x1GTAqPhQotci0ZHUW9NvNGPzNb8MNnhMKuoiifoLGTj8IcLOQmr aj8A== 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 :arc-authentication-results; bh=ceDszTT2+ZM2LnziwK9Air7d1TQaNLBqJREVvzuXRKw=; b=l/1CfRDUiZQWGBJkypgFIz7Ah0ck1NBNoUTpgaU8YjKMA/2LKg0Y60M6LV9trzzU1H oLdoFkkUg63rk4+FWHKxDsTmELEh4t3w+KuGpXPasII2tKqz2M9kx3o3o9ZDPfAW5VSm NdLlNoy5aCkWGtp+54S1qgmqlC5naZJmk77KTzpfE+AALJpudFQrP5TMp9Ih2GYl0Xtj 2YU6/mQJph/pntvAtsMgrY1k9WdCjx4yJwpTWNlB8j3Jlr0s488RqrodxWfPxqBhFdIQ 4nt2ePhwZj9Ed7Nq2t6spzj8NvivcgKGrlOaubE+xPyRhWcKyIzM5gwVxK7mqa7zS/i1 mf6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hmbFPxjx; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si6147209pgr.795.2018.03.13.00.25.33; Tue, 13 Mar 2018 00:25:47 -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=@google.com header.s=20161025 header.b=hmbFPxjx; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752130AbeCMHYg (ORCPT + 99 others); Tue, 13 Mar 2018 03:24:36 -0400 Received: from mail-io0-f193.google.com ([209.85.223.193]:42698 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752068AbeCMHYe (ORCPT ); Tue, 13 Mar 2018 03:24:34 -0400 Received: by mail-io0-f193.google.com with SMTP id u84so14522989iod.9 for ; Tue, 13 Mar 2018 00:24:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ceDszTT2+ZM2LnziwK9Air7d1TQaNLBqJREVvzuXRKw=; b=hmbFPxjxXJGieghF2e2FQB3cauAwi986yddVJwyLoI1Kn7hMSEH4/v3+FEaIMjslte sMvJcg94sFOntCgrQ+91UIDacxDeY1OqWZ0QUe/hzNZmtTQqRrfoqsfV6qbMgeddrYha zwUGH8pXSLGTdDF2CdYL/C3xebN8SV4RbblYVlmRF4PGi11wW18YHKthPiLtfzIU5C6p C1FAt9auQMcwXVVDuN0QnKJ35OE1qiNhkr574az88MWLMGcVaKimPBHijYsUpGxAh8b+ k9+cVRSuB+mVHlibVRV3dKeEWqYH3kM5DADnPnbjgNNR9PJRvJWgmm4VKLG+gsOx7Jnf 5mlQ== 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=ceDszTT2+ZM2LnziwK9Air7d1TQaNLBqJREVvzuXRKw=; b=g4o+xjNydthoqakllbr0HIde2fDSS9Dejwz+XYzgTQhAGb9yNV9dHYNQICp7zB59Sh QH5HAOxY4DUJi/V/i9p1RsxvSszIMPcfvxDd6ckB4mLH8YVAw8vnkRd3NLJGK0X+DB5s aIusG6r6hl19yP7h9UmzNNvmwEBp6T34KkPVCHtnFJD0dCgOyATKRFaYp/rnQptNA417 aoOp7HQg9FSML8bla1qeVnPv8defZDTHWyACbcI0M+rgEUyBM4htFoK+G6USSVEOw6S9 5731COM/aJJRhN7RvuT5h7rdRHCymjo40Xk9nsv9629m72XQb1Tjpr1Y03E3ixLiFyO+ hx5A== X-Gm-Message-State: AElRT7GnHwcCRPagkW7xckM44RZer3LBlbv4cy+Z63v4SCNNxil9U2bY mKGlSUmupDnbn7JP/7PJZe4ptpHMBt1VXxr2P1/f5g== X-Received: by 10.107.183.65 with SMTP id h62mr11812411iof.278.1520925873108; Tue, 13 Mar 2018 00:24:33 -0700 (PDT) MIME-Version: 1.0 References: <01000161fc0b4755-df0621f4-ab5d-479a-b425-adf98427a308-000000@email.amazonses.com> <0100016206a68850-bd5c96b3-f275-46ea-98b1-1317e02a5d6e-000000@email.amazonses.com> <29c1640a-cf19-ca19-7de9-96f202edfb5a@redhat.com> <010001620bafa06b-41525407-603e-40a9-ba11-6033b2f5dcc7-000000@email.amazonses.com> <010001621a9e5069-0b1a6328-97e4-4396-9438-b90f5b8c82a4-000000@email.amazonses.com> <010001621b287e42-58955302-cc14-4212-b7b0-e6e358633dab-000000@email.amazonses.com> <010001621b7ce5a3-b80c55b8-be68-4b44-ab52-4949e8ddb8d0-000000@email.amazonses.com> In-Reply-To: From: Thiebaud Weksteen Date: Tue, 13 Mar 2018 07:24:22 +0000 Message-ID: Subject: Re: Regression from efi: call get_event_log before ExitBootServices To: Ard Biesheuvel Cc: Jeremy Cline , hdegoede@redhat.com, Javier Martinez Canillas , Jarkko Sakkinen , linux-efi@vger.kernel.org, linux-integrity@vger.kernel.org, tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org 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 Mon, Mar 12, 2018 at 10:03 PM Ard Biesheuvel wrote: > On 12 March 2018 at 19:55, Thiebaud Weksteen wrote: > > On Mon, Mar 12, 2018 at 7:33 PM Jeremy Cline wrote: > > > >> On 03/12/2018 02:29 PM, Thiebaud Weksteen wrote: > >> > On Mon, Mar 12, 2018 at 6:30 PM Ard Biesheuvel < > > ard.biesheuvel@linaro.org> > >> > wrote: > >> > > >> >> On 12 March 2018 at 17:01, Jeremy Cline wrote: > >> >>> On 03/12/2018 10:56 AM, Ard Biesheuvel wrote: > >> >>>> On 12 March 2018 at 14:30, Jeremy Cline wrote: > >> >>>>> On 03/12/2018 07:08 AM, Ard Biesheuvel wrote: > >> >>>>>> On 10 March 2018 at 10:45, Thiebaud Weksteen > >> > wrote: > >> >>>>>>> On Fri, Mar 9, 2018 at 5:54 PM Jeremy Cline > >> > wrote: > >> >>>>>>> > >> >>>>>>>> On Fri, Mar 09, 2018 at 10:43:50AM +0000, Thiebaud Weksteen > > wrote: > >> >>>>>>>>> Thanks a lot for trying out the patch! > >> >>>>>>>>> > >> >>>>>>>>> Please don't modify your install at this stage, I think we are > >> > hitting a > >> >>>>>>>>> firmware bug and that would be awesome if we can fix how we are > >> >>>>>>> handling it. > >> >>>>>>>>> So, if we reach that stage in the function it could either be > >> > that: > >> >>>>>>>>> * The allocation did not succeed, somehow, but the firmware > > still > >> >>>>>>> returned > >> >>>>>>>>> EFI_SUCCEED. > >> >>>>>>>>> * The size requested is incorrect (I'm thinking something like a > >> > 1G of > >> >>>>>>>>> log). This would be due to either a miscalculation of log_size > >> >>>>>>> (possible) > >> >>>>>>>>> or; the returned values of GetEventLog are not correct. > >> >>>>>>>>> I'm sending a patch to add checks for these. Could you please > >> > apply and > >> >>>>>>>>> retest? > >> >>>>>>>>> Again, thanks for helping debugging this. > >> >>>>>>> > >> >>>>>>>> No problem, thanks for the help :) > >> >>>>>>> > >> >>>>>>>> With the new patch: > >> >>>>>>> > >> >>>>>>>> Locating the TCG2Protocol > >> >>>>>>>> Calling GetEventLog on TCG2Protocol > >> >>>>>>>> Log returned > >> >>>>>>>> log_location is not empty > >> >>>>>>>> log_size != 0 > >> >>>>>>>> log_size < 1M > >> >>>>>>>> Allocating memory for storing the logs > >> >>>>>>>> Returned from memory allocation > >> >>>>>>>> Copying log to new location > >> >>>>>>> > >> >>>>>>>> And then it hangs. I added a couple more print statements: > >> >>>>>>> > >> >>>>>>>> diff --git a/drivers/firmware/efi/libstub/tpm.c > >> >>>>>>> b/drivers/firmware/efi/libstub/tpm.c > >> >>>>>>>> index ee3fac109078..1ab5638bc50e 100644 > >> >>>>>>>> --- a/drivers/firmware/efi/libstub/tpm.c > >> >>>>>>>> +++ b/drivers/firmware/efi/libstub/tpm.c > >> >>>>>>>> @@ -148,8 +148,11 @@ void > >> >>>>>>> efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg) > >> >>>>>>>> efi_printk(sys_table_arg, "Copying log to new > >> > location\n"); > >> >>>>>>> > >> >>>>>>>> memset(log_tbl, 0, sizeof(*log_tbl) + log_size); > >> >>>>>>>> + efi_printk(sys_table_arg, "Successfully memset log_tbl to > >> > 0\n"); > >> >>>>>>>> log_tbl->size = log_size; > >> >>>>>>>> + efi_printk(sys_table_arg, "Set log_tbl->size\n"); > >> >>>>>>>> log_tbl->version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2; > >> >>>>>>>> + efi_printk(sys_table_arg, "Set log_tbl-version\n"); > >> >>>>>>>> memcpy(log_tbl->log, (void *) first_entry_addr, > > log_size); > >> >>>>>>> > >> >>>>>>>> efi_printk(sys_table_arg, "Installing the log into the > >> >>>>>>> configuration table\n"); > >> >>>>>>> > >> >>>>>>>> and it's hanging at "memset(log_tbl, 0, sizeof(*log_tbl) + > >> > log_size);" > >> >>>>>>> > >> >>>>>>> Thanks. Well, it looks like the memory that is supposedly > > allocated > >> > is not > >> >>>>>>> usable. I'm thinking this is a firmware bug. > >> >>>>>>> Ard, would you agree on this assumption? Thoughts on how to > > proceed? > >> >>>>>>> > >> >>>>>> > >> >>>>>> I am rather puzzled why the allocate_pool() should succeed and the > >> >>>>>> subsequent memset() should fail. This does not look like an issue > >> > that > >> >>>>>> is intimately related to TPM2 support, rather an issue in the > >> > firmware > >> >>>>>> that happens to get tickled after the change. > >> >>>>>> > >> >>>>>> Would you mind trying replacing EFI_LOADER_DATA with > >> >>>>>> EFI_BOOT_SERVICES_DATA in the allocate_pool() call? > >> >>>>> > >> >>>>> Replacing EFI_LOADER_DATA with EFI_BOOT_SERVICES_DATA still hangs at > >> > the > >> >>>>> memset() call. > >> >>>>> > >> >>>> > >> >>>> Could you try the following please? (attached as well in case gmail > >> > mangles it) > >> >>>> > >> >>>> diff --git a/drivers/firmware/efi/libstub/tpm.c > >> >>>> b/drivers/firmware/efi/libstub/tpm.c > >> >>>> index 2298560cea72..30d960a344b7 100644 > >> >>>> --- a/drivers/firmware/efi/libstub/tpm.c > >> >>>> +++ b/drivers/firmware/efi/libstub/tpm.c > >> >>>> @@ -70,6 +70,8 @@ void > >> >>>> efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg) > >> >>>> size_t log_size, last_entry_size; > >> >>>> efi_bool_t truncated; > >> >>>> void *tcg2_protocol; > >> >>>> + unsigned long num_pages; > >> >>>> + efi_physical_addr_t log_tbl_alloc; > >> >>>> > >> >>>> status = efi_call_early(locate_protocol, &tcg2_guid, NULL, > >> >>>> &tcg2_protocol); > >> >>>> @@ -104,9 +106,12 @@ void > >> >>>> efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg) > >> >>>> } > >> >>>> > >> >>>> /* Allocate space for the logs and copy them. */ > >> >>>> - status = efi_call_early(allocate_pool, EFI_LOADER_DATA, > >> >>>> - sizeof(*log_tbl) + log_size, > >> >>>> - (void **) &log_tbl); > >> >>>> + num_pages = DIV_ROUND_UP(sizeof(*log_tbl) + log_size, > >> > EFI_PAGE_SIZE); > >> >>>> + status = efi_call_early(allocate_pages, > >> >>>> + EFI_ALLOCATE_ANY_PAGES, > >> >>>> + EFI_LOADER_DATA, > >> >>>> + num_pages, > >> >>>> + &log_tbl_alloc); > >> >>>> > >> >>>> if (status != EFI_SUCCESS) { > >> >>>> efi_printk(sys_table_arg, > >> >>>> @@ -114,6 +119,7 @@ void > >> >>>> efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg) > >> >>>> return; > >> >>>> } > >> >>>> > >> >>>> + log_tbl = (struct linux_efi_tpm_eventlog *)(unsigned > >> > long)log_tbl_alloc; > >> >>>> 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; > >> >>>> @@ -126,7 +132,7 @@ void > >> >>>> efi_retrieve_tpm2_eventlog_1_2(efi_system_table_t *sys_table_arg) > >> >>>> return; > >> >>>> > >> >>>> err_free: > >> >>>> - efi_call_early(free_pool, log_tbl); > >> >>>> + efi_call_early(free_pages, log_tbl_alloc, num_pages); > >> >>>> } > >> >>>> > >> >>>> void efi_retrieve_tpm2_eventlog(efi_system_table_t *sys_table_arg) > >> >>>> > >> >>> > >> >>> Hi Ard, > >> >>> > >> >>> When I apply this, it starts hanging at > >> >>> > >> >>> 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); > >> >>> > >> >>> rather than at the memset() call. > >> >>> > >> > > >> >> That is *very* surprising, given that the change only affects code > >> >> that executes after that. > >> > > > > > Hans, you said you configured the tablet to use the 32-bit version of grub > > instead > > of 64. Why's that? > > > > Jeremy, could you confirm if you are building the kernel in 64bit mode? Is > > your Android install working? (that is, what happens if you boot Boot0000)? > > > >> >> I understand how annoying this is for you, and I think we should try > >> >> to fix this, but reverting the patches outright isn't the solution > >> >> either. > >> > > >> >> Which UEFI vendor and version does your system report? > >> > > >> > You should be able to find this info using the "ver" command in the UEFI > >> > shell. > >> > The UEFI vendor is Insyde (see first message). > >> > > > > >> Ah, thanks! > > > >> EFI Specification Revision : 2.40 > >> EFI Vendor : INSYDE Corp. > >> EFI Revision : 21573.83 > > > Thiebaud, > If we don't manage to resolve this, do you see any way to blacklist > systems based on this information? Would it be reasonable, say, to > require UEFI v2.5 or later for TPM2 support? Or doesn't that make any > sense (I am aware that the TCG EFI spec and the UEFI spec are somewhat > orthogonal, but it also depends on the hardware you are targetting, I > guess). Otherwise, we could use a more specific match, perhaps? I understand we are getting late in the rc and that this should be resolved quickly. As we have seen, this is a bug related to the firmware more than the TPM version. So filtering out on the UEFI version make sense. If it is too late and our only option, I'm ok with filtering out on >= 2.5. A more specific match would target the exact EFI revision, right? If so, yes that would be better but I'm not sure how this can be implemented. > This is of course depending on whether we reach consensus on whether > we should make any changes at all for what appears to be a single > sample of a certain piece of hardware, where other samples running the > same firmware (right?) are working fine. Right, this is my understanding as well.