From nobody Wed Dec 17 09:50:19 2025 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 90A6FCDB474 for ; Mon, 16 Oct 2023 23:00:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234164AbjJPXAC (ORCPT ); Mon, 16 Oct 2023 19:00:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232985AbjJPW77 (ORCPT ); Mon, 16 Oct 2023 18:59:59 -0400 Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95BBD9B for ; Mon, 16 Oct 2023 15:59:57 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id F2EA8240029 for ; Tue, 17 Oct 2023 00:59:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1697497196; bh=rnbADe6m90A07GERJn789AJyLmRj2m+LZ1+95wztGA4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version: Content-Transfer-Encoding:From; b=Jh5UDJJDwz543riptIZiaIlXKxwqO2SN1Q1V4cGEbYu1Agz/0ga4sKyIegpitZdnN MQZXCjVcZans1EzSX9QLZ1MyhbX8wrfGn5qEUOI+BXTvthMCFdCEJVEPx6F0nH8J5z udKowcI8GDPfQNUGyMw8jULBGKNijrF2IP6wvMFMKrBZpRjd9kDu8zYP9ZWPnhiMYi TziYQT8sxADAQxTxE6Htmcn/+B6MKcwE9QUH/VNRJHyiczu0CD5ooOaSrryBvpz0PA cQnJJq+VVGBlSM/r3sAKexhOHeoEE3QOSAA18pFDxz7i4CBJUiLW4WlH8xgJZDiHc5 HF4qQjPO3j60g== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4S8Xcp34TVz9rxK; Tue, 17 Oct 2023 00:59:54 +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 v3 1/3] nvme-auth: alloc nvme_dhchap_key as single buffer Date: Mon, 16 Oct 2023 22:58:55 +0000 Message-Id: <20231016225857.3085234-2-shiftee@posteo.net> In-Reply-To: <20231016225857.3085234-1-shiftee@posteo.net> References: <20231016225857.3085234-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" 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 | 26 +++++++++++++++----------- include/linux/nvme-auth.h | 3 ++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c index d90e4f0c08b7..225fc474e34a 100644 --- a/drivers/nvme/common/auth.c +++ b/drivers/nvme/common/auth.c @@ -163,14 +163,9 @@ struct nvme_dhchap_key *nvme_auth_extract_key(unsigned= char *secret, p =3D strrchr(secret, ':'); if (p) allocated_len =3D p - secret; - key =3D kzalloc(sizeof(*key), GFP_KERNEL); + key =3D nvme_auth_alloc_key(allocated_len, 0); if (!key) return ERR_PTR(-ENOMEM); - key->key =3D kzalloc(allocated_len, GFP_KERNEL); - if (!key->key) { - ret =3D -ENOMEM; - goto out_free_key; - } =20 key_len =3D base64_decode(secret, allocated_len, key->key); if (key_len < 0) { @@ -213,19 +208,28 @@ struct nvme_dhchap_key *nvme_auth_extract_key(unsigne= d char *secret, key->hash =3D key_hash; return key; out_free_secret: - kfree_sensitive(key->key); -out_free_key: - kfree(key); + nvme_auth_free_key(key); return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(nvme_auth_extract_key); =20 +struct nvme_dhchap_key *nvme_auth_alloc_key(u32 len, u8 hash) +{ + struct nvme_dhchap_key *key =3D kzalloc(len + sizeof(*key), GFP_KERNEL); + + if (key) { + key->len =3D len; + key->hash =3D hash; + } + return key; +} +EXPORT_SYMBOL_GPL(nvme_auth_alloc_key); + void nvme_auth_free_key(struct nvme_dhchap_key *key) { if (!key) return; - kfree_sensitive(key->key); - kfree(key); + kfree_sensitive(key); } EXPORT_SYMBOL_GPL(nvme_auth_free_key); =20 diff --git a/include/linux/nvme-auth.h b/include/linux/nvme-auth.h index dcb8030062dd..df96940be930 100644 --- a/include/linux/nvme-auth.h +++ b/include/linux/nvme-auth.h @@ -9,9 +9,9 @@ #include =20 struct nvme_dhchap_key { - u8 *key; size_t len; u8 hash; + u8 key[]; }; =20 u32 nvme_auth_get_seqnum(void); @@ -27,6 +27,7 @@ u8 nvme_auth_hmac_id(const char *hmac_name); struct nvme_dhchap_key *nvme_auth_extract_key(unsigned char *secret, u8 key_hash); void nvme_auth_free_key(struct nvme_dhchap_key *key); +struct nvme_dhchap_key *nvme_auth_alloc_key(u32 len, u8 hash); u8 *nvme_auth_transform_key(struct nvme_dhchap_key *key, char *nqn); int nvme_auth_generate_key(u8 *secret, struct nvme_dhchap_key **ret_key); int nvme_auth_augmented_challenge(u8 hmac_id, u8 *skey, size_t skey_len, --=20 2.39.2