Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2033734ybt; Mon, 15 Jun 2020 16:30:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoLISQs7H6Tt0ThUJTJDMcbaRAPuxdlKoDajpsBgQvpA/PVMUFBwUAxvCt5GzOHIyLTQnN X-Received: by 2002:aa7:cdda:: with SMTP id h26mr134166edw.327.1592263816917; Mon, 15 Jun 2020 16:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592263816; cv=none; d=google.com; s=arc-20160816; b=oeaUixfUjWHuaFJ/ETtLWn5dZK/dE2942tyvE7zw/IeXA9YL3w1dOLq63LZh5lgKrm ao2YbvzrUKnHs8Qt1pHIKOKEBf6MdFyr8ifZJ1UKO570UM6Ty6JLca89cewy5JwP1c6n 9HueRIMrQG7l6IVf+M6mOQHMeSbC5BkRhBgy2Rx1nhL6Onnnx8y7kzsJMyZ0bHeXspWl zjhMDcyqoaBnAlimOlNOVYVEZB8WGw1lk+qi+jV51wHYbyxwqdhu2tHQ7Y8wu1AG9vOC eF2lnhX4NtJcGGvZ6Zj5whbLOAgg1vNnaTBaDt9mubMLdFnJChXPSXqxwkAOPv3foZ4R PtEQ== 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:dkim-signature:dkim-filter; bh=24da9vv8AG04i92vfIYdv7Ik8ZBjVgmLxlUf5hhLH44=; b=cHYwc2JmHYmUkb5WD11+3O1scOZ93mwOce6uyeGWsoJoyvYtXwQg1fmCVnn4Ca5NtT DEhfNE4evHuvu0+J4cJZuXYpi8Eg2iYsylkdH3xpWrbj/lwG9ZxbFFC2ZQCb7/UrMOHa uTb3ZtmBjtkl96haPn1pmVcezBjKh6rfwcfQaV+RrmzAKAw2oX2DlKOcZxFFw9HmWPgC +Eax6QRNnYq8nZxDg9SPWafZr0irpqHxVTtiD7beqrBLGoyvs1Dos34w/RCujtX96oSm ZSHDLfVdyUdJ3Huf0Femt9gcm8KFqgii54HFyR8hz0APbtXawsogRqjvGchKaEeb8GOx 3ZJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=HjclWTng; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jp20si10250081ejb.307.2020.06.15.16.29.54; Mon, 15 Jun 2020 16:30:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=HjclWTng; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726673AbgFOX2J (ORCPT + 99 others); Mon, 15 Jun 2020 19:28:09 -0400 Received: from linux.microsoft.com ([13.77.154.182]:45588 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725960AbgFOX2J (ORCPT ); Mon, 15 Jun 2020 19:28:09 -0400 Received: from sequoia.work.tihix.com (162-237-133-238.lightspeed.rcsntx.sbcglobal.net [162.237.133.238]) by linux.microsoft.com (Postfix) with ESMTPSA id 657B920B4780; Mon, 15 Jun 2020 16:28:07 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 657B920B4780 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1592263688; bh=24da9vv8AG04i92vfIYdv7Ik8ZBjVgmLxlUf5hhLH44=; h=From:To:Cc:Subject:Date:From; b=HjclWTngt51xsAal4zzyK0uAtUedBu2Y7q/XWrKVuhbLSJpCqw2ExCH4kxcbRu1vB yhsc7vwUXpblnhoxrZPvfUb5+brRVxSvwxZLh5+XAOgbcnwms1xrZL4a9VQJaCQIcB uDPfW+rzO5f5KFUPMJ93ceQ3foH3VSXtI/YOjNSM= From: Tyler Hicks To: Jarkko Sakkinen , Peter Huewe , Ard Biesheuvel Cc: Jason Gunthorpe , Petr Vandrovec , Nayna Jain , Thirupathaiah Annapureddy , linux-integrity@vger.kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] tpm: Require that all digests are present in TCG_PCR_EVENT2 structures Date: Mon, 15 Jun 2020 18:25:04 -0500 Message-Id: <20200615232504.1848159-1-tyhicks@linux.microsoft.com> X-Mailer: git-send-email 2.25.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 Require that the TCG_PCR_EVENT2.digests.count value strictly matches the value of TCG_EfiSpecIdEvent.numberOfAlgorithms in the event field of the TCG_PCClientPCREvent event log header. Also require that TCG_EfiSpecIdEvent.numberOfAlgorithms is non-zero. The TCG PC Client Platform Firmware Profile Specification section 9.1 (Family "2.0", Level 00 Revision 1.04) states: For each Hash algorithm enumerated in the TCG_PCClientPCREvent entry, there SHALL be a corresponding digest in all TCG_PCR_EVENT2 structures. Note: This includes EV_NO_ACTION events which do not extend the PCR. Section 9.4.5.1 provides this description of TCG_EfiSpecIdEvent.numberOfAlgorithms: The number of Hash algorithms in the digestSizes field. This field MUST be set to a value of 0x01 or greater. Enforce these restrictions, as required by the above specification, in order to better identify and ignore invalid sequences of bytes at the end of an otherwise valid TPM2 event log. Firmware doesn't always have the means necessary to inform the kernel of the actual event log size so the kernel's event log parsing code should be stringent when parsing the event log for resiliency against firmware bugs. This is true, for example, when firmware passes the event log to the kernel via a reserved memory region described in device tree. Prior to this patch, a single bit set in the offset corresponding to either the TCG_PCR_EVENT2.eventType or TCG_PCR_EVENT2.eventSize fields, after the last valid event log entry, could confuse the parser into thinking that an additional entry is present in the event log. This patch raises the bar on how difficult it is for stale memory to confuse the kernel's event log parser but there's still a reliance on firmware to properly initialize the remainder of the memory region reserved for the event log as the parser cannot be expected to detect a stale but otherwise properly formatted firmware event log entry. Fixes: fd5c78694f3f ("tpm: fix handling of the TPM 2.0 event logs") Signed-off-by: Tyler Hicks --- include/linux/tpm_eventlog.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/tpm_eventlog.h b/include/linux/tpm_eventlog.h index 4f8c90c93c29..d83eb9fd5614 100644 --- a/include/linux/tpm_eventlog.h +++ b/include/linux/tpm_eventlog.h @@ -201,7 +201,7 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event, efispecid = (struct tcg_efi_specid_event_head *)event_header->event; /* Check if event is malformed. */ - if (count > efispecid->num_algs) { + if (!efispecid->num_algs || count != efispecid->num_algs) { size = 0; goto out; } -- 2.25.1