From patchwork Mon Oct 16 08:57:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark O'Donovan X-Patchwork-Id: 153263 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3324779vqb; Mon, 16 Oct 2023 01:57:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVhjL15gIHQQ56XH+ASDh30ZDxI6VgDKnm82YW0rqgUuEWLTuvC1z/l0C07moNhEVKRCcW X-Received: by 2002:a05:6830:4867:b0:6bf:500f:b570 with SMTP id dx7-20020a056830486700b006bf500fb570mr30913828otb.3.1697446655656; Mon, 16 Oct 2023 01:57:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697446655; cv=none; d=google.com; s=arc-20160816; b=RK4rPTy4C9ieqLiN9h9HaCIpb43RIVsuiiyO8YXOlK4LjPq8MNy3eTFIYAkMTBKgc0 qgIfTjs5iMnZZrrrsGWKzRDMAFs+b1VDfNdZMkxR884rBR3jA3X6Qdb9mYFuMtgOXOWP xI/bv08gAs2R0DwXEMJF/vTQRV4eP6Z6uibur9rCAY5ju/hQsPF3u1+9aGFzpBqnVCHv mlNZBqbPbI2YLTyQqV287I+UV0972XUbVEMGnBCEN1OH1akgDeOrbnVSc2fRDWHMcy1N AUvh120xsyvAoFbbCfqGRie+M7xo+ySW2IqtbMQtRWWW2pqai48SUcqFxvpZJGZQqBg7 Uxsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IMQR5cNvM+ZVjAji+5R7a1XSgCNs6VwXtgxU/bgB4Eo=; fh=OK6NlIuxAObXnbB+YsmCJIFQ9spAlQ71xiCElZ04Vio=; b=IpWLGLbX8KYhh/BdN7BxVWm1u4fUSvNMU1HT5BSb+oBxtiXW2B2XEnK0yUODOTxW4D mi6JmweoYrr/XBvK9WkxddBSk7FztPzOoJDV9jzgJ8EB7Gid+E/HyK5IuBTsLbUAbWvA jzEzZOXeozm8TakX0sn7H0azYPea7c7Yhn4vctuezX0hvkK8Q/0g3uKebqIU2EYi40yV A0DbAWrpa5AczR1nGJQeBXDfqkFEWvzJ2dMrEHJ09NZhBQX+n65ZpNw0J69ZgWlETnM1 T/U8cdlNk0COv45chHNPnOYeFVtVy0w4p7DfMVGZBHfExEj6fK8qP9Kyzv14jtvnXO7r YUHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=fl7cKXtK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id by5-20020a056a02058500b005af417423b4si6719620pgb.589.2023.10.16.01.57.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 01:57:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=fl7cKXtK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D909D80B81CB; Mon, 16 Oct 2023 01:57:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233128AbjJPI53 (ORCPT + 18 others); Mon, 16 Oct 2023 04:57:29 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 16 Oct 2023 01:57:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779901824537049820 X-GMAIL-MSGID: 1779901824537049820 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 == 0) { transformed_key = kmemdup(key->key, key->len, GFP_KERNEL); + if (transformed_key) + key->transformed_len = key->len; return transformed_key ? transformed_key : ERR_PTR(-ENOMEM); } hmac_name = 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; } - transformed_key = kzalloc(crypto_shash_digestsize(key_tfm), GFP_KERNEL); + key->transformed_len = crypto_shash_digestsize(key_tfm); + transformed_key = kzalloc(key->transformed_len, GFP_KERNEL); if (!transformed_key) { ret = -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 = 0; 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, } ret = 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, } ret = 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 *response, } ret = crypto_shash_setkey(shash_tfm, host_response, - ctrl->host_key->len); + ctrl->host_key->transformed_len); if (ret) goto out_free_response; @@ -410,7 +410,7 @@ int nvmet_auth_ctrl_hash(struct nvmet_req *req, u8 *response, } ret = crypto_shash_setkey(shash_tfm, ctrl_response, - ctrl->ctrl_key->len); + ctrl->ctrl_key->transformed_len); if (ret) goto out_free_response; 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 @@ struct nvme_dhchap_key { u8 *key; - size_t len; u8 hash; + size_t len; + size_t transformed_len; }; u32 nvme_auth_get_seqnum(void);