Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lee Seong Hyeon" <ihopenre@gmail.com>, linux-nvme@lists.infradead.org
Subject: Re: [PATCH RESEND 2/2] nvmet-auth: fail the transaction when the hash was changed
Date: Sat, 05 Dec 2026 01:12:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-250888@kernel.org> (raw)
In-Reply-To: <20261205004816.2017-3-ihopenre@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] nvmet-auth: SUCCESS2 hash mismatch sets FAILURE1 and returns
  success
- [Medium] nvmet-auth: nvmet_auth_receive_data_len() sizes SUCCESS1 with
  ctrl->shash_id
--

commit 4340d49e872c07246a6237d56d0d333f026696c4
Author: Lee Seong Hyeon <ihopenre@gmail.com>

nvmet-auth: fail the transaction when the hash was changed

This commit records the hash ID used to generate a queue's DH-HMAC-CHAP
challenge in sq->dhchap_hash_id and fails the transaction with
NVME_AUTH_DHCHAP_FAILURE_HASH_UNUSABLE if ctrl->shash_id has changed by
the time Reply, Success1, or Success2 is processed.

> diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/fabrics-cmd-auth.c
> index fe068dd5d450c..7f1549fc1545c 100644
> --- a/drivers/nvme/target/fabrics-cmd-auth.c
> +++ b/drivers/nvme/target/fabrics-cmd-auth.c

[ ... ]

> @@ -379,6 +388,19 @@ void nvmet_execute_auth_send(struct nvmet_req *req)
>  			NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
>  		goto done_kfree;
>  	}
> +	/*
> +	 * The challenge values of this transaction have the length of the
> +	 * hash they were generated for.  Any queue can make the controller
> +	 * switch to another hash, so do not go on with a different one.
> +	 */
> +	if ((data->auth_id == NVME_AUTH_DHCHAP_MESSAGE_REPLY ||
> +	     data->auth_id == NVME_AUTH_DHCHAP_MESSAGE_SUCCESS2) &&
> +	    !nvmet_auth_hash_unchanged(req)) {
> +		req->sq->authenticated = false;
> +		req->sq->dhchap_step = NVME_AUTH_DHCHAP_MESSAGE_FAILURE1;
> +		req->sq->dhchap_status = NVME_AUTH_DHCHAP_FAILURE_HASH_UNUSABLE;
> +		goto done_kfree;
> +	}
>  
>  	switch (data->auth_id) {
>  	case NVME_AUTH_DHCHAP_MESSAGE_REPLY:

[Severity: Medium]
Can setting dhchap_step to NVME_AUTH_DHCHAP_MESSAGE_FAILURE1 on a Success2
hash mismatch leave the host and target out of sync?

Unlike Reply, Success2 is the terminal host message in DH-HMAC-CHAP.
Because status stays 0, nvmet_execute_auth_send() completes with
NVME_SC_SUCCESS, so the host marks the queue authenticated and never
issues a follow-up auth_receive to collect Failure1.  Meanwhile, the done:
path skips nvmet_auth_sq_free() and nvmet_ctrl_fatal_error() because
dhchap_step is neither SUCCESS2 nor FAILURE2, re-arming auth_expired_work
while leaving req->sq->authenticated false (and skipping
nvmet_auth_insert_psk() when ctrl->concat is set).

Should the Success2 mismatch case set dhchap_step to
NVME_AUTH_DHCHAP_MESSAGE_FAILURE2 instead, as done_failure1: does?

[ ... ]

> @@ -503,6 +526,8 @@ static int nvmet_auth_success1(struct nvmet_req *req, void *d, u32 al)
>  	data->auth_id = NVME_AUTH_DHCHAP_MESSAGE_SUCCESS1;
>  	data->t_id = cpu_to_le16(req->sq->dhchap_tid);
>  	data->hl = hash_len;
> +	if (!nvmet_auth_hash_unchanged(req))
> +		return NVME_AUTH_DHCHAP_FAILURE_HASH_UNUSABLE;
>  	if (req->sq->dhchap_c2) {
>  		if (!ctrl->ctrl_key) {
>  			pr_warn("ctrl %d qid %d no ctrl key\n",

[Severity: Medium]
Does nvmet_auth_receive_data_len() still size the Success1 minimum buffer
length using ctrl->shash_id, preventing this check from running?

drivers/nvme/target/fabrics-cmd-auth.c:nvmet_auth_receive_data_len() {
    ...
	case NVME_AUTH_DHCHAP_MESSAGE_SUCCESS1:
		min_len = sizeof(struct nvmf_auth_dhchap_success1_data);
		if (req->sq->dhchap_c2)
			min_len += nvme_auth_hmac_hash_len(ctrl->shash_id);
		break;
    ...
}

If another queue switches ctrl->shash_id to a larger hash (such as SHA-256
to SHA-512) while this queue is waiting at Success1 with req->sq->dhchap_c2
set, a host submitting auth_receive with an exact-sized al for the original
hash fails in nvmet_execute_auth_receive() with NVME_SC_INVALID_FIELD |
NVME_STATUS_DNR before nvmet_auth_success1() can send Failure1.  That also
leaves req->sq->dhchap_step stuck at NVME_AUTH_DHCHAP_MESSAGE_SUCCESS1
without cleaning up the transaction.

Should nvmet_auth_receive_data_len() use req->sq->dhchap_hash_id (or
sizeof(struct nvmf_auth_dhchap_failure_data) when the hash changed)?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205004816.2017-1-ihopenre@gmail.com?part=2


      reply	other threads:[~2026-12-05  1:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  0:48 [PATCH RESEND 0/2] nvmet-auth: fix use-after-free and out-of-bounds read across queues Lee Seong Hyeon
2026-12-05  0:48 ` [PATCH RESEND 1/2] nvmet-auth: serialize the controller authentication state Lee Seong Hyeon
2026-12-05  0:48 ` [PATCH RESEND 2/2] nvmet-auth: fail the transaction when the hash was changed Lee Seong Hyeon
2026-12-05  1:12   ` sashiko-bot [this message]

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=sashiko-outbox-250888@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ihopenre@gmail.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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