[PATCH v2 5/5] nvmet-auth: require a DH value when a DH group was negotiated

Guixin Liu kanie at linux.alibaba.com
Wed Dec 2 03:58:56 PST 2026


nvmet_auth_reply() only processes the host's DH value when dhvlen is
non-zero. If a non-null DH group was negotiated (ctrl->dh_tfm is set)
but the host sends a reply with dhvlen == 0, the session key derivation
is skipped and req->sq->dhchap_skey stays NULL. nvmet_auth_host_hash()
then builds the augmented challenge from an empty session key, so the
response no longer depends on the DH shared secret, and with secure
channel concatenation the TLS PSK is derived without any DH entropy.

Reject a reply that carries no DH value when a DH group was negotiated,
mirroring the existing check that rejects a DH value when no group was
negotiated.

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. The
target host is configured for ffdhe2048, so a non-null DH group is
negotiated and ctrl->dh_tfm is set. A TEST-ONLY injection in the test
host (not part of this patch) emulates a malicious host: it computes
the reply response with an empty session key and sends the reply with
dhvlen == 0, omitting the DH value entirely.

Unpatched: nvmet_auth_reply() skips nvmet_auth_ctrl_sesskey() because
dhvlen is 0, leaving dhchap_skey NULL; the augmented challenge is built
from an empty session key and matches the host's response, so
authentication succeeds even though the negotiated DH exchange was
never performed (controller reaches live, "authenticated ... dhgroup
ffdhe2048"). Patched: the reply is rejected with INCORRECT_PAYLOAD
(failure1) and authentication fails.

Regression without the injection (host performs the real DH exchange):
authentication succeeds.
 drivers/nvme/target/fabrics-cmd-auth.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/fabrics-cmd-auth.c
index cfd6cdeab3c3..8b60065cbc2d 100644
--- a/drivers/nvme/target/fabrics-cmd-auth.c
+++ b/drivers/nvme/target/fabrics-cmd-auth.c
@@ -163,6 +163,8 @@ static u8 nvmet_auth_reply(struct nvmet_req *req, void *d, u32 tl)
 		if (nvmet_auth_ctrl_sesskey(req, data->rval + 2 * data->hl,
 					    dhvlen) < 0)
 			return NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE;
+	} else if (ctrl->dh_tfm) {
+		return NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
 	}
 
 	response = kmalloc(data->hl, GFP_KERNEL);
-- 
2.43.7




More information about the Linux-nvme mailing list