From nobody Fri Jan 2 03:11:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A4A4CDB465 for ; Mon, 16 Oct 2023 09:07:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233148AbjJPI5a (ORCPT ); Mon, 16 Oct 2023 04:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233109AbjJPI51 (ORCPT ); Mon, 16 Oct 2023 04:57:27 -0400 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90D2795 for ; Mon, 16 Oct 2023 01:57:25 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 39042240105 for ; Mon, 16 Oct 2023 10:57:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1697446644; bh=kv0HETudyLnK7zerm9neLvpDVJtlAcnFf3yrw1VeEJU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version: Content-Transfer-Encoding:From; b=fl7cKXtKqgMoo+wm4CW5MibIn+9AP5TAEM+bUCfIFsikcsqq0zlIpFLLEMwrkkGU7 MqvGf107aMkBI3j4y7GOthQmbkYuntjHWmaHHZJnMezHHR5Da7ZJIQvlufzzJZJNn0 4irEZBPwawFDf29amh26/1rekW71at6oFz9wkszJtGJZHkxAqOnaHkNKOlT2POSLpC nm3B99HsSTmzoubvKH2l+bTAbi1RoelQDSHIhAU1x7xsUza2EU2mM5wFQlVSK0+E7n 4CB6Vasig2VvGnYIodopcXpxCUqh9fvYiwczGez/vgPV7pWhd9lGkb+XU+All+BhzM YDy61XdIgSfzg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4S89wf3nYFz9rxd; Mon, 16 Oct 2023 10:57:22 +0200 (CEST) From: Mark O'Donovan To: linux-kernel@vger.kernel.org Cc: linux-nvme@lists.infradead.org, sagi@grimberg.me, hch@lst.de, axboe@kernel.dk, kbusch@kernel.org, hare@suse.de, Mark O'Donovan , Akash Appaiah Subject: [PATCH v2 1/2] nvme-auth: use transformed key size to create resp Date: Mon, 16 Oct 2023 08:57:14 +0000 Message-Id: <20231016085715.3068974-2-shiftee@posteo.net> In-Reply-To: <20231016085715.3068974-1-shiftee@posteo.net> References: <20231016085715.3068974-1-shiftee@posteo.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This does not change current behaviour as the driver currently verifies that the secret size is the same size as the length of the transformation hash. Co-developed-by: Akash Appaiah Signed-off-by: Akash Appaiah Signed-off-by: Mark O'Donovan --- V1 -> V2: support target implementation and controller secrets also drivers/nvme/common/auth.c | 6 +++++- drivers/nvme/host/auth.c | 4 ++-- drivers/nvme/target/auth.c | 4 ++-- include/linux/nvme-auth.h | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c index d90e4f0c08b7..26a7fbdf4d55 100644 --- a/drivers/nvme/common/auth.c +++ b/drivers/nvme/common/auth.c @@ -243,6 +243,8 @@ u8 *nvme_auth_transform_key(struct nvme_dhchap_key *key= , char *nqn) } if (key->hash =3D=3D 0) { transformed_key =3D kmemdup(key->key, key->len, GFP_KERNEL); + if (transformed_key) + key->transformed_len =3D key->len; return transformed_key ? transformed_key : ERR_PTR(-ENOMEM); } hmac_name =3D nvme_auth_hmac_name(key->hash); @@ -263,7 +265,8 @@ u8 *nvme_auth_transform_key(struct nvme_dhchap_key *key= , char *nqn) goto out_free_key; } =20 - transformed_key =3D kzalloc(crypto_shash_digestsize(key_tfm), GFP_KERNEL); + key->transformed_len =3D crypto_shash_digestsize(key_tfm); + transformed_key =3D kzalloc(key->transformed_len, GFP_KERNEL); if (!transformed_key) { ret =3D -ENOMEM; goto out_free_shash; @@ -297,6 +300,7 @@ u8 *nvme_auth_transform_key(struct nvme_dhchap_key *key= , char *nqn) kfree(shash); out_free_key: crypto_free_shash(key_tfm); + key->transformed_len =3D 0; =20 return ERR_PTR(ret); } diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c index daf5d144a8ea..89293da3210e 100644 --- a/drivers/nvme/host/auth.c +++ b/drivers/nvme/host/auth.c @@ -442,7 +442,7 @@ static int nvme_auth_dhchap_setup_host_response(struct = nvme_ctrl *ctrl, } =20 ret =3D crypto_shash_setkey(chap->shash_tfm, - chap->host_response, ctrl->host_key->len); + chap->host_response, ctrl->host_key->transformed_len); if (ret) { dev_warn(ctrl->device, "qid %d: failed to set key, error %d\n", chap->qid, ret); @@ -520,7 +520,7 @@ static int nvme_auth_dhchap_setup_ctrl_response(struct = nvme_ctrl *ctrl, } =20 ret =3D crypto_shash_setkey(chap->shash_tfm, - ctrl_response, ctrl->ctrl_key->len); + ctrl_response, ctrl->ctrl_key->transformed_len); if (ret) { dev_warn(ctrl->device, "qid %d: failed to set key, error %d\n", chap->qid, ret); diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c index 4dcddcf95279..c46473b383b1 100644 --- a/drivers/nvme/target/auth.c +++ b/drivers/nvme/target/auth.c @@ -298,7 +298,7 @@ int nvmet_auth_host_hash(struct nvmet_req *req, u8 *res= ponse, } =20 ret =3D crypto_shash_setkey(shash_tfm, host_response, - ctrl->host_key->len); + ctrl->host_key->transformed_len); if (ret) goto out_free_response; =20 @@ -410,7 +410,7 @@ int nvmet_auth_ctrl_hash(struct nvmet_req *req, u8 *res= ponse, } =20 ret =3D crypto_shash_setkey(shash_tfm, ctrl_response, - ctrl->ctrl_key->len); + ctrl->ctrl_key->transformed_len); if (ret) goto out_free_response; =20 diff --git a/include/linux/nvme-auth.h b/include/linux/nvme-auth.h index dcb8030062dd..cf24d885dfd9 100644 --- a/include/linux/nvme-auth.h +++ b/include/linux/nvme-auth.h @@ -10,8 +10,9 @@ =20 struct nvme_dhchap_key { u8 *key; - size_t len; u8 hash; + size_t len; + size_t transformed_len; }; =20 u32 nvme_auth_get_seqnum(void); --=20 2.39.2 From nobody Fri Jan 2 03:11:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0E38CDB465 for ; Mon, 16 Oct 2023 08:57:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233141AbjJPI5g (ORCPT ); Mon, 16 Oct 2023 04:57:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233114AbjJPI53 (ORCPT ); Mon, 16 Oct 2023 04:57:29 -0400 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C939B95 for ; Mon, 16 Oct 2023 01:57:27 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 6F1CF240104 for ; Mon, 16 Oct 2023 10:57:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1697446646; bh=brODLvvYvkikrtNYqrnX6Dobqx5VOdIf75/P3TBpnxg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version: Content-Transfer-Encoding:From; b=rz2yLfYBh0V5kX5rXYaSPuirzbRNh3TlARKEGFpk83Z1fEDqOkk8uoQwvUZ2x2R2p 7qhvUaxbbH8yOVvpm/7NqoMuQNdbF7qlPkPPB5dJultfzwkHORlLOfC7uRcNmzcOPU gH0JZykB4FMxUM9dLD1RhEW1ThK80mIHB/yNX15jfxTFFXyRoFeCP4v/YIEduB/y1b CE4a5IYhGK8guUXD+Db0sLNpS//yv2MnCyZtNGmrrFr7jD2PoLfQBHJBDrSsHTsUXY cbAIl/2u7voMpgBUyE2AMdH9wwbrLx4NEogU379p2bVQKrLLBamF3JbjrKpjG6D1Fd iJhgi/ZQPfdDw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4S89wh1bVBz9rxj; Mon, 16 Oct 2023 10:57:24 +0200 (CEST) From: Mark O'Donovan To: linux-kernel@vger.kernel.org Cc: linux-nvme@lists.infradead.org, sagi@grimberg.me, hch@lst.de, axboe@kernel.dk, kbusch@kernel.org, hare@suse.de, Mark O'Donovan , Akash Appaiah Subject: [PATCH v2 2/2] nvme-auth: allow mixing of secret and hash lengths Date: Mon, 16 Oct 2023 08:57:15 +0000 Message-Id: <20231016085715.3068974-3-shiftee@posteo.net> In-Reply-To: <20231016085715.3068974-1-shiftee@posteo.net> References: <20231016085715.3068974-1-shiftee@posteo.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We can now use any of the secret transformation hashes with a secret, regardless of the secret size. e.g. a 32 byte key with the SHA-512(64 byte) hash. The example secret from the spec should now be permitted with any of the following: DHHC-1:00:ia6zGodOr4SEG0Zzaw398rpY0wqipUWj4jWjUh4HWUz6aQ2n: DHHC-1:01:ia6zGodOr4SEG0Zzaw398rpY0wqipUWj4jWjUh4HWUz6aQ2n: DHHC-1:02:ia6zGodOr4SEG0Zzaw398rpY0wqipUWj4jWjUh4HWUz6aQ2n: DHHC-1:03:ia6zGodOr4SEG0Zzaw398rpY0wqipUWj4jWjUh4HWUz6aQ2n: Note: Secrets are still restricted to 32,48 or 64 bits. Co-developed-by: Akash Appaiah Signed-off-by: Akash Appaiah Signed-off-by: Mark O'Donovan Reviewed-by: Hannes Reinecke --- drivers/nvme/common/auth.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c index 26a7fbdf4d55..712178e1fb02 100644 --- a/drivers/nvme/common/auth.c +++ b/drivers/nvme/common/auth.c @@ -187,14 +187,6 @@ struct nvme_dhchap_key *nvme_auth_extract_key(unsigned= char *secret, goto out_free_secret; } =20 - if (key_hash > 0 && - (key_len - 4) !=3D nvme_auth_hmac_hash_len(key_hash)) { - pr_err("Mismatched key len %d for %s\n", key_len, - nvme_auth_hmac_name(key_hash)); - ret =3D -EINVAL; - goto out_free_secret; - } - /* The last four bytes is the CRC in little-endian format */ key_len -=3D 4; /* --=20 2.39.2