Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2294126ybt; Tue, 16 Jun 2020 02:11:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+OaHHezJhIYZwFsFpAWdl5Sjt8ANlmudpHjtox0BUvVSAJR5DxxRr13JLEM0rBLLZkdNq X-Received: by 2002:a05:6402:128b:: with SMTP id w11mr1551453edv.377.1592298701568; Tue, 16 Jun 2020 02:11:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592298701; cv=none; d=google.com; s=arc-20160816; b=vEb/Wz15Gr7gEQJQ/smUzwj7q1UEjIikaVIvdAc5sVBlR8i7A5nSVlPTPT4GduLA3l CSdtDOv0UoUWMGWzU7lzw3o/x3CmxfzNsUMFWLpzRTGyn740GHDql8PcXFutvh8E4QdF RfkPom+M7pddsok996kORyJB/MDGOTAuuxcNMnhygoBhpciEZfIexRBlnOVDZ0IJJuTa CnQKtXrpDE5bYdMuOOGKMQz/jEafQUJiy9CZwCW7A2HMMsc9MEbTncl0/78ECQc3vNo8 ef/0T4xi+qncCLtrTIrniHxcGgwQ3Ha/2HxXFeLDjuJ283FwctVW0Rpep39flg6VbzAA 5v5Q== 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; bh=xVmLmYeCz8DguouYz2WpRtqNT5frZUN5IMD5m+asG4E=; b=jD+mENqW11f8pbCDmTr6Yp3NLnoZxI9JzDk3cGomyu1zngjy1LLVxsCAk77Rt2laUo xxl0++elwFaVs2c5tL2H8uYG571Cg3uhest3jZfpzwH1q82Sp+npsWC5PhMkZzJRcaox yfNghuP5st3fnlHMAmewK+QRMl26HrpMpVPtqkgx1o8stzSRSSkdHU063xhTAb3tgZQE qC/r5BZZZY5JVf0q/9Y5KGjQGrzwhHsmi3U7ULxXBzbZjRttwR8XaxA4ijTfXt1YuIFL MybF6XSo3iM6XVO13fC1FrO/syLQbGg6J9KfPyVltIzcWbWLLuD7/1cOajMpj+q2VLZh E2fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QAbJhmj3; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr12si13660530ejc.352.2020.06.16.02.11.18; Tue, 16 Jun 2020 02:11:41 -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=@kernel.org header.s=default header.b=QAbJhmj3; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727987AbgFPJIv (ORCPT + 99 others); Tue, 16 Jun 2020 05:08:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:40766 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727804AbgFPJIu (ORCPT ); Tue, 16 Jun 2020 05:08:50 -0400 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C272A207DD; Tue, 16 Jun 2020 09:08:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592298529; bh=mMcZbBKDIEf5QDbJvhcjb8NySIKsPG7Fhgc8LiSbKCo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=QAbJhmj34S2Fh7X92lHNNV0g9TgINhpbE+Xi01XOpZGNnKr1JQOzc8zJFa/Q/IWIE KUXLzFRoNnTDPXxxfw5nMVDVRRo5OGfYUCr1Uu+PHiRMjg+ihC/RhWsE2s9n/dd3g0 4HFqrjPh5o76I0Mk0irL6v+qQWIW1zQYLLpbow1A= Received: by mail-oi1-f176.google.com with SMTP id a137so18611837oii.3; Tue, 16 Jun 2020 02:08:49 -0700 (PDT) X-Gm-Message-State: AOAM532iBcwy8DQnU/c6AeEDsaRJC0okNSv1M7hOKPjTmTBuLeg5FPR0 tulR5SBG+4hKCDmeyhe9hKWIAUAr0/AYstUiE8M= X-Received: by 2002:aca:ba03:: with SMTP id k3mr2525490oif.33.1592298529095; Tue, 16 Jun 2020 02:08:49 -0700 (PDT) MIME-Version: 1.0 References: <20200615232504.1848159-1-tyhicks@linux.microsoft.com> In-Reply-To: <20200615232504.1848159-1-tyhicks@linux.microsoft.com> From: Ard Biesheuvel Date: Tue, 16 Jun 2020 11:08:38 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] tpm: Require that all digests are present in TCG_PCR_EVENT2 structures To: Tyler Hicks , Matthew Garrett , Peter Jones Cc: Jarkko Sakkinen , Peter Huewe , Jason Gunthorpe , Petr Vandrovec , Nayna Jain , Thirupathaiah Annapureddy , linux-integrity , linux-efi , Linux Kernel Mailing List 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 (cc Matthew and Peter) On Tue, 16 Jun 2020 at 01:28, Tyler Hicks wrote: > > 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. > When does this happen? Do we have code in mainline that does this? > 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 > --- I am all for stringent checks, but this could potentially break measured boot on systems that are working fine today, right? > 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 >