[PATCH v2 4/5] nvmet-auth: reject negotiation when the configured DH group is not offered
Guixin Liu
kanie at linux.alibaba.com
Wed Dec 2 03:58:55 PST 2026
The DH group negotiation loop stores the first offered group that
differs from the configured one in a local variable that is never
used, so the controller keeps the configured group even when the host
did not offer it and advertises a group outside the host's list. The
fallback path is only reached for entries equal to the configured
group, which defeats its purpose.
The DH key pair is set up for the configured group at controller
initialization and is shared across all queues, so switching to a
different group during per-queue negotiation would require regenerating
controller-wide DH state. Instead, check that the host offers the
configured group and fail negotiation if it does not, leaving the
configured DH context intact.
Fixes: 7a277c37d3522 ("nvmet-auth: Diffie-Hellman key exchange support")
Cc: stable at vger.kernel.org
Signed-off-by: Guixin Liu <kanie at linux.alibaba.com>
---
Reproduced in a QEMU/KVM guest with nvmet-tcp and DH-HMAC-CHAP
authentication. The target host is configured for ffdhe2048; a
TEST-ONLY injection in the test host (not part of this patch) makes it
offer only ffdhe3072.
Unpatched: the negotiation loop keeps the configured ffdhe2048 and
advertises it in the challenge even though the host did not offer it.
Patched: negotiation fails with DHGROUP_UNUSABLE because the configured
group is not in the host's list.
Regression without the injection (host offers the full group list,
including the configured ffdhe2048): authentication succeeds.
Changes since v1:
- Drop the fallback to another offered group entirely. Regenerating the
controller-wide DH key pair from per-queue negotiation races with
other queues using it, and falling back to the NULL group downgrades
the configured FFDHE security. Instead just require the configured
group to be offered and fail otherwise (Sashiko).
drivers/nvme/target/fabrics-cmd-auth.c | 30 ++++++--------------------
1 file changed, 7 insertions(+), 23 deletions(-)
diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/fabrics-cmd-auth.c
index 34c2e14d0bd9..cfd6cdeab3c3 100644
--- a/drivers/nvme/target/fabrics-cmd-auth.c
+++ b/drivers/nvme/target/fabrics-cmd-auth.c
@@ -47,7 +47,7 @@ static u8 nvmet_auth_negotiate(struct nvmet_req *req, void *d, u32 tl)
{
struct nvmet_ctrl *ctrl = req->sq->ctrl;
struct nvmf_auth_dhchap_negotiate_data *data = d;
- int i, hash_id = 0, fallback_hash_id = 0, dhgid, fallback_dhgid;
+ int i, hash_id = 0, fallback_hash_id = 0;
if (tl < sizeof(*data) +
sizeof(struct nvmf_auth_dhchap_protocol_descriptor))
@@ -114,32 +114,16 @@ static u8 nvmet_auth_negotiate(struct nvmet_req *req, void *d, u32 tl)
ctrl->shash_id = fallback_hash_id;
}
- dhgid = -1;
- fallback_dhgid = -1;
for (i = 0; i < data->auth_protocol[0].dhchap.dhlen; i++) {
- int tmp_dhgid = data->auth_protocol[0].dhchap.idlist[i + 30];
-
- if (tmp_dhgid != ctrl->dh_gid) {
- dhgid = tmp_dhgid;
+ if (data->auth_protocol[0].dhchap.idlist[i + 30] ==
+ ctrl->dh_gid)
break;
- }
- if (fallback_dhgid < 0) {
- const char *kpp = nvme_auth_dhgroup_kpp(tmp_dhgid);
-
- if (crypto_has_kpp(kpp, 0, 0))
- fallback_dhgid = tmp_dhgid;
- }
}
- if (dhgid < 0) {
- if (fallback_dhgid < 0) {
- pr_debug("%s: ctrl %d qid %d: no usable DH group found\n",
- __func__, ctrl->cntlid, req->sq->qid);
- return NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE;
- }
- pr_debug("%s: ctrl %d qid %d: configured DH group %s not found\n",
+ if (i == data->auth_protocol[0].dhchap.dhlen) {
+ pr_debug("%s: ctrl %d qid %d: configured DH group %s not offered\n",
__func__, ctrl->cntlid, req->sq->qid,
- nvme_auth_dhgroup_name(fallback_dhgid));
- ctrl->dh_gid = fallback_dhgid;
+ nvme_auth_dhgroup_name(ctrl->dh_gid));
+ return NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE;
}
if (ctrl->dh_gid == NVME_AUTH_DHGROUP_NULL && ctrl->concat) {
pr_debug("%s: ctrl %d qid %d: NULL DH group invalid "
--
2.43.7
More information about the Linux-nvme
mailing list