Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4319960ybl; Mon, 26 Aug 2019 08:42:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyAgR1Y70MIvdUSJgfyNkEQnRMbRPV++so6AnwMXdAicAyynZ7mGm0DpGsOL00VVveuYqYf X-Received: by 2002:a17:902:7c0b:: with SMTP id x11mr18438107pll.73.1566834145020; Mon, 26 Aug 2019 08:42:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566834145; cv=none; d=google.com; s=arc-20160816; b=SblqN99QFIxar+D11ysWKEEIufnJotHzWng7ugZc7QCTwLDSsL2cde6RaPWezWvTXW 8OJCjbCu8OHs2fivMJ41r8WZMJnJjFs1U5mYhWhbuaueKorlT2yH6MComowQDxioeiwz bPL+BmuvS+k2nuZrdlXB2587cC1lOSmXIvP5Ryqqp6I2kiON0FbRY6Z4ggiioYzZ3V4Z CoSvYmapKmdsORT72hFtYwsvzH0mv+k6Od5edCqtE6iJRz+PfiNdhD28vNMDTj+I/jtT a+cRjzNs6+8HZ+62gzzuApKshEt3ydNM9gt52wAjpF6FkFY71wHQym/Pinu4CWPwhN5c tIig== 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 :message-id:date:subject:cc:to:from; bh=wqb88Aii4pGYf3uWORb1tXmo7Mbg5Sbh/M0v+Bz3S3k=; b=ngvxONeBlIHbTaRA7q/1K50I/E0Js77o5K8SKLOerdBHtvjTYFtownMxfPH9GsOZub 0tGmV6APZWZI55C1srKQXHDLI4oDAyWGf7pBu3bAOTDkNv8ianxXMqcucsr3k3YMWfVz MOTlalPMx3Br2M232//cbbl8ZJbcjcSnSDm00Ccqb4BLgjGJCHBgMRo1opWS2kr0sQIl fB6DX/RYOicQUjD8UneJw5Tierd4L12X7HGMx+OxKCvRfjrYZwx3tzGfrr9trtZSEPm3 PGJ4RxvQvjPrcnDBYlpEVlUoVrz6MyikmeU6ZmpWzvADFtc3vi4iJDzS5jlCBZTKKE0h kCkQ== 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 w9si9943176plz.346.2019.08.26.08.42.10; Mon, 26 Aug 2019 08:42:25 -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 S1732405AbfHZPai (ORCPT + 99 others); Mon, 26 Aug 2019 11:30:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43112 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728965AbfHZPai (ORCPT ); Mon, 26 Aug 2019 11:30:38 -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 EF6573082131; Mon, 26 Aug 2019 15:30:37 +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 1C6AE1001E85; Mon, 26 Aug 2019 15:30:37 +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 1/2] efi+tpm: Don't access event->count when it isn't mapped. Date: Mon, 26 Aug 2019 11:30:27 -0400 Message-Id: <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.42]); Mon, 26 Aug 2019 15:30:38 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some machines generate a lot of event log entries. When we're iterating over them, the code removes the old mapping and adds a new one, so once we cross the page boundary we're unmapping the page with the count on it. Hilarity ensues. This patch keeps the info from the header in local variables so we don't need to access that page again or keep track of if it's mapped. Signed-off-by: Peter Jones Tested-by: Lyude Paul --- include/linux/tpm_eventlog.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/linux/tpm_eventlog.h b/include/linux/tpm_eventlog.h index 63238c84dc0..549dab0b56b 100644 --- a/include/linux/tpm_eventlog.h +++ b/include/linux/tpm_eventlog.h @@ -170,6 +170,7 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event, u16 halg; int i; int j; + u32 count, event_type; marker = event; marker_start = marker; @@ -190,16 +191,22 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event, } event = (struct tcg_pcr_event2_head *)mapping; + /* + * the loop below will unmap these fields if the log is larger than + * one page, so save them here for reference. + */ + count = event->count; + event_type = event->event_type; efispecid = (struct tcg_efi_specid_event_head *)event_header->event; /* Check if event is malformed. */ - if (event->count > efispecid->num_algs) { + if (count > efispecid->num_algs) { size = 0; goto out; } - for (i = 0; i < event->count; i++) { + for (i = 0; i < count; i++) { halg_size = sizeof(event->digests[i].alg_id); /* Map the digest's algorithm identifier */ @@ -256,8 +263,9 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event, + event_field->event_size; size = marker - marker_start; - if ((event->event_type == 0) && (event_field->event_size == 0)) + if (event_type == 0 && event_field->event_size == 0) size = 0; + out: if (do_mapping) TPM_MEMUNMAP(mapping, mapping_size); -- 2.23.0.rc2