Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Guixin Liu <kanie@linux.alibaba.com>
To: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>,
	Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	Nilay Shroff <nilay@linux.ibm.com>,
	Daniel Wagner <dwagner@suse.de>, Hannes Reinecke <hare@suse.de>
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH 4/4] nvmet-auth: select the configured DH group from the host's list
Date: Wed,  2 Dec 2026 11:47:07 +0800	[thread overview]
Message-ID: <20261202034707.3844378-5-kanie@linux.alibaba.com> (raw)
In-Reply-To: <20261202034707.3844378-1-kanie@linux.alibaba.com>

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@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@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



  parent reply	other threads:[~2026-12-02  3:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  3:47 [PATCH 0/4] nvme: target and host fixes from a drivers/nvme audit Guixin Liu
2026-12-02  3:47 ` [PATCH 1/4] nvme: mask the status before checking for Host Identifier Inconsistent Guixin Liu
2026-12-02  3:47 ` [PATCH 2/4] nvmet: read CRTO from the capability register Guixin Liu
2026-12-02  3:47 ` [PATCH 3/4] nvmet: snapshot the passthru command before completing the request Guixin Liu
2026-12-02  3:59   ` sashiko-bot
2026-12-02  5:45     ` Guixin Liu
2026-12-02  3:47 ` Guixin Liu [this message]
2026-12-02  4:01   ` [PATCH 4/4] nvmet-auth: select the configured DH group from the host's list sashiko-bot
2026-12-02  5:49     ` Guixin Liu

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=20261202034707.3844378-5-kanie@linux.alibaba.com \
    --to=kanie@linux.alibaba.com \
    --cc=axboe@kernel.dk \
    --cc=dwagner@suse.de \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=nilay@linux.ibm.com \
    --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