Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4321302ybl; Mon, 26 Aug 2019 08:43:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqy99arrlC6/mkCWMNsQsRD75n2fOuHGC087u0GdE6DXsHlSGJapYyrC0ylLW5BnonVRjbSQ X-Received: by 2002:a65:6850:: with SMTP id q16mr17398588pgt.423.1566834221591; Mon, 26 Aug 2019 08:43:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566834221; cv=none; d=google.com; s=arc-20160816; b=GuVM/PEm/gt6ybJTkn404bCJnhjAAT/eLMKZQLOCWkECSBBffielnlv6OugLYniq2Q saLF+2JQIFmCB2bYpT3dwJaHkohLyeeh8Lj2Im7VlFFqhaQa5EUUJqf+dzhn4gruo6aj fo4sZ/yW1bHWebFhNgbo+4WQavUgheiuKEdXpRTrdJxl8TkZ2HJLcs6d+/nlhEm7hGV6 CTHhIk7Sb55BLqOgaf5BzJ6+kVAYObkQtfK5tkuDBBbLLUKzLbr8qhEs9taj+3dEvVH+ DofkEbYF6jgqVGQ7Vk/eXHgiI+qqoHJkDJTq3dyLSKQZpXnlSD4qICIR2sBVFIJ71d9+ Bmgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ukiolgt0PXxYxWyVYsYHFGzKfl5kaEuz9kdb5EI7Iw8=; b=iWluW8Mxwc7YT3t/C/nFkQswF8moFA2pwF+nQH2J8a/uDiwYlQHS2pSHfUjeqt+a+m XVfrHF1zW6saeH9hJgRI7PU7VKmk677skBoTC7wsQPcjWWz49wk3UNbvS476uIhQjJbL ewB1wFDUylDSJGNlnPRgDY63jvq0rpDVjMUNmlAjVZUK4l1TS6WRfVISUADiun/X88UO eJQR7OEB0YC7pKna4diA5Ug/p411eQYKYr97hl8eE/3rohqDaScANqEcPNxjcMIT7BSO mVDGvQMsZNqNadLRZ4S4e2/x6i5PTSmqC7NjzIE97njDFwAAA6iRrvlpEblwXisSU11J ExAQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b41si9963544pla.155.2019.08.26.08.43.26; Mon, 26 Aug 2019 08:43:41 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732465AbfHZPan (ORCPT + 99 others); Mon, 26 Aug 2019 11:30:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36392 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729335AbfHZPan (ORCPT ); Mon, 26 Aug 2019 11:30:43 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 358043C93; Mon, 26 Aug 2019 15:30:43 +0000 (UTC) Received: from trillian.uncooperative.org.com (dhcp-10-20-1-91.bss.redhat.com [10.20.1.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5147A100EBDA; Mon, 26 Aug 2019 15:30:42 +0000 (UTC) From: Peter Jones To: Ard Biesheuvel Cc: Jarkko Sakkinen , Roberto Sassu , Matthew Garrett , Bartosz Szczepanek , Lyude Paul , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Jones Subject: [PATCH 2/2] efi+tpm: don't traverse an event log with no events Date: Mon, 26 Aug 2019 11:30:28 -0400 Message-Id: <20190826153028.32639-2-pjones@redhat.com> In-Reply-To: <20190826153028.32639-1-pjones@redhat.com> References: <20190826153028.32639-1-pjones@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 26 Aug 2019 15:30:43 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When there are no entries to put into the final event log, some machines will return the template they would have populated anyway. In this case the nr_events field is 0, but the rest of the log is just garbage. This patch stops us from trying to iterate the table with __calc_tpm2_event_size() when the number of events in the table is 0. Signed-off-by: Peter Jones Tested-by: Lyude Paul --- drivers/firmware/efi/tpm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c index 1d3f5ca3eaa..be51ed17c6e 100644 --- a/drivers/firmware/efi/tpm.c +++ b/drivers/firmware/efi/tpm.c @@ -75,11 +75,15 @@ int __init efi_tpm_eventlog_init(void) goto out; } - tbl_size = tpm2_calc_event_log_size((void *)efi.tpm_final_log - + sizeof(final_tbl->version) - + sizeof(final_tbl->nr_events), - final_tbl->nr_events, - log_tbl->log); + tbl_size = 0; + if (final_tbl->nr_events != 0) { + void *events = (void *)efi.tpm_final_log + + sizeof(final_tbl->version) + + sizeof(final_tbl->nr_events); + tbl_size = tpm2_calc_event_log_size(events, + final_tbl->nr_events, + log_tbl->log); + } memblock_reserve((unsigned long)final_tbl, tbl_size + sizeof(*final_tbl)); early_memunmap(final_tbl, sizeof(*final_tbl)); -- 2.23.0.rc2