nvmet-auth: fix error handling on CHALLENGE failure
Subsystems (3)
PATCH 1/1 nvmet-auth: fix error handling on CHALLENGE failure
From: Shao Mingyin <[email protected]>
In nvmet_execute_auth_receive(), when nvmet_auth_challenge() fails (for example when the initiator-supplied allocation length is shorter than the DH-HMAC-CHAP challenge response, or the challenge nonce allocation fails), the error path sets status = NVME_SC_INTERNAL and breaks out of the switch. The unconditional
status = nvmet_copy_to_sgl(req, 0, d, al);
after the switch then overwrites the error status (nvmet_copy_to_sgl() returns 0 on success), so the AUTH_RECEIVE command incorrectly completes with SUCCESS and the initiator proceeds with a truncated/empty challenge.
Fix this by freeing the buffer and jumping to the common done: label on CHALLENGE failure, skipping the copy_to_sgl() entirely and preserving the NVME_SC_INTERNAL status.
---
drivers/nvme/target/fabrics-cmd-auth.c +4 -3
@@ -605,10 +605,11 @@ void nvmet_execute_auth_receive(struct nvmet_req *req)switch (req->sq->dhchap_step) {case NVME_AUTH_DHCHAP_MESSAGE_CHALLENGE :if (nvmet_auth_challenge (req, d, al) <0 ) { -pr_warn ("ctrl %d qid %d: challenge error (%d)\n" , - ctrl->cntlid, req->sq->qid, status); +pr_warn ("ctrl %d qid %d: challenge error\n" , + ctrl->cntlid, req->sq->qid); status =NVME_SC_INTERNAL ; -break ; +kfree (d); + goto done; } req->sq->dhchap_step =NVME_AUTH_DHCHAP_MESSAGE_REPLY ;break ;
Quoted 10 lines · On Mon, Oct 26, 2026 at 04:45:26PM +0800, [email protected] wrote:
From: Shao Mingyin <[email protected]>
In
nvmet_execute_auth_receive(), whennvmet_auth_challenge()fails (for example when the initiator-supplied allocation length is shorter than the DH-HMAC-CHAP challenge response, or the challenge nonce allocation fails), the error path sets status =NVME_SC_INTERNALand breaks out of the switch. The unconditionalstatus = nvmet_copy_to_sgl(req, 0, d, al);
Quoted 7 lines
after the switch then overwrites the error status (
nvmet_copy_to_sgl()returns 0 on success), so theAUTH_RECEIVEcommand incorrectly completes with SUCCESS and the initiator proceeds with a truncated/empty challenge.Fix this by freeing the buffer and jumping to the common done: label on CHALLENGE failure, skipping the
copy_to_sgl()entirely and preserving theNVME_SC_INTERNALstatus.
Thanks, applied to nvme-7.4.