Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1805974ybn; Thu, 26 Sep 2019 02:29:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcY5949qvmX+0DGJBCoGlXOJgmQAEpAOModvFSLaoEV7zVdc82Yl/PJ3a2zS3D1pJwxkLm X-Received: by 2002:a50:a41c:: with SMTP id u28mr2428559edb.185.1569490142217; Thu, 26 Sep 2019 02:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569490142; cv=none; d=google.com; s=arc-20160816; b=ZNubnPg5OCCgSUynsdQMdZxzPewyDpWHZ5Zg8sL/37qZc3z+2UTSF/Ekyhj0wEXEB/ LOSwiIlPFYUOoo7ISGFplP+bbIk4ZTvlYCdN6hrdbuCfIDxMN0/KapALVyrcrVqYAi/G 2gs/93ZnsVpOJWfVWF7gA0kptc0HbIW4qzNr2JWwhe8wqcdk6X4kke1PRdFjzT64VRhE ii7cxw3fZlA88WmJp1aD2LGDRZs0eZC1JLESOr6N+bJD82jIQlmTXK99PvnPnFnX7M5F e5VO4nYIYUI7ynmeXN44sxbEmhj5K2lwoqHY9YH90rJSJN6Mb3/KPL1y6ps/Sr6m9rvp JfXQ== 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=0FY3OMeSE7sfB8tjcag0vvwYNbmwB8seiwupv5JuR04=; b=S3n52Aquzpc1t1zna4/O+XNQb8rWk3B0rotwGxYf7MsMS5nbO5un/HAuMsRS6cH/j/ MgFHzrduqiB8B3TH7xNVALxz8/pCPZu8NaPkplDO7hv3RWdmNabGw+mKf667REh3ThHf 9n6EJS6M7Hzx4uh+rHMc2BC5mu1qjCUcCIKia7PAAzR325qByN8eSk6YMLtFsfNxZtqK zU0aH33zkcfFxDM8v8VHmANAe8DArRyw+prxYVFLcwqiYs1I7Ak7LbsRPSnCdyid2xUa QUxG3PYnaevhF37tc/GKvDZ9UgUenOVUhyJU6Q93SMTs0/DsRzCGMHuhMwY7Xlha4UtU dhug== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dv21si673066ejb.241.2019.09.26.02.28.38; Thu, 26 Sep 2019 02:29:02 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389107AbfIYKQf (ORCPT + 99 others); Wed, 25 Sep 2019 06:16:35 -0400 Received: from mga06.intel.com ([134.134.136.31]:40402 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727141AbfIYKQe (ORCPT ); Wed, 25 Sep 2019 06:16:34 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2019 03:16:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,547,1559545200"; d="scan'208";a="193723106" Received: from dariusvo-mobl.ger.corp.intel.com (HELO localhost) ([10.249.39.150]) by orsmga006.jf.intel.com with ESMTP; 25 Sep 2019 03:16:27 -0700 From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: Peter Jones , linux-efi@vger.kernel.org, stable@vger.kernel.org, Lyude Paul , Jarkko Sakkinen , Matthew Garrett , Ard Biesheuvel , Roberto Sassu , Bartosz Szczepanek , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 1/2] efi+tpm: Don't access event->count when it isn't mapped. Date: Wed, 25 Sep 2019 13:16:18 +0300 Message-Id: <20190925101622.31457-1-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Jones 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. Fixes: 44038bc514a2 ("tpm: Abstract crypto agile event size calculations") Cc: linux-efi@vger.kernel.org Cc: linux-integrity@vger.kernel.org Cc: stable@vger.kernel.org Signed-off-by: Peter Jones Tested-by: Lyude Paul Reviewed-by: Jarkko Sakkinen Acked-by: Matthew Garrett Acked-by: Ard Biesheuvel Signed-off-by: Jarkko Sakkinen --- 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 63238c84dc0b..12584b69a3f3 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 = READ_ONCE(event->count); + event_type = READ_ONCE(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.20.1