Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2833888lqo; Mon, 20 May 2024 20:18:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKaMcTuCJcWQ62PC1tixnUWghES0S+9VfZYgHq2np8tnt5f1gS9J53WC72atjBzyKj3G6aAGPvbM/SLa1QKAtfcIXw7B6MzAEA4o/N1Q== X-Google-Smtp-Source: AGHT+IGkLGkhMEU9xe/cvSDQjAWlTJepvSfv+BdLdYY1dQDAB7gYxAV+mVqBVI479Ds2ZJxjOZ5I X-Received: by 2002:a05:622a:448:b0:43e:2256:7b7d with SMTP id d75a77b69052e-43e22567e5bmr252370261cf.45.1716261499259; Mon, 20 May 2024 20:18:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716261499; cv=pass; d=google.com; s=arc-20160816; b=WpY9JHUmDkCMhfTPKUdfm/C3g88o9RoMrZ6CFmXnkIDKTvqeskMTPuKDT8RzVTMwWo lLGsvL+tzsa9PrSy2TuSen5M1huxKuh6nz4GukdaxtJoX3uJyaBo6XvditgQKV6NH+YI uxpe3Ffmx63nA32Ws77J2q/s3/FMuFlglZ5LwI43wMQ7Za/btnxBJ8Wa6BLNHflQRtLN /eMtuqxRCNNxe5JrcvvMDPFMO/63HJWAAoELif9knCSeDiQ0sMrfoyy7PNnY2Aox/qje ELL3Jqhodr1DkyHEM4f5P+53pDO1OvhGm/tfhWX8Hl1//Ypt1SIBm0svqHVkBlqwXEQd PBIQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=0W1K4/bnAxmDtKxSlRyWJS71ccomqLJHmXSPbW1sWy0=; fh=32Gorq14wzxqldfP7+dDOnTOErirctCcW98+XgYwMiU=; b=bnmnskkVjkWnvmfNcwVldRg5szEHlOqTUvGcUyECzCXcnsMgCx6g3oF1sbyhIOAFhd kESViLceLHV7xNY8+l4WwYEM7znn8AbZ3MnQZzlbswlfI7BN2aCzkvgAseldk/66TwcO KlObYDLtirtw8kN6HIBlmZXgiDcbMM1mHL6XzWTcbZhHhkWc9ieWL9tpxFZh2zVo19HR ZY+3iBm4lH3krqhYukYoLknCoZsbd3aPmmFP+FeYlpeiqNIHliY2lrY6RPjDjQ4tLQXC seBC7vilgI6sLsuj61TC4TGvQrZuslbBT9NGRvACGVIwbHhY3nmaBa9s8T9BorNeZ8BE nuKQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BE+6tN+m; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4291-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4291-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43df549ca2dsi9105391cf.125.2024.05.20.20.18.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 20:18:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4291-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BE+6tN+m; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4291-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4291-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0315B1C20A8E for ; Tue, 21 May 2024 03:18:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1FCA22E62F; Tue, 21 May 2024 03:17:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BE+6tN+m" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C09093BB32; Tue, 21 May 2024 03:17:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716261439; cv=none; b=lyDGkfJpJJmHeLiVzYurx4DTT5kOx9Xc5zji2NVUh0rvG3Kaa33EO6rP1SvYIcQTksFv0s81hTLNkkeSTG+TpvwPTv5hXnzmWfcRKmwv+CkO/3c1Js6pXB9ZAMn8AnReGZWXNGmLZkwNApan6FvFxW3c6Tyamjg0eaE63eGOd28= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716261439; c=relaxed/simple; bh=UAboRLGS7mPC957H6sOCjxTXDHuNsnoUR6E4ZLlnQfU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RSaxncjtJ8W9xFc8MYYnP3hix6ngPqVENTuc4FHdalqXqXzdU93vvz25ZS3NxyPK3BRRv5RCs9HxQ0UEtIyzvZYFjyuIjaLz7viY5gEqod5iUVw5eUMOXNq0jRpbiUL2lJh8PtjWEYJYRwCOuNrMb2n216FJK/eIskG5APaGspM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BE+6tN+m; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D663EC2BD10; Tue, 21 May 2024 03:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716261439; bh=UAboRLGS7mPC957H6sOCjxTXDHuNsnoUR6E4ZLlnQfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BE+6tN+m6fx9OgZToaDacpbDWg+pJj59hvxFVCDQEd+zb5xAE344zx6ST7EMNHWsB so/X2hKPVn3FuA0kkSjC0jZjpND0sNc6ne2LAtIOgkAKzfycTyiLSmglDudknOizHY If14J9oWy00jpVeGnKzaOAqQFyn1yHlueM0RwJJSsCTyKys0ZbunfqptVIMvdTnoY3 Kgv16jgwi/KoB1jlWHOuIsUKU9ugR4YeH8b7+VCWOFQczT3oQDDf817ATCeSu68Rfc /7hQqB9zS9bT8SMWo1Jv2jjVc/sCPGkvZjFXaOsJoE+esLGSQAJgxzZepkX8QqMpUs uPSu9a0mFz5jQ== From: Jarkko Sakkinen To: Herbert Xu Cc: linux-integrity@vger.kernel.org, keyrings@vger.kernel.org, Andreas.Fuchs@infineon.com, James Prestwood , David Woodhouse , Eric Biggers , James Bottomley , Jarkko Sakkinen , "David S. Miller" , linux-crypto@vger.kernel.org (open list:CRYPTO API), linux-kernel@vger.kernel.org (open list), Peter Huewe , Jason Gunthorpe , James Bottomley , Mimi Zohar , David Howells , Paul Moore , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org (open list:SECURITY SUBSYSTEM) Subject: [PATCH v2 5/6] tpm: tpm2_key: Extend parser to TPM_LoadableKey Date: Tue, 21 May 2024 06:16:30 +0300 Message-ID: <20240521031645.17008-6-jarkko@kernel.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240521031645.17008-1-jarkko@kernel.org> References: <20240521031645.17008-1-jarkko@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Extend parser to TPM_LoadableKey. Add field for oid to struct tpm2_key so that callers can differentiate different key types. Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm2_key.c | 14 +++++++++++--- include/crypto/tpm2_key.h | 2 ++ security/keys/trusted-keys/trusted_tpm2.c | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/char/tpm/tpm2_key.c b/drivers/char/tpm/tpm2_key.c index 0112362e432e..59797dc232f1 100644 --- a/drivers/char/tpm/tpm2_key.c +++ b/drivers/char/tpm/tpm2_key.c @@ -32,16 +32,24 @@ int tpm2_key_type(void *context, size_t hdrlen, const void *value, size_t vlen) { enum OID oid = look_up_OID(value, vlen); - - if (oid != OID_TPMSealedData) { + struct tpm2_key *key = context; + + switch (oid) { + case OID_TPMSealedData: + pr_info("TPMSealedData\n"); + break; + case OID_TPMLoadableKey: + pr_info("TPMLodableKey\n"); + break; + default: char buffer[50]; - sprint_oid(value, vlen, buffer, sizeof(buffer)); pr_debug("OID is \"%s\" which is not TPMSealedData\n", buffer); return -EINVAL; } + key->oid = oid; return 0; } diff --git a/include/crypto/tpm2_key.h b/include/crypto/tpm2_key.h index acf41b2e0c92..2d2434233000 100644 --- a/include/crypto/tpm2_key.h +++ b/include/crypto/tpm2_key.h @@ -2,12 +2,14 @@ #ifndef __LINUX_TPM2_KEY_H__ #define __LINUX_TPM2_KEY_H__ +#include #include /* * TPM2 ASN.1 key */ struct tpm2_key { + enum OID oid; u32 parent; const u8 *blob; u32 blob_len; diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trusted-keys/trusted_tpm2.c index f255388d32b8..ce4c667c3ee3 100644 --- a/security/keys/trusted-keys/trusted_tpm2.c +++ b/security/keys/trusted-keys/trusted_tpm2.c @@ -305,6 +305,10 @@ static int tpm2_load_cmd(struct tpm_chip *chip, payload->old_format = 1; } else { blob = key.blob; + if (key.oid != OID_TPMSealedData) { + tpm2_key_destroy(&key); + return -EINVAL; + } } if (!blob) -- 2.45.1