Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4820504rwb; Sun, 13 Nov 2022 14:45:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf5KQ0lBmotUECGwGhtlisvSYrafjXjX/FCaqmIJbXxIrLcTp2LJrlMbg4LBycAuklwDWN9H X-Received: by 2002:a17:902:d583:b0:186:bb44:946d with SMTP id k3-20020a170902d58300b00186bb44946dmr11571004plh.11.1668379527323; Sun, 13 Nov 2022 14:45:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668379527; cv=none; d=google.com; s=arc-20160816; b=xoWTY/1HYe+j5w9Ry6X6pwlKg/8tSkrAZG2Jo0GRuhiJaACnYJkuxUhioV/VSUQe1f yDN3PLIEWN2PRFCmc8ixPFJWT9CEBqZTZT0o4TA05Vz1NuLeOk6dd1je9qGTcUcZwaj1 t5w/R4Ahc7orHepgvVxZ4Oog6U2+OcOjeP1lIn5ap7NF027BQOKl+tL5MgXhD6IIO002 ZIWd+BGTVvml9oBRKqafrr3VXAdHHyuzA2+dFWYtU2tnPQrDJJ27ioI/KZAcLXIQgBEO SoIBM2RnVgFAav8HGwn9pe620u6EAdVJ2eNNXpn/4qL7LEmqaaHGatIwakIdjcBxwRtB TxWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=lyt3Uy0tk6YVN2/PGuaL8QefzTR3Lo3jutDZxTmkoH0=; b=ENq5lmtGGI/amf0oYkIKDGTOFEF83I8fO6AVrBtYNB5k9/li2Trklx0AwDG2A9zQu/ J7LKOq1UnFiVM9ct/3BQRy69i/Ge1QMJnncXzgV0w+CkGad/UQ81WioLJJeuog02MjtI a5+2jsnM6HumqQoBlm8ybig+W+zGuIOTF3LfWN6CrFB795y7Is2kuMRhfjhJtJcLn7Du HdF6njczLY2nMY+xodyQPcvDzo2DVEtRjKVdE1t93Kj32t/p0qWp1eJlwjJCs6YJNvv+ Kyn/H6KFtTUqIMCuUSLo4rHcNa3LFe23AwyZO6Swgw8kBtXiQqiJNHSG62uUq0yJPvTa iY8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sa508lT3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v3-20020a170902e8c300b001870dc9ef5asi7509668plg.285.2022.11.13.14.45.16; Sun, 13 Nov 2022 14:45:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sa508lT3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235440AbiKMWN3 (ORCPT + 89 others); Sun, 13 Nov 2022 17:13:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229692AbiKMWN1 (ORCPT ); Sun, 13 Nov 2022 17:13:27 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5182993; Sun, 13 Nov 2022 14:13:23 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E075860C0A; Sun, 13 Nov 2022 22:13:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A110C433D6; Sun, 13 Nov 2022 22:13:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668377602; bh=U2ikFT6APnNMIjqmwVyd0zK7pPxr9s3HsJ5ryDClCZI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sa508lT3frr4RDqVpbXRhF0rZhhOCKgRoIwGz0c5TFPEjyqwT7RVUb7+gQ8KC3H+v hBOBKeCj0VFPv/HvwF+ASUxsDFjLJtTTzg+gr+0AultOmcMECBR8L6E/G+0Pa5g31z Pn46Lh+Z6aL9KsK8la+0fi7T6etk1d6jl18gMFVGTgNxmMt+odueFN80jh0/TxB8xW U48ZUddUVrKuq8UZyFnuHE0fBAmryLm6uiZFg0I7m6t3pDW1c5gFyLc3SR+LM04Y2P 2GUEvg44W3ZQSXjFzn4TOiM0KuAMj5JvaZEtBZSAjecTfu2CxeAKbAQPH27hr11DjZ dRfsS1NK8ERog== Date: Sun, 13 Nov 2022 14:13:19 -0800 From: Eric Biggers To: Evan Green Cc: linux-kernel@vger.kernel.org, corbet@lwn.net, linux-integrity@vger.kernel.org, gwendal@chromium.org, dianders@chromium.org, apronin@chromium.org, Pavel Machek , Ben Boeckel , rjw@rjwysocki.net, jejb@linux.ibm.com, Kees Cook , dlunev@google.com, zohar@linux.ibm.com, Matthew Garrett , jarkko@kernel.org, linux-pm@vger.kernel.org, Matthew Garrett , David Howells , James Morris , Paul Moore , "Serge E. Hallyn" , axelj , keyrings@vger.kernel.org, linux-security-module@vger.kernel.org Subject: Re: [PATCH v5 06/11] security: keys: trusted: Verify creation data Message-ID: References: <20221111231636.3748636-1-evgreen@chromium.org> <20221111151451.v5.6.I6cdb522cb5ea28fcd1e35b4cd92cbd067f99269a@changeid> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221111151451.v5.6.I6cdb522cb5ea28fcd1e35b4cd92cbd067f99269a@changeid> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 11, 2022 at 03:16:31PM -0800, Evan Green wrote: > security: keys: trusted: Verify creation data > > If a loaded key contains creation data, ask the TPM to verify that > creation data. This allows users like encrypted hibernate to know that > the loaded and parsed creation data has not been tampered with. I don't understand what the purpose of this is. I thought that the way to "seal" a key to a TPM PCR is to include the PCR in the "policy". Are you doing that too? What is the purpose of using the "creation data"? > + /* Auth */ > + tpm_buf_append_u32(&buf, 9); > + tpm_buf_append_u32(&buf, TPM2_RS_PW); > + tpm_buf_append_u16(&buf, 0); > + tpm_buf_append_u8(&buf, 0); > + tpm_buf_append_u16(&buf, 0); This is struct tpm2_null_auth_area, so this is another place that could take advantage of a new helper function to append it. > + /* Creation data hash */ > + if (payload->creation_hash_len < 2) { > + rc = -EINVAL; > + goto out; > + } > + > + tpm_buf_append_u16(&buf, payload->creation_hash_len - 2); > + tpm_buf_append(&buf, payload->creation_hash + 2, > + payload->creation_hash_len - 2); So the first two bytes of creation_hash are a redundant length field that needs to be ignored here? Perhaps tpm2_key_encode() shouldn't include that redundant length field? > + > + /* signature scheme */ > + tpm_buf_append_u16(&buf, TPM_ALG_NULL); > + > + /* creation ticket */ > + tpm_buf_append(&buf, payload->tk, payload->tk_len); > + > + rc = tpm_transmit_cmd(chip, &buf, 6, "certifying creation data"); > + if (rc) > + goto out; This is another instance of the bug where a positive TPM2_RC_* code is being returned from a function that is supposed to return a negative errno value. - Eric