Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3160442lqo; Tue, 21 May 2024 08:28:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/zWl9Chg4PkLyM5szFRgh3YbThfflqBtC0Y7J0piB+Ze7u3lQvqSIa1bykACnf90T5GGBKwbUdhJxVMo+C99BpHWlxReo1LS//FkHyg== X-Google-Smtp-Source: AGHT+IHCHlUXJ81Iss9hRg/7/agOeUSo04znJjNeVWk+s0TjsRUeI2gUAtgFNFeg4a66YTD9PFjB X-Received: by 2002:a17:906:3849:b0:a59:b02a:90dc with SMTP id a640c23a62f3a-a5a2d66ac03mr2060436266b.54.1716305304379; Tue, 21 May 2024 08:28:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716305304; cv=pass; d=google.com; s=arc-20160816; b=WuLxe81PNVCgXeIGaaiXPvc76glwIL4ewymxnSNg+qNp8PPHCOdiHsE1/0y+ipw8cT k1upQi6T86U34WJQWm8p8LMKRQW6ePNxCQvb6Kvur9mpDvwb2rEsa8yOy+RfIYYvDImF 8xq30CciK9Loe12yKercz24CI0eFHelXwRDmYJRstNa3HD7JzTBmFdk5r46Nz2JXW8dT eov6APDQ2g+TlR7A5Vk7lX8kYDReTx1G2wOwU3Ul7r0vhsGS7J3K2emuAm3O182EiIbS HW9wPt6NNwO6nflqQeQN53nnIIJbq38ugYDZSZbv/53YHm0LwLNLShWMNwl1sBiKaimL hPtQ== 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=spUO/SNeAlhXWz9rakG/M0WumNrLduFivDDHgYhP51I=; fh=32Gorq14wzxqldfP7+dDOnTOErirctCcW98+XgYwMiU=; b=y5Xu++DzTwrdBxKD3trv8E9sRKyOfMPvIo8+cIcHcDr0aRP7INuCGdF3pnqtg5L/tS 4vSWYR6TEA+fTLUa+95Zwppyw3otSs0eyI+RNhjA91Da00twQsEi7wGOGz26B8yNgWaH kermZPnL1EHTEfnqtqufr1QXYcFhuG2/+BBeycU1HDu25Fu4o0SiiMZPwKu7Jl7HQ94n NaqyH2UoyoVgJS/Ksvk6RAkDT/4R8HFbG3AI1k7gnUGnhd9Iq+JlQYXpifxBvJcQEib4 F2bEJj8RzAh0n/0erYs5F+fir4ryT6EJEcfnrCsLaftlrLaaW9krZ7q2tD/9gLVPKeR2 rmUA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mvatreaw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4305-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4305-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17c2c687si1445706166b.931.2024.05.21.08.28.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 08:28:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4305-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mvatreaw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4305-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4305-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 201B21F227E4 for ; Tue, 21 May 2024 15:28:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D6DB1448EF; Tue, 21 May 2024 15:27:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mvatreaw" 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 4B3D7146D77; Tue, 21 May 2024 15:27:29 +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=1716305249; cv=none; b=Sm5+MZU+rZdjfBVLua8Hflg/mUJUnwHF8DQrHYU6gz01QHBq08IZGQ1/xFpUbFUZkTbRJYUttGgqa6QV+cOG0CIWIYunttLeM38qquSN3YtEVcpOw6lsuOjdireZugF/54xmxWIjF8ZEVWICWlcIkCY9fusbEymO+jEgerqFUpE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716305249; c=relaxed/simple; bh=zi66issw9MiUi8Zz5qR+3SdBH1g6liWWaQWZQngxkW0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jSnBVl1sVHg6w/rJHpkkYZRZtPZpvKNAGz8rvlQu/jE1MGyfVbtNy8ixhhffznqmsP+28sUrw7fKvhaqzKAClW+NBUcwcVDvGuVd2cbUUxcn4wcdL3YCSRCIN9c5/FXDm1Vt9rUQEMtsp5d1uSMlFmnTtnlMHzKTgHns3nqVr3w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mvatreaw; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76D73C2BD11; Tue, 21 May 2024 15:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716305249; bh=zi66issw9MiUi8Zz5qR+3SdBH1g6liWWaQWZQngxkW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mvatreawEq355t8Gw/Bq8zGwK0yyo+Qa7G7CsSNi9NDKp9fuv2UAPAM0px69HdEMY hGJkHOD4g2Xc60Q94jEDzaYykpHbH/F8pGTQnu1mzEST67YM5423/lVkGC4vbZPO8b lmgVD0Rqd+JD4v0VsnRPlWTu55CAfIZwZwET8tdt3SESlxkUKiH64GR6xMXhZ09HJi YszETIgyp75Z3JVZxD4INNKfgvRMKKH7wmvqsQK/35Vu8KAp8rDUppbtnzKiLIKoMj VzcX7BUHDZHYyUwi0wE1b8Jfte7iRuWbDCJClju6CAegZ7A/dg6DJk7N/wJxaQAfiA 8VkdDABmPGHUg== 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 v3 4/5] tpm: tpm2_key: Extend parser to TPM_LoadableKey Date: Tue, 21 May 2024 18:26:46 +0300 Message-ID: <20240521152659.26438-5-jarkko@kernel.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240521152659.26438-1-jarkko@kernel.org> References: <20240521152659.26438-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 0112362e432e..06be1cc0156b 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 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