From: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
To: hare@kernel.org, hare@suse.de, hch@lst.de, kbusch@kernel.org,
kch@nvidia.com, sagi@grimberg.me
Cc: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org,
Sreeraj S Kurup <sreekuttan2156239@gmail.com>
Subject: [PATCH v3] nvmet: clean up DH group state on initialization failure
Date: Tue, 10 Nov 2026 10:00:58 +0000 [thread overview]
Message-ID: <20261110100058.4652-1-sreekuttan2156239@gmail.com> (raw)
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.
Fixes: 7a277c37d352 ("nvmet-auth: Diffie-Hellman key exchange support")
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
v3:
- Clear stale DH key state when crypto_alloc_kpp() fails during
re-authentication.
- Fix the error path when crypto_alloc_kpp() fails by returning
the allocation error instead of incorrectly reporting success.
v2:
- Consolidate error handling in "nvmet_setup_dhgroup()" using
a shared cleanup label to avoid duplicated teardown code.
- Add Fixes trailer.
drivers/nvme/target/auth.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c
index ccba84b1344e..33f2584973ec 100644
--- a/drivers/nvme/target/auth.c
+++ b/drivers/nvme/target/auth.c
@@ -97,6 +97,10 @@ int nvmet_setup_dhgroup(struct nvmet_ctrl *ctrl, u8 dhgroup_id)
ret = PTR_ERR(ctrl->dh_tfm);
ctrl->dh_tfm = NULL;
ctrl->dh_gid = 0;
+ kfree_sensitive(ctrl->dh_key);
+ ctrl->dh_key = NULL;
+ ctrl->dh_keysize = 0;
+ return ret;
} else {
ctrl->dh_gid = dhgroup_id;
pr_debug("%s: ctrl %d setup DH group %d\n",
@@ -105,9 +109,7 @@ 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);
- kfree_sensitive(ctrl->dh_key);
- ctrl->dh_key = NULL;
- return ret;
+ goto err;
}
ctrl->dh_keysize = crypto_kpp_maxsize(ctrl->dh_tfm);
kfree_sensitive(ctrl->dh_key);
@@ -115,18 +117,26 @@ 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);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto err;
}
ret = nvme_auth_gen_pubkey(ctrl->dh_tfm, ctrl->dh_key,
ctrl->dh_keysize);
if (ret < 0) {
pr_warn("ctrl %d failed to generate public key\n",
ctrl->cntlid);
- kfree(ctrl->dh_key);
- ctrl->dh_key = NULL;
+ goto err;
}
}
+ return 0;
+err:
+ 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;
return ret;
}
--
2.55.0
reply other threads:[~2026-11-10 10:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261110100058.4652-1-sreekuttan2156239@gmail.com \
--to=sreekuttan2156239@gmail.com \
--cc=hare@kernel.org \
--cc=hare@suse.de \
--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 \
/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®