Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2915917lqo; Tue, 21 May 2024 00:38:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXmteidzkJa7eZ11IZ7qVNN0SHFT4XJposBSsi3G2Kp3nQz3noHhKzHt4q0Vyj/8weINHIhhmDQLdojTORiF5niH+3Xwl8a0o//ITgaBA== X-Google-Smtp-Source: AGHT+IEizvpA/dR8D8DVeRSltQ0YUsKWyaT3zQ/e+/014OZzxqig3JZJ7DKtG8/6a5fPDOX0K1J6 X-Received: by 2002:a05:6a21:32a7:b0:1af:b89b:a7f1 with SMTP id adf61e73a8af0-1b1ca452895mr11469720637.27.1716277136032; Tue, 21 May 2024 00:38:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716277136; cv=pass; d=google.com; s=arc-20160816; b=S150vJHaEjWG9qwO+H6+YbI9pP9MeoOWVzsT8UHIV0VNQtk2Ff2wHmTubAyyWMJYqM Ov6NBv3uvZG7ndK3+4LWt9RBTB4tFJG4xHNYcdFqs8zlPPvfuar6A8Ltua8wS2xFilsr pH1bHMjDYuYgKvruZwjzb+GO//2iYEFfUtS5h0oLPy+9sX5iZTKscBreL/27WK15509P YpDl/UKVHZScZtIPRBmaIWmqSPkTqkkDVSHNJE2zq6j1qkWXPZm4X4yWmCfRFQZnTHwD qfHarHi/48tk5M8CQVmPAj7Y+y5Tu7dZd1niLn+NXIHH27VMLuLkEG91FVu5jUBSv4Oc 0yyw== 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=ru2GjphcYNS5rFnSj8BBlVSGTp/L8oH+FkKgchU/ZMg=; fh=V58SiSLp9BPhHeokcyC4I+bhFkvlSCWETxAzYLAm3AU=; b=FsWvO5cF2p24g8mYjIRbc0YglMj4sjGgCRIk1Azl0Sy3TxC8M5+lBgLFT1I+HnXRO5 d4arPENlbTFsF4TBKCpk1LNTRm0JdoKUK9dDpwWx5BfDyIp5GhQNhyMP5QnKnXWGbtOf BZiXfotGRyvd5e1r28u7vzqm+uDcNPl4jci+QIJxxThl0MnWrYCQ9CyK1TxzqcW8kLpV hn7jcf9P0AJig+kA9smdQcpg+NaTHjRPKpOfw1SpcKyoSXBeLsnTQGaHwhiJp7tf0Hea csz4gXAR3P7iAyKpPXOt5xNaGBEcOwHsNsfVe/t+1tGscDLz9nCvu8VqDE1BV8gIptdH 77bQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FF2GoAgC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4298-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4298-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-65968055bf6si1602272a12.721.2024.05.21.00.38.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 00:38:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4298-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=FF2GoAgC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4298-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4298-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 613B6282D5B for ; Tue, 21 May 2024 07:38:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D8F0450A9D; Tue, 21 May 2024 07:38:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FF2GoAgC" 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 8E061256A; Tue, 21 May 2024 07:38:51 +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=1716277131; cv=none; b=eWOns4g0hU5Wh04tVgt3ydNhISPltyzge3tto+NuL57XXEyG2E1oXlQRxs1JZu8WKAOL2UEFRmI5VK6qQyi5szIWhihwmjFF/BJtbCCqSY7hUcrAMJOR4rWpWLr8qCP69f02Gr9DDinjbL9HH/a9IFcSA9UZJOmFMKnY/lScO5I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716277131; c=relaxed/simple; bh=n3xfaBqyzHw0uuGiyp3gaPzVQKCAlmedilfKQVu9mgo=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=r9Xe8jbnnHeMuzGilBT3aolUdo3DmLleO0zSKRCvm5ziGyWggPMaer5c2A8Aa920u18t2N56GhQ/69ddcsaerAluPPb8MvtI++fq4xZ1yymi9isV6J1rR18BgxPd2WG1gbqkCdXU7I/71S8o8HqjqplGKIlWuaZNXpbz0y4yqVA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FF2GoAgC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99EC7C2BD11; Tue, 21 May 2024 07:38:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716277131; bh=n3xfaBqyzHw0uuGiyp3gaPzVQKCAlmedilfKQVu9mgo=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=FF2GoAgCjJ498XNO6RAlKNhFWaypadqZPrO9K2pDtYj81cNYbQoUelahRp//zSwIK dEVKHEHcKNGy/JAom8vs4u6fsKrVwqx3sABZTq4bYPjLuAJvucsv7edvjUBK7RFz0X 9BJc5Kg5yCzmfPti5qB/vRRA0KSv7PlzkM6KDx4ML/y9KlkjyxY5R4UCslzidFccGh AWwit3scKE2v1fcoo/vu2mWN/VbylF2mvX5qDRp6CiQGJWgcDEuobS+iS3rxS54ngk /icdK1nFDzd2ShkqAGZhaeOomcZ7N1X1PVLn8lz3O9vwWySaswsXTJPXT80Rz9TmdZ KchKbYY5CwgDQ== 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: Tue, 21 May 2024 10:38:45 +0300 Message-Id: Cc: "linux-integrity@vger.kernel.org" , "keyrings@vger.kernel.org" , "Andreas.Fuchs@infineon.com" , "James Prestwood" , "David Woodhouse" , "Eric Biggers" , "James Bottomley" , "David S. Miller" , "open list:CRYPTO API" , "open list" , "David Howells" , "James Bottomley" , "Stefan Berger" , "Ard Biesheuvel" , "Mario Limonciello" Subject: Re: [EXTERNAL] [PATCH v2 6/6] keys: asymmetric: ASYMMETRIC_TPM2_KEY_RSA_SUBTYPE From: "Jarkko Sakkinen" To: "Bharat Bhushan" , "Herbert Xu" X-Mailer: aerc 0.17.0 References: <20240521031645.17008-1-jarkko@kernel.org> <20240521031645.17008-7-jarkko@kernel.org> In-Reply-To: < On Tue May 21, 2024 at 10:25 AM EEST, Bharat Bhushan wrote: > > + rc =3D crypto_akcipher_encrypt(req); > > + rc =3D crypto_wait_req(rc, &cwait); > > + > > Few Minor comments,=20 > Extra line here=20 Yeah, makes sense. > > + if (!rc) > > + rc =3D req->dst_len; > > + > > + akcipher_request_free(req); > > + > > +err_tfm: > > + crypto_free_akcipher(tfm); > > + > > + return rc; > > +} > > + > > +static int __tpm2_key_rsa_decrypt(struct tpm_chip *chip, > > + struct tpm2_key_rsa *key, > > + struct kernel_pkey_params *params, > > + const void *in, int in_len, void *out) > > +{ > > + unsigned int offset =3D 0; > > + u32 key_handle =3D 0; > > + struct tpm_buf buf; > > + u16 decrypted_len; > > + u32 parent; > > + u8 *pos; > > + int ret; > > + > > + ret =3D tpm_try_get_ops(chip); > > + if (ret) > > + return ret; > > + > > + ret =3D tpm2_start_auth_session(chip); > > + if (ret) > > + goto err_ops; > > + > > + if (key->key.parent =3D=3D TPM2_RH_NULL) { > > + ret =3D tpm2_load_context(chip, chip->null_key_context, > > &offset, > > + &parent); > > + if (ret) { > > + ret =3D -EIO; > > + goto err_auth; > > + } > > + } else { > > + parent =3D key->key.parent; > > + } > > Do we need braces here? I think I added them because checkpatch complained me about not having them. So I guess the rule is that if any branch has braces, all of them should have... > > > + > > + ret =3D tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_LOAD); > > + if (ret < 0) > > + goto err_parent; > > + > > + tpm_buf_append_name(chip, &buf, parent, NULL); > > + tpm_buf_append_hmac_session(chip, &buf, > > TPM2_SA_CONTINUE_SESSION | > > + TPM2_SA_ENCRYPT, NULL, 0); > > + tpm_buf_append(&buf, key->key.blob, key->key.blob_len); > > + if (buf.flags & TPM_BUF_OVERFLOW) { > > + ret =3D -E2BIG; > > + goto err_buf; > > + } > > + tpm_buf_fill_hmac_session(chip, &buf); > > + ret =3D tpm_transmit_cmd(chip, &buf, 4, "RSA key loading"); > > + ret =3D tpm_buf_check_hmac_response(chip, &buf, ret); > > + if (ret) { > > + ret =3D -EIO; > > + goto err_buf; > > + } > > + key_handle =3D be32_to_cpup((__be32 > > *)&buf.data[TPM_HEADER_SIZE]); > > + > > + tpm_buf_reset(&buf, TPM2_ST_SESSIONS, TPM2_CC_RSA_DECRYPT); > > + tpm_buf_append_name(chip, &buf, key_handle, NULL); > > + tpm_buf_append_hmac_session(chip, &buf, TPM2_SA_DECRYPT, > > NULL, 0); > > + tpm_buf_append_u16(&buf, in_len); > > + tpm_buf_append(&buf, in, in_len); > > + tpm_buf_append_u16(&buf, TPM_ALG_NULL); > > + tpm_buf_append_u16(&buf, 0); > > + tpm_buf_fill_hmac_session(chip, &buf); > > + ret =3D tpm_transmit_cmd(chip, &buf, 4, "RSA key decrypting"); > > + ret =3D tpm_buf_check_hmac_response(chip, &buf, ret); > > + if (ret) { > > + ret =3D -EIO; > > + goto err_blob; > > + } > > + > > + pos =3D buf.data + TPM_HEADER_SIZE + 4; > > + decrypted_len =3D be16_to_cpup((__be16 *)pos); > > + pos +=3D 2; > > + > > + if (params->out_len < decrypted_len) { > > + ret =3D -EMSGSIZE; > > + goto err_blob; > > + } > > + > > + memcpy(out, pos, decrypted_len); > > + ret =3D decrypted_len; > > + > > +err_blob: > > + tpm2_flush_context(chip, key_handle); > > + > > +err_buf: > > + tpm_buf_destroy(&buf); > > + > > +err_parent: > > + if (key->key.parent =3D=3D TPM2_RH_NULL) > > + tpm2_flush_context(chip, parent); > > + > > +err_auth: > > + if (ret < 0) > > + tpm2_end_auth_session(chip); > > + > > +err_ops: > > + tpm_put_ops(chip); > > + return ret; > > +} > > + > > +static int tpm2_key_rsa_decrypt(struct tpm_chip *chip, struct tpm2_key= _rsa > > *key, > > + struct kernel_pkey_params *params, > > + const void *in, void *out) > > +{ > > + const u8 *ptr; > > + int out_len; > > + u8 *work; > > + int ret; > > + > > + work =3D kzalloc(params->out_len, GFP_KERNEL); > > + if (!work) > > + return -ENOMEM; > > Maybe use ERR_PTR() here and couple of more places Hmm... but the function returns 'int'? BR, Jarkko