Skip to contentSkip to conversation

nvme-auth: validate DH value length when reusing a group

PATCH Superseded Andrew Stellman 4 participants 5 messages Nov 29 – Nov 30

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme-auth: validate DH value length when reusing a group

From: Andrew Stellman <[email protected]>

When a DH-HMAC-CHAP challenge names the DH group already in use, nvme_auth_process_dhchap_challenge() jumps to skip_kpp before the DH value length checks. A challenge with an empty DH value for a non-NULL group, or with a DH value for the NULL group, then returns 0. The fresh-group path rejects both.

Apply the same two checks, with the same error and status codes, on the reuse path before the jump. These challenges are now rejected with -EPROTO.

Tested on mainline 7.4.0-rc4-g4f069ab1ec24 in an arm64 QEMU guest, using a test-only debugfs hook that calls the function with synthetic
challenges: both malformed reuse cases returned 0 without the patch and -EPROTO with it, and the three control cases (an empty DH value for a fresh group, and valid challenges for a reused NULL and non-NULL group) gave the same results either way. Not tested over a live NVMe/TCP connection.

The issue was found by Claude Opus 5.5, Claude Opus 4.8, OpenAI GPT-6 Sol and Claude Sonnet 5.5 running Quality Playbook, an LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
The fix was drafted with OpenAI GPT-6 (Codex) and this changelog with Claude Opus 5.5, and both were reviewed by me.

Fixes b61775d185a3 ("nvme-auth: Diffie-Hellman key exchange support")

---
A reproducer is available on request.

 drivers/nvme/host/auth.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/nvme/host/auth.c +13 -0
index 9a3da74dec5aa..c45f88ca5db34 100644
@@ -219,6 +219,19 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
 
 	if (chap->dhgroup_id == data->dhgid &&
 	    (data->dhgid == NVME_AUTH_DHGROUP_NULL || chap->dh_tfm)) {
+		if (data->dhgid != NVME_AUTH_DHGROUP_NULL && !dhvlen) {
+			dev_warn(ctrl->device, "qid %d: empty DH value\n",
+				 chap->qid);
+			chap->status = NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE;
+			return -EPROTO;
+		}
+		if (data->dhgid == NVME_AUTH_DHGROUP_NULL && dhvlen) {
+			dev_warn(ctrl->device,
+				 "qid %d: invalid DH value for NULL DH\n",
+				 chap->qid);
+			chap->status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
+			return -EPROTO;
+		}
 		dev_dbg(ctrl->device,
 			"qid %d: reuse existing DH group %s\n",
 			chap->qid, gid_name);
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 49 lines · Andrew Stellman

From: Andrew Stellman <[email protected]>

When a DH-HMAC-CHAP challenge names the DH group already in use, nvme_auth_process_dhchap_challenge() jumps to skip_kpp before the DH value length checks. A challenge with an empty DH value for a non-NULL group, or with a DH value for the NULL group, then returns 0. The fresh-group path rejects both.

Apply the same two checks, with the same error and status codes, on the reuse path before the jump. These challenges are now rejected with -EPROTO.

Tested on mainline 7.4.0-rc4-g4f069ab1ec24 in an arm64 QEMU guest, using a test-only debugfs hook that calls the function with synthetic
challenges: both malformed reuse cases returned 0 without the patch and -EPROTO with it, and the three control cases (an empty DH value for a fresh group, and valid challenges for a reused NULL and non-NULL group) gave the same results either way. Not tested over a live NVMe/TCP connection.

The issue was found by Claude Opus 5.5, Claude Opus 4.8, OpenAI GPT-6 Sol and Claude Sonnet 5.5 running Quality Playbook, an LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
The fix was drafted with OpenAI GPT-6 (Codex) and this changelog with Claude Opus 5.5, and both were reviewed by me.

Fixes b61775d185a3 ("nvme-auth: Diffie-Hellman key exchange support")

---
A reproducer is available on request.

  drivers/nvme/host/auth.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
drivers/nvme/host/auth.c +6 -0
index 9a3da74dec5aa..c45f88ca5db34 100644
@@ -219,6 +219,19 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
 
  	if (chap->dhgroup_id == data->dhgid &&
  	    (data->dhgid == NVME_AUTH_DHGROUP_NULL || chap->dh_tfm)) {
+		if (data->dhgid != NVME_AUTH_DHGROUP_NULL && !dhvlen) {
+			dev_warn(ctrl->device, "qid %d: empty DH value\n",
+				 chap->qid);
+			chap->status = NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE;
+			return -EPROTO;
+		}

drivers/nvme/host/auth.c static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl, · line 237

Quoted 10 lines
drivers/nvme/host/auth.c +7 -0
+		if (data->dhgid == NVME_AUTH_DHGROUP_NULL && dhvlen) {
+			dev_warn(ctrl->device,
+				 "qid %d: invalid DH value for NULL DH\n",
+				 chap->qid);
+			chap->status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
+			return -EPROTO;
+		}
  		dev_dbg(ctrl->device,
  			"qid %d: reuse existing DH group %s\n",
  			chap->qid, gid_name);

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                  Kernel Storage Architect
[email protected]                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
#2 lore raw
In reply to Andrew Stellman

Please write a sensible and short commit log yourself. Thank you.

Quoted 49 lines · Andrew Stellman

From: Andrew Stellman <[email protected]>

When a DH-HMAC-CHAP challenge names the DH group already in use, nvme_auth_process_dhchap_challenge() jumps to skip_kpp before the DH value length checks. A challenge with an empty DH value for a non-NULL group, or with a DH value for the NULL group, then returns 0. The fresh-group path rejects both.

Apply the same two checks, with the same error and status codes, on the reuse path before the jump. These challenges are now rejected with -EPROTO.

Tested on mainline 7.4.0-rc4-g4f069ab1ec24 in an arm64 QEMU guest, using a test-only debugfs hook that calls the function with synthetic
challenges: both malformed reuse cases returned 0 without the patch and -EPROTO with it, and the three control cases (an empty DH value for a fresh group, and valid challenges for a reused NULL and non-NULL group) gave the same results either way. Not tested over a live NVMe/TCP connection.

The issue was found by Claude Opus 5.5, Claude Opus 4.8, OpenAI GPT-6 Sol and Claude Sonnet 5.5 running Quality Playbook, an LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
The fix was drafted with OpenAI GPT-6 (Codex) and this changelog with Claude Opus 5.5, and both were reviewed by me.

Fixes b61775d185a3 ("nvme-auth: Diffie-Hellman key exchange support")

---
A reproducer is available on request.

 drivers/nvme/host/auth.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/nvme/host/auth.c +6 -0
index 9a3da74dec5aa..c45f88ca5db34 100644
@@ -219,6 +219,19 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
 
 	if (chap->dhgroup_id == data->dhgid &&
 	    (data->dhgid == NVME_AUTH_DHGROUP_NULL || chap->dh_tfm)) {
+		if (data->dhgid != NVME_AUTH_DHGROUP_NULL && !dhvlen) {
+			dev_warn(ctrl->device, "qid %d: empty DH value\n",
+				 chap->qid);
+			chap->status = NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE;
+			return -EPROTO;
+		}

drivers/nvme/host/auth.c static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl, · line 237

Quoted 10 lines
drivers/nvme/host/auth.c +7 -0
+		if (data->dhgid == NVME_AUTH_DHGROUP_NULL && dhvlen) {
+			dev_warn(ctrl->device,
+				 "qid %d: invalid DH value for NULL DH\n",
+				 chap->qid);
+			chap->status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
+			return -EPROTO;
+		}
 		dev_dbg(ctrl->device,
 			"qid %d: reuse existing DH group %s\n",
 			chap->qid, gid_name);

---end quoted text---

#3 lore raw

PATCH v2 1/1 nvme-auth: validate DH value length when reusing a group

In reply to Andrew Stellman

From: Andrew Stellman <[email protected]>

When a DH-HMAC-CHAP challenge names the DH group that's already in use, nvme_auth_process_dhchap_challenge() skips the DH value length checks. A challenge with an empty DH value for a non-NULL group, or with a DH value for the NULL group, then returns 0, even though the same challenge for a new group is rejected.

Run the same two checks before reusing the group.

Found with Quality Playbook
(https://github.com/andrewstellman/quality-playbook).

Fixes b61775d185a3 ("nvme-auth: Diffie-Hellman key exchange support")

---
Christoph, I rewrote the commit log to be short, as you asked.
v1: https://lore.kernel.org/linux-nvme/[email protected]/

I tested this in an arm64 QEMU guest (full disclosure: I used OpenAI Codex to do a lot of the tedious setup for me) with a test-only hook that passes synthetic challenges to the function. Both malformed challenges returned 0 without the patch and -EPROTO with it. That reproducer is available on request.

I found this issue running Quality Playbook, an open-source code review tool that I maintain, with Claude Opus 5.5, and confirmed it with Claude Opus 4.8, OpenAI GPT-6 Sol and Claude Sonnet 5.5. The fix was drafted with OpenAI GPT-6 (Codex). I reviewed everything, but I'm new to this codebase, so I relied heavily on AI explanations of things.

Quality Playbook also found 37 other possible issues in drivers/nvme/host that I haven't reviewed or reproduced yet. I only send Linux bugs that I've reviewed and can actually reproduce, so I'll work through them (at my slow human speed, not AI speed) and send the ones I can verify. I'm happy to send you the list privately if it would help.

Andrew

 drivers/nvme/host/auth.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/nvme/host/auth.c +13 -0
index 9a3da74dec5aa..c45f88ca5db34 100644
@@ -219,6 +219,19 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
 
 	if (chap->dhgroup_id == data->dhgid &&
 	    (data->dhgid == NVME_AUTH_DHGROUP_NULL || chap->dh_tfm)) {
+		if (data->dhgid != NVME_AUTH_DHGROUP_NULL && !dhvlen) {
+			dev_warn(ctrl->device, "qid %d: empty DH value\n",
+				 chap->qid);
+			chap->status = NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE;
+			return -EPROTO;
+		}
+		if (data->dhgid == NVME_AUTH_DHGROUP_NULL && dhvlen) {
+			dev_warn(ctrl->device,
+				 "qid %d: invalid DH value for NULL DH\n",
+				 chap->qid);
+			chap->status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
+			return -EPROTO;
+		}
 		dev_dbg(ctrl->device,
 			"qid %d: reuse existing DH group %s\n",
 			chap->qid, gid_name);
maintainer Applied
#4 lore raw
Quoted 9 lines · Andrew Stellman

When a DH-HMAC-CHAP challenge names the DH group that's already in use, nvme_auth_process_dhchap_challenge() skips the DH value length checks. A challenge with an empty DH value for a non-NULL group, or with a DH value for the NULL group, then returns 0, even though the same challenge for a new group is rejected.

Run the same two checks before reusing the group.

[...]

Thanks, applied to nvme-7.4.

[1/1] nvme-auth: validate DH value length when reusing a group

      commit: 5cce12122887aec39b5b9d289cd058c8c5ca2d16

--
Keith Busch <[email protected]>