[PATCH 4/4] nvmet-auth: select the configured DH group from the host's list

Guixin Liu kanie at linux.alibaba.com
Tue Dec 1 19:47:07 PST 2026


The DH group negotiation loop adopts the first offered group that
differs from the configured one and never assigns it, so the
configured group is kept even when the host did not offer it, against
the negotiation rule that the controller select from the host's list.
The fallback path is only reached for entries equal to the configured
group, which defeats its purpose.

Mirror the hash negotiation loop: record the first usable offered
group as the fallback, then adopt the configured group when the host
offers it. When falling back, regenerate the DH context with
nvmet_setup_dhgroup(), as the key pair was set up for the configured
group at controller initialization. Treat the NULL DH group as usable
like the configfs dhgroup store does, and guard against unknown group
ids.

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 target keeps ffdhe2048, a group the host did not offer
(observed via the selected-DH-group print). Patched: the target falls
back to the offered ffdhe3072, regenerates the DH context, and
authentication succeeds. An intermediate version that changed the
group without regenerating the DH key pair failed authentication
(host response mismatch); regenerating with nvmet_setup_dhgroup()
fixes that.

Regression without the injection (host offers the full group list):
authentication with the configured group succeeds.
 drivers/nvme/target/fabrics-cmd-auth.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/fabrics-cmd-auth.c
index 34c2e14d0bd9..96765add5e4d 100644
--- a/drivers/nvme/target/fabrics-cmd-auth.c
+++ b/drivers/nvme/target/fabrics-cmd-auth.c
@@ -118,17 +118,21 @@ static u8 nvmet_auth_negotiate(struct nvmet_req *req, void *d, u32 tl)
 	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];
+		const char *kpp;
 
-		if (tmp_dhgid != ctrl->dh_gid) {
-			dhgid = tmp_dhgid;
-			break;
-		}
 		if (fallback_dhgid < 0) {
-			const char *kpp = nvme_auth_dhgroup_kpp(tmp_dhgid);
-
-			if (crypto_has_kpp(kpp, 0, 0))
+			if (tmp_dhgid == NVME_AUTH_DHGROUP_NULL) {
 				fallback_dhgid = tmp_dhgid;
+			} else {
+				kpp = nvme_auth_dhgroup_kpp(tmp_dhgid);
+				if (kpp && crypto_has_kpp(kpp, 0, 0))
+					fallback_dhgid = tmp_dhgid;
+			}
 		}
+		if (tmp_dhgid != ctrl->dh_gid)
+			continue;
+		dhgid = tmp_dhgid;
+		break;
 	}
 	if (dhgid < 0) {
 		if (fallback_dhgid < 0) {
@@ -139,7 +143,8 @@ static u8 nvmet_auth_negotiate(struct nvmet_req *req, void *d, u32 tl)
 		pr_debug("%s: ctrl %d qid %d: configured DH group %s not found\n",
 			 __func__, ctrl->cntlid, req->sq->qid,
 			 nvme_auth_dhgroup_name(fallback_dhgid));
-		ctrl->dh_gid = fallback_dhgid;
+		if (nvmet_setup_dhgroup(ctrl, fallback_dhgid) < 0)
+			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