From: Hannes Reinecke <hare@suse.de>
To: Sreeraj S Kurup <sreekuttan2156239@gmail.com>,
hare@kernel.org, hch@lst.de, kbusch@kernel.org, kch@nvidia.com,
sagi@grimberg.me
Cc: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org
Subject: Re: [PATCH] nvmet: clean up DH group state on initialization failure
Date: Tue, 10 Nov 2026 14:02:52 +0100 [thread overview]
Message-ID: <739b20b7-6921-4b37-8712-433ba19e5b84@suse.de> (raw)
In-Reply-To: <20261110084832.3508-1-sreekuttan2156239@gmail.com>
On 11/10/26 9:48 AM, Sreeraj S Kurup wrote:
> nvmet_setup_dhgroup() leaves the DH transform and group ID
> initialized when private-key generation, public-key allocation,
> or public-key generation fails.
>
> A subsequent invocation with the same DH group incorrectly
> returns success because the existing transform and group ID
> are treated as proof of successful initialization.
>
> Release the transform and reset the group state on initialization
> failures so that subsequent attempts can properly retry setup.
>
> Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
> ---
> drivers/nvme/target/auth.c | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c
> index ccba84b1344e..7733d50de708 100644
> --- a/drivers/nvme/target/auth.c
> +++ b/drivers/nvme/target/auth.c
> @@ -105,6 +105,10 @@ int nvmet_setup_dhgroup(struct nvmet_ctrl *ctrl, u8 dhgroup_id)
> if (ret < 0) {
> pr_debug("%s: ctrl %d failed to generate private key, err %d\n",
> __func__, ctrl->cntlid, ret);
> + crypto_free_kpp(ctrl->dh_tfm);
> + ctrl->dh_tfm = NULL;
> + ctrl->dh_gid = 0;
> + ctrl->dh_keysize = 0;
> kfree_sensitive(ctrl->dh_key);
> ctrl->dh_key = NULL;
> return ret;
> @@ -115,6 +119,10 @@ int nvmet_setup_dhgroup(struct nvmet_ctrl *ctrl, u8 dhgroup_id)
> if (!ctrl->dh_key) {
> pr_warn("ctrl %d failed to allocate public key\n",
> ctrl->cntlid);
> + crypto_free_kpp(ctrl->dh_tfm);
> + ctrl->dh_tfm = NULL;
> + ctrl->dh_gid = 0;
> + ctrl->dh_keysize = 0;
> return -ENOMEM;
> }
> ret = nvme_auth_gen_pubkey(ctrl->dh_tfm, ctrl->dh_key,
> @@ -122,8 +130,12 @@ int nvmet_setup_dhgroup(struct nvmet_ctrl *ctrl, u8 dhgroup_id)
> if (ret < 0) {
> pr_warn("ctrl %d failed to generate public key\n",
> ctrl->cntlid);
> - kfree(ctrl->dh_key);
> + kfree_sensitive(ctrl->dh_key);
> ctrl->dh_key = NULL;
> + crypto_free_kpp(ctrl->dh_tfm);
> + ctrl->dh_tfm = NULL;
> + ctrl->dh_gid = 0;
> + ctrl->dh_keysize = 0;
> }
> }
>
Can't we make this a helper?
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
prev parent reply other threads:[~2026-11-10 13:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 8:48 Sreeraj S Kurup
2026-11-10 13:02 ` Hannes Reinecke [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=739b20b7-6921-4b37-8712-433ba19e5b84@suse.de \
--to=hare@suse.de \
--cc=hare@kernel.org \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--cc=sreekuttan2156239@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®