Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4664439iob; Sun, 8 May 2022 21:08:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAD/fF9fvlC9eQ7hemCo2IPzDvMEJLdB94oBilfKnEQYPF8Eqj7pEghK7dlpkCJKvrc5fm X-Received: by 2002:a17:902:ce0a:b0:15d:917:fad4 with SMTP id k10-20020a170902ce0a00b0015d0917fad4mr14272084plg.3.1652069288320; Sun, 08 May 2022 21:08:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652069288; cv=none; d=google.com; s=arc-20160816; b=vVFkgM7nYq35e2jn5rFYIcVr5tI0NF3YKJaDWDZRNfOU/YpTKvcp6k8drRXiFWzaFv SMC/yT7VmKZIN+W3zM5pFzfSI4RJFqC8naJT3x9L8ISfYJVCmgtXk39OXaVksFQlLwKB XEXdBwLtGxOd7yjcTxNbcp0TzK4il7VPOA3x/+d+BTquNZeW+3jkq1BxrmUJtrRyqPEY 5dCsTKmUHtM4kD063g9sc27kzG87ADv/X3KYdGI69cfDHf/oNL9NjVjxXYK2hDNIwLFW wkAYfg4a+5RPSJH5xcu8aJ6toYNbEaws7CYupP7c/T6LrtdNczMVrLsu/7scX7sEGEnp m1lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NCPgvpZcA0uAt4aHPP7BYpOEKu3u65fsur79lcM7RCY=; b=ujmvKOU6rKld7zEEZ9aI+xTu1/v/MNIaMeUJgHb9uu7feDRSUS87pxfk5MNUQNlYJA iMRKzK2jdKnurRP10YTvHZB70entVdLeGUQg8sZM4NlIFh6D9lcKPubE0I6Dy+UQDLyR 4nFp/UVKaqssaB73QA7BsyEwXeq9B9H+ovbLdyP0tlRvUVxas7xrQS0mNR4gLU7/IV6F M05WaoYs2pxYszM/snnJR4MK7cS13wWliQ7dlhtzWAbFTYDva9sfzRdAxocikC6B6uaX uXiC15cNxDI288APQfej/ULm3nq/ox0hlJ8jmMxWdAsnhiXz9b/E6/2loUdgKM5GN/Hr v4Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Zs2UVopn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b1-20020a170903228100b0015eafbef962si11359774plh.31.2022.05.08.21.08.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 21:08:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Zs2UVopn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E6E1621E1C; Sun, 8 May 2022 21:06:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382292AbiEDXsx (ORCPT + 99 others); Wed, 4 May 2022 19:48:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383949AbiEDXZR (ORCPT ); Wed, 4 May 2022 19:25:17 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C35914EF54 for ; Wed, 4 May 2022 16:21:39 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id x18so2823786plg.6 for ; Wed, 04 May 2022 16:21:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NCPgvpZcA0uAt4aHPP7BYpOEKu3u65fsur79lcM7RCY=; b=Zs2UVopnaRBcMqzeWwdu3RMSHFGCRemyVLw1Wiq1qURH8sHjtfDVQfZbSeFcEHO3yo 3A1MC5oNYk09WmKFCtVeexkI58hzjqDiFLj3wo1aQ2A7txkNgN7GmMK0k3LRqjZKN7OW Ejffr5D3JC4siZtEiGZt/YgD+39nWwRmq2VxY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NCPgvpZcA0uAt4aHPP7BYpOEKu3u65fsur79lcM7RCY=; b=ievlUr3X4YrSs41pUDF+OmQwZBVczvM2bPpRD7dpAQ9mFcZK27oWpaxMNUtNNrNx8+ E4q7pVnTWS15ndAxidscXc3rJA3q0ksgBppdvd0qrjxYqpahlIhQtp5aQlXClKnBWol7 fxlvyu1AwzS4JffZ9xEPcEAVBjkvRT9h/D07s2lD/K8fPFBJgQcwK/BoHjKzGCyFb+fT JXB9Oi0Q856fJra1ZKW4nEzlsc690MwVQs98TeRtONBhtuPKOn87yrsWcSvgRGGTBJrE BBr3/BB3RBYNXcCnEu++Y81L9n7CvjGNYPcSpLptAjZu3TOf3eIkrtzSMmSypQSmMbEc TguA== X-Gm-Message-State: AOAM533L89UtlSsxM3i5A9baoPPOyHSYboR2NTQbAT1zefvM578MSipG hApslFb8gaCl36SqHO3dcYYdRi8JX1HxxNUz X-Received: by 2002:a17:903:2d0:b0:14d:8a8d:cb1 with SMTP id s16-20020a17090302d000b0014d8a8d0cb1mr24121633plk.50.1651706499061; Wed, 04 May 2022 16:21:39 -0700 (PDT) Received: from evgreen-glaptop.lan ([98.47.98.87]) by smtp.gmail.com with ESMTPSA id q12-20020a170902f78c00b0015e8d4eb2d6sm1901pln.288.2022.05.04.16.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 16:21:38 -0700 (PDT) From: Evan Green To: linux-kernel@vger.kernel.org Cc: Matthew Garrett , dlunev@google.com, zohar@linux.ibm.com, jejb@linux.ibm.com, linux-integrity@vger.kernel.org, corbet@lwn.net, rjw@rjwysocki.net, gwendal@chromium.org, jarkko@kernel.org, linux-pm@vger.kernel.org, Evan Green , David Howells , Hao Wu , James Morris , Matthew Garrett , "Serge E. Hallyn" , axelj , keyrings@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH 05/10] security: keys: trusted: Verify creation data Date: Wed, 4 May 2022 16:20:57 -0700 Message-Id: <20220504161439.5.I6cdb522cb5ea28fcd1e35b4cd92cbd067f99269a@changeid> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220504232102.469959-1-evgreen@chromium.org> References: <20220504232102.469959-1-evgreen@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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. Partially-sourced-from: Matthew Garrett Signed-off-by: Evan Green --- Source material for this change is at: https://patchwork.kernel.org/project/linux-pm/patch/20210220013255.1083202-9-matthewgarrett@google.com/ include/linux/tpm.h | 1 + security/keys/trusted-keys/trusted_tpm2.c | 72 ++++++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 8320cbac6f4009..438f8bc0a50582 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -224,6 +224,7 @@ enum tpm2_command_codes { TPM2_CC_SELF_TEST = 0x0143, TPM2_CC_STARTUP = 0x0144, TPM2_CC_SHUTDOWN = 0x0145, + TPM2_CC_CERTIFYCREATION = 0x014A, TPM2_CC_NV_READ = 0x014E, TPM2_CC_CREATE = 0x0153, TPM2_CC_LOAD = 0x0157, diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trusted-keys/trusted_tpm2.c index b7ddb78e644d17..6db30a5fc320c0 100644 --- a/security/keys/trusted-keys/trusted_tpm2.c +++ b/security/keys/trusted-keys/trusted_tpm2.c @@ -600,6 +600,69 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip, return rc; } +/** + * tpm2_certify_creation() - execute a TPM2_CertifyCreation command + * + * @chip: TPM chip to use + * @payload: the key data in clear and encrypted form + * @blob_handle: the loaded TPM handle of the key + * + * Return: 0 on success + * -EINVAL on tpm error status + * < 0 error from tpm_send or tpm_buf_init + */ +static int tpm2_certify_creation(struct tpm_chip *chip, + struct trusted_key_payload *payload, + u32 blob_handle) +{ + struct tpm_header *head; + struct tpm_buf buf; + int rc; + + rc = tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_CERTIFYCREATION); + if (rc) + return rc; + + /* Use TPM_RH_NULL for signHandle */ + tpm_buf_append_u32(&buf, 0x40000007); + + /* Object handle */ + tpm_buf_append_u32(&buf, blob_handle); + + /* 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); + + /* Qualifying data */ + tpm_buf_append_u16(&buf, 0); + + /* Creation data hash */ + tpm_buf_append_u16(&buf, payload->creation_hash_len); + tpm_buf_append(&buf, payload->creation_hash, + payload->creation_hash_len); + + /* 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; + + head = (struct tpm_header *)buf.data; + + if (head->return_code != 0) + rc = -EINVAL; +out: + tpm_buf_destroy(&buf); + return rc; +} + /** * tpm2_unseal_trusted() - unseal the payload of a trusted key * @@ -625,8 +688,15 @@ int tpm2_unseal_trusted(struct tpm_chip *chip, goto out; rc = tpm2_unseal_cmd(chip, payload, options, blob_handle); - tpm2_flush_context(chip, blob_handle); + if (rc) + goto flush; + + if (payload->creation_len) + rc = tpm2_certify_creation(chip, payload, blob_handle); + +flush: + tpm2_flush_context(chip, blob_handle); out: tpm_put_ops(chip); -- 2.31.0