Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp19217ybt; Tue, 30 Jun 2020 13:56:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXRE1dZSbt+NXtTrprL+WFMfAmI7I+VpyeYgryU1wMkjo1Tl25T2FO42kk/BaNFwNQIurr X-Received: by 2002:a17:907:1059:: with SMTP id oy25mr21207798ejb.90.1593550140454; Tue, 30 Jun 2020 13:49:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593550140; cv=none; d=google.com; s=arc-20160816; b=HFKGlulT7pHlCh+cce2BmEXjc7MIyEVRYn5pRRWj4NPw21LYhHWo4Yp1zO+9U5YklK fCh/I6ATtVKvWpo1TLqBiWTz9vEB5a1hSnxoaSgkKeMRdZi4Pq8cDSLMjrE3Ffj3LEVY H+vbXnfScqTMk3pA4YPez9gZGw0b6JpQEkSPm/QznvwXZjAY9cXqzd59ZDxTyUqdwqsJ 0eODGu7FNfi/3omh71jpUiAFUjJlvkaqBVo30cE8tG1rqtPTJZja36vEhaIpzB3m5rmY ZU9DVhlCCgSAiiobYkGPAkhDfOyAMPx5VLYAzn2BSnGub/P50SPd6Y6vWkZ4H0spa8Ko 6f6Q== 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=dWsiMCNYKI2SdyUsKebdSBXPw/X6He/OCbjzIK4n/n8=; b=JRmJUh0nMQQ1zmtzszGd874jG/oxOLARfNPX6Y/xcGGcsG6CcrcwZSjN1Mt1tOKz+w NTMNefRtrKX//P8ho9IbiGLnS+rc5Fd1E8Mgh/C0aI6kPBB4zQH1Ko7PvDsqAW+jW1Tn iPqvaynJEntg60++1alTsQSTmBPoCduZ2fwUkHWlh8YN9UtjhZMJ/n1ti3U89MhP4pWf 29yuQgeaWEuoCOIj4AYdxohT/tY0fY9bFYofd7OSmU089RiwXptd7JHhD2jRkrtdTdyV LgZ48avaOxYWI80y0Aixx/RIK8LJyCLe9H/hzYivY4OWigcpQM+W1/Yyayo9dUA3dqtH a4Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ydWGPy5P; 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 g12si2436292edv.266.2020.06.30.13.48.37; Tue, 30 Jun 2020 13:49:00 -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=ydWGPy5P; 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 S1726371AbgF3TKZ (ORCPT + 99 others); Tue, 30 Jun 2020 15:10:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:57008 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726347AbgF3TKY (ORCPT ); Tue, 30 Jun 2020 15:10:24 -0400 Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (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 82CF4206A1; Tue, 30 Jun 2020 19:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593544223; bh=bvlrBIfobkJqYUwxFksgp5a8Mp33hFTvnGQJoruLeuY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ydWGPy5P0M/MOtzOb7cUumHcgEcBKEz3HcrctoB7EZjLFRYWjETnvQegJG24Fg8zO xdATpa8ivXsc6/01zIHIA/AoOIV2O+3HuDASjsb0d3HqK5nNymjAeV/55d0zIGRmBR vKzo0Veies9WvUU+irZ5vR96h9P95/xMpmqmR+oQ= Received: by mail-ot1-f52.google.com with SMTP id t18so6510720otq.5; Tue, 30 Jun 2020 12:10:23 -0700 (PDT) X-Gm-Message-State: AOAM530xR4yAenqF71g56/6apwLmanOn1fvEmNcQQsOvPM+50Cx0My/k KlxUIXiA5sxaAwv3kDgkbwzt52xQwEuYzFbkTI8= X-Received: by 2002:a9d:4a8f:: with SMTP id i15mr20375352otf.77.1593544222958; Tue, 30 Jun 2020 12:10:22 -0700 (PDT) MIME-Version: 1.0 References: <20200615232504.1848159-1-tyhicks@linux.microsoft.com> <20200630185327.pasrylg7og7rlno3@redhat.com> In-Reply-To: <20200630185327.pasrylg7og7rlno3@redhat.com> From: Ard Biesheuvel Date: Tue, 30 Jun 2020 21:10:11 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] tpm: Require that all digests are present in TCG_PCR_EVENT2 structures To: Peter Jones Cc: Tyler Hicks , Matthew Garrett , 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 On Tue, 30 Jun 2020 at 20:53, Peter Jones wrote: > > On Tue, Jun 16, 2020 at 11:08:38AM +0200, Ard Biesheuvel wrote: > > (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? > > Seems like in that case our measurement is unreliable and can't really > be trusted. That said, having things that were using the measurements > before this suddenly stop being able to access sealed secrets is not a > great experience for the user who unwittingly bought the junk hardware. > Same with the zero-supported-hashes case. It would be nice to at log it > and have a way for them to opt-in to allowing the old measurement to go > through, so they can recover their data, though I don't know what that > method would be if the measured command line is one of their > dependencies. > Maybe use a EFI variable?