Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3379024lqo; Tue, 21 May 2024 15:42:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwxKN2vGVfHULuzozfb10EP8rgv+VrOW8/iBgj5OJlCDWDyPRpApGHmbljDvBKsxWOITja8Il7GYHeX0A0eMWj2xMX8XBvC0tI1JiIeg== X-Google-Smtp-Source: AGHT+IGmo0duvi6Mc6w0sRytt2tZotdcFt2WSzOMNNg1yLWFSox9uQwSHzy6LndA6e5+g7QDX276 X-Received: by 2002:adf:fdcd:0:b0:352:b632:b309 with SMTP id ffacd0b85a97d-354d8daceb1mr183538f8f.60.1716331351172; Tue, 21 May 2024 15:42:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716331351; cv=pass; d=google.com; s=arc-20160816; b=M0wpS/4lebUsZRrljDOVx0XDlgzBz4BaLrgvCricCTL8Z1SRppmGK2kAU5hOEL/ScY L9OXK4UjGhd1lbq54JR56IxnEPobiHMi05tjvHW0mjMVW8trM/IhBcwT7rGcCaKVVDz5 yfaJ8WyjbsjJ6R18eEMzuEVlnV0x4p/V4+HZAUbX0vhqI0Eetlml2kOs+PKpk2KD2qtG 4jXNeU79+2pZ2/Gg2/z4oz92PWU61nR2QOV2H3oiNJdDthI/gsrRd7Fytqi0X94c6HM4 5fVn/B29MoK3sr+U3mVfMDsW3rrDLYle4LDQNNWs8FhgeVj+7233g417scJmjksO2Gs5 sS9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=6Npc/KFbH/HUmFPgaFvYlPlSIugyrKQ5m0GDqQCqnPI=; fh=XmYt1gmEYYJ9zQ+7A08TBO5oQNQcls25UnrI2E3980Y=; b=y0f6PZxZ18EqrhgeeiXC1hM3d0AwXK2U3r+9Q3tJNmd5iZnGaXnmbc5JE4fg4HdrBe ioHRPQMhyJltqWMMNxtYuGO4ddo1jlGubA0pA/cRIk37GzcAk6peTivDyqdA5ueXotbD smCIXTumnvAnzztkCKn7q1Ng/Padf2NKXHFL7avGkZz7Rw2u4K2ufX+HLF3N97/GjMAU kRPEmu114/BF/fbo3ezWiGeHYDg2bVfCcBdUNHn0SFIjgi/VAr4DBR1kh+GWlDskr1Ya 2PUY0of2SQ50zSFHLpMEZvshNTMvlu8QQr982ISXIjW/wmj1UMdIuk8LlirTM+l95Wdb /Qug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iNTPCUzu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4316-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4316-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-a5a17b219e7si1452119466b.311.2024.05.21.15.42.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 15:42:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4316-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=iNTPCUzu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4316-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4316-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 843DF1F226F2 for ; Tue, 21 May 2024 22:42:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 46F39149E19; Tue, 21 May 2024 22:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iNTPCUzu" 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 DF8483BB21; Tue, 21 May 2024 22:42:20 +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=1716331341; cv=none; b=gFrh1S762JJQFlf27y6BmrzcV+vPFeYUcMHeSfmKKtpF0JS8RTztUY8Lh7a582LGtUAcNhD5suxYpm7id95NvaZzStWQBfxPz2w7Ji6tNl2phDzW73vm2HXyPLD46uxPuR8Qq3U58T64VlmCrNOKtxdiZmeCiPq5kzlZIQJOLYI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716331341; c=relaxed/simple; bh=IGvF/ZLOM9k1OCm5fZ83p/8+gCIoPFXgGAl3mveUSZk=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=GKQvCe1jYH46xJ7qxVtX4gsoN1XMhHhRCgyLaDMERRlW5E+p5hqAW5gyQajJ81baxHRNYCFJwK2NFxkJaLnxokOR3QG3kHUasd63f8/ebPgoUEQdbPfF1O5Ahck7gSP2QZtva37ye26LRD+9SugfPn6TU7YILib39YE2QPhHJUw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iNTPCUzu; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2291C2BD11; Tue, 21 May 2024 22:42:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716331340; bh=IGvF/ZLOM9k1OCm5fZ83p/8+gCIoPFXgGAl3mveUSZk=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=iNTPCUzu30RcoOTyh95mpUIKKWjWX+HNAGih+3DGc0/eSY8NdIHk2BLpOukXlOxP6 LXYhq7kSYdzrB18aR0IBv5wnXnyoVQySZ7bIxfCtI7r/leT38vOW4S4+QSjyKT+wpj ZRxyM+46opxpZ5ydIUBCrX07ykzGMxEwhc2P6K99mk3Ply+ySg3Lt75aIEDcau73Oh LB9VQIHY1MlDsFu/LTbB6ScqhnVzc6U68XMprFupVBI/d2RtskBmFfVN7ZJhTzt40c JyysYQ1tUd7vG90G0uyd7gWVTmZXS9mESMKvEEV6FI8FxlS2OMrHRb53TzUHuGR+7X hb0hgS4el2tOw== Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 22 May 2024 01:42:14 +0300 Message-Id: Cc: "James Bottomley" , "Herbert Xu" , , , , "James Prestwood" , "David Woodhouse" , "Eric Biggers" , "David S. Miller" , "open list:CRYPTO API" , "open list" , "Peter Huewe" , "Jason Gunthorpe" , "Mimi Zohar" , "Paul Moore" , "James Morris" , "Serge E. Hallyn" , "open list:SECURITY SUBSYSTEM" Subject: Re: [PATCH v2 4/6] KEYS: trusted: Move tpm2_key_decode() to the TPM driver From: "Jarkko Sakkinen" To: "David Howells" X-Mailer: aerc 0.17.0 References: <20240521031645.17008-1-jarkko@kernel.org> <20240521031645.17008-5-jarkko@kernel.org> <336755.1716327854@warthog.procyon.org.uk> In-Reply-To: <336755.1716327854@warthog.procyon.org.uk> On Wed May 22, 2024 at 12:44 AM EEST, David Howells wrote: > Jarkko Sakkinen wrote: > > > On Tue May 21, 2024 at 9:18 PM EEST, James Bottomley wrote: > > ... > > You don't save a single byte of memory with any constant that dictates > > the size requirements for multiple modules in two disjoint subsystems. > > I think James is just suggesting you replace your limit argument with a > constant not that you always allocate that amount of memory. What the li= mit > should be, OTOH, is up for discussion, but PAGE_SIZE seems not unreasonab= le. When the decoder for ASN.1 was part of trusted keys, the check used to be: if (ctx.priv_len + ctx.pub_len > MAX_BLOB_SIZE) return -EINVAL; And MAX_BLOB_SIZE is only 512 bytes, which does not fit event 2048 bit RSA key but that 512 bytes cap seems to be just fine for trusted keys. So the new check is: if (blob_len > max_key_len) return -E2BIG; 1. Too big value is not invalid value, thus -E2BIG. It is has also shown to be practically useful while testing this key type. 2. tpm2_key_rsa needs up to 8192 bytes for a blob to fit 4096-bit RSA key.=20 Just saying but there is also primary null key allocated by the driver. And neither driver uses MAX_BLOB_SiZE. It uses value 8x MAX_BLOB_SIZE i.e. 4096 bytes so not really following the idea suggested. Finaly, there is three completely separate algorithms: - KEYEDHASH (trusted_keys) - RSA (tpm2_key_rsa) - ECDSA (driver)=C2=A7 =09 With all this put together it is just common sense to have parametrized cap value, and it would have no logic at all to treat them unified way. For tpm2_key_rsa I will define for clarity: #define TPM2_KEY_RSA_MAX_SIZE 8192 For tpm2_key_ecdsa you would define #define TPM2_KEY_ECDSA_MAX_SIZE 4096 So yeah, this is how I will proceed because it is really the only senseful way to proceed. > > David BR, Jarkko