Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp171679lqb; Thu, 23 May 2024 14:27:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5Annh/YIq4wCMiJNP0QVall3VTBEp9CApd+kEfGOe7gpPQXIDvwF23EwP/gc+ACvthkzBNdA/Ghu1DFy+/XCdHfjXBeciLOMcBUWHlQ== X-Google-Smtp-Source: AGHT+IEj6m1/UVGITO8RyLzf3ZERI5LqzP4y8i6BaZ108p4vZZtE6+x/0B7ISx+D3HRdRqdXN685 X-Received: by 2002:a05:6a21:4995:b0:1b0:194a:830c with SMTP id adf61e73a8af0-1b212f75b87mr643416637.56.1716499645915; Thu, 23 May 2024 14:27:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716499645; cv=pass; d=google.com; s=arc-20160816; b=e1toFospt+EvlMeCiJBE7fuTFxDhAuuHQOydY69ZSfkUHX9rlHXb2efBFfpusFNEEC 9ljo3keSZG66BRwiKASRo6mQBhg/ob6RASymg7BaoPbj4X1n5gquzI5ScpANLDrRstjY jdfryDSMXvTUOklwlg5ZFGOCkBBQxN3V4TVEi+SxsMNN8fZ5t75gcbvc+TlHPS+LWyfQ FLF48iTGcPvoBHk8v9/RnSj3pS7o7vueq1dy0pAMXPG6vOr218ri5KplGbHHOnTcM8Ef eZcFzUVGAgVParhFmD+Kb2KvIfTYCV9hoV0jw62B7EbSDWujV7ptnIE/pUeS3ehe83DS JSuw== 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=aExsMOhdqhAjXE2FMKZhTCGnANyDeCoFTBcsIRAyMrw=; fh=Uj+JI8xIhdSjsZbJpEu5OybZTU1oW3tXFQVqTPnb7to=; b=LyDikqlFZr8As0lVinrSLOrOznOJD259zQqpNVlKbMK8TlPd7ZPcsqZuxy+YaG3ZZ4 EAEcmuf2/JfTp7AVGfsPCpCDIEctzynL6AEsnaPGNpqRuL349fVvnRGCuhVlcUWZLYTK vRo3zzeQM9TID74dGVksSry+vvYfrXwnyoKVDQrvWndelFKkOXl+s6V8bl788vvxXZnU nLF0GfTCmgXs6D74BhtYgzTLwp7Wrxta2QlKpbZ4hWfYN7e6cxKJPD08qLxvVFiXq1WT ogpErHzw7SGNhcuajNYJ34uJql8vZMlk9YVC0jq307k7fC6mKa6k0EISM0AqWlCShxxp m9Zw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Dqz8ifPL; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4376-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4376-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-682275b158fsi35894a12.345.2024.05.23.14.27.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 14:27:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4376-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Dqz8ifPL; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4376-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4376-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4B663280D8D for ; Thu, 23 May 2024 21:27:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25F6312A145; Thu, 23 May 2024 21:25:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Dqz8ifPL" 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 C9437129E8F; Thu, 23 May 2024 21:25:42 +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=1716499542; cv=none; b=mYkQv2H1A9k7xyaPYWkwlLl9H1wLXQzpVI78Wx0rnUXBP0FHwfZxcgva7zXmQbbP8eyw/vfAiFBKRIxvdrxODvLcS3vVQwzOkJeKC2tC36sJYOAjGxOGGa3VIGhqImXgo217yMahiFL3WSSe5OiZRT1pu5J4M/T/SWFTiZsfDXc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716499542; c=relaxed/simple; bh=bwx46fyxi21f4lcvrvEJTqeSya2jS+B+m4IM+zxLp1E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h+aY1VY6MywZ3NbYMzoTMHc45LpiwTXBKtZJU5ItEhl4s5GHEsSYNfGfeHnbcvSobsf5mSowdrkCPAFrGa/meAYwmRo9rJ0EYVQiFmOVOkSab6PhNsbi3e0hjfCCo/lJeuOdz4ZE6pDW0X+sCyANX4aIVLpArIQPQtHDo2gHJGI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Dqz8ifPL; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06DF3C2BD10; Thu, 23 May 2024 21:25:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716499542; bh=bwx46fyxi21f4lcvrvEJTqeSya2jS+B+m4IM+zxLp1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dqz8ifPLdAC3GfGmk+iFUDIJYQqDFZKz/rHwVow7krDMeCSi92Z3jvuJnR5ceYxj1 DHv9R1+hOfYxsGuV2ZrmOaE5rD+6NiD8KJS9yfkSS3sJJ+vILaZbFZgDwlUHjdIxu0 vDvImru48Z+xuT0jf2SFL5Ykhy4ujTInzztBw6VIVopGF53MjuECGB4hFB1tqmco+y oMr9tmZO7Bp55qDHTzprKeGKMCCC/vXLP1eym3eRqKoMJmEXhfbrLK1srcUCASIKdk oUulJ0Ow1p2ZXao4JBOuFtARibYlFAOJEZp542NuhQ7lWf8G1ouQHviuYtQVUos4gv Ry3+u3YepTBvg== 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 , linux-crypto@vger.kernel.org, Jarkko Sakkinen , "David S. Miller" , 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 v5 4/5] tpm: tpm2_key: Extend parser to TPM_LoadableKey Date: Fri, 24 May 2024 00:25:05 +0300 Message-ID: <20240523212515.4875-5-jarkko@kernel.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523212515.4875-1-jarkko@kernel.org> References: <20240523212515.4875-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 --- v3: * Fixup klog messages: https://lore.kernel.org/linux-integrity/SN7PR18MB53140F4341BC441C1C11586EE3EA2@SN7PR18MB5314.namprd18.prod.outlook.com/ --- drivers/char/tpm/tpm2_key.c | 17 ++++++++++++----- include/crypto/tpm2_key.h | 2 ++ security/keys/trusted-keys/trusted_tpm2.c | 4 ++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/char/tpm/tpm2_key.c b/drivers/char/tpm/tpm2_key.c index 7662b2cb85bf..b5c07288eff5 100644 --- a/drivers/char/tpm/tpm2_key.c +++ b/drivers/char/tpm/tpm2_key.c @@ -32,16 +32,23 @@ 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_debug("TPMSealedData\n"); + break; + case OID_TPMLoadableKey: + pr_debug("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); + pr_debug("Unknown OID \"%s\"\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 e0bd1a2fc2ca..5b4555dd13e5 100644 --- a/security/keys/trusted-keys/trusted_tpm2.c +++ b/security/keys/trusted-keys/trusted_tpm2.c @@ -303,6 +303,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