Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guixin Liu" <kanie@linux.alibaba.com>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH 4/4] nvmet-auth: select the configured DH group from the host's list
Date: Wed, 02 Dec 2026 04:01:54 +0000	[thread overview]
Message-ID: <sashiko-outbox-244823@kernel.org> (raw)
In-Reply-To: <20261202034707.3844378-5-kanie@linux.alibaba.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Critical] nvmet-auth: race and UAF in nvmet_auth_negotiate() via
  nvmet_setup_dhgroup()
- [High] nvmet-auth: NULL DH fallback in nvmet_auth_negotiate()
  downgrades FFDHE
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] nvmet-auth: missing dhvlen check in nvmet_auth_reply()
  bypasses DH exchange [1]
--

commit 9ae2d361be0af29223daffafb91f03e1b18c83ea
Author: Guixin Liu <kanie@linux.alibaba.com>

nvmet-auth: select the configured DH group from the host's list

This commit updates DH group negotiation in nvmet_auth_negotiate() to match
the configured DH group from the host's offered list or fall back to the
first usable offered group and regenerate the DH context via
nvmet_setup_dhgroup().

> diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/fabrics-cmd-auth.c
> index 34c2e14d0bd92..96765add5e4de 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;
> +			}
>  		}

[Severity: High]
Does accepting NVME_AUTH_DHGROUP_NULL as fallback_dhgid downgrade FFDHE
negotiation to NULL DH?

Fallback selection is only used when ctrl->dh_gid is a non-null FFDHE
group that the host did not offer.  Standard hosts such as the Linux
NVMe host (nvme_auth_set_dhchap_negotiate_data()) put
NVME_AUTH_DHGROUP_NULL in the first DH slot ahead of all FFDHE groups.
Because fallback_dhgid latches onto 0 on the first entry, none of the
subsequent FFDHE groups offered by the host are considered, and
nvmet_setup_dhgroup(ctrl, NVME_AUTH_DHGROUP_NULL) tears down
ctrl->dh_tfm and ctrl->dh_key.  When ctrl->concat is enabled, latching
onto NVME_AUTH_DHGROUP_NULL also causes negotiation to fail with
NVME_AUTH_DHCHAP_FAILURE_CONCAT_MISMATCH even if valid FFDHE groups
follow in idlist.

> +		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 "

[Severity: Critical]
Can calling nvmet_setup_dhgroup() here race across submission queues and
corrupt ctrl->dh_tfm and ctrl->dh_key?

nvmet_execute_auth_send() and nvmet_execute_auth_receive() can run
concurrently on the admin queue and I/O queues while holding only the
per-queue req->sq->auth_lock, whereas ctrl->dh_tfm, ctrl->dh_key,
ctrl->dh_keysize and ctrl->dh_gid are shared across the controller:

CPU0 (queue A)                    CPU1 (queue B)
nvmet_execute_auth_receive()
  mutex_lock(&sqA->auth_lock)
  d = kzalloc(al, GFP_KERNEL)
  nvmet_auth_challenge()
    if (ctrl->dh_tfm)
      data_size += ctrl->dh_keysize;
    if (al < data_size) ...
                                  nvmet_execute_auth_send()
                                    mutex_lock(&sqB->auth_lock)
                                    nvmet_auth_negotiate()
                                      nvmet_setup_dhgroup(ctrl, ...)
                                        crypto_free_kpp(ctrl->dh_tfm)
                                        kfree_sensitive(ctrl->dh_key)
                                        ...
                                        ctrl->dh_keysize = 1024
    nvmet_auth_ctrl_exponential(...,
      ctrl->dh_keysize)
      memcpy(..., ctrl->dh_key, 1024)  <-- heap buffer overflow / UAF

Two queues can also call nvmet_setup_dhgroup() concurrently and double
free ctrl->dh_tfm and ctrl->dh_key, or free ctrl->dh_tfm while another
queue is using it in nvmet_auth_reply() -> nvmet_auth_ctrl_sesskey().
In addition, because nvmet_execute_auth_send() only restores the
controller's configured DH group via nvmet_setup_auth() when
!req->sq->qid, a fallback on an I/O queue permanently changes or clears
ctrl->dh_gid for the whole controller.

[Severity: Critical]
This problem wasn't introduced by this patch, but in nvmet_auth_reply()
immediately below, can a reply with dhvlen == 0 bypass the negotiated
Diffie-Hellman key exchange [1]?

drivers/nvme/target/fabrics-cmd-auth.c:nvmet_auth_reply() {
	...
	if (dhvlen) {
		if (!ctrl->dh_tfm)
			return NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
		if (nvmet_auth_ctrl_sesskey(req, data->rval + 2 * data->hl,
					    dhvlen) < 0)
			return NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE;
	}
	...
}

When a non-null DH group was negotiated (ctrl->dh_gid !=
NVME_AUTH_DHGROUP_NULL and ctrl->dh_tfm != NULL), sending data->dhvlen
set to 0 skips nvmet_auth_ctrl_sesskey(), leaving req->sq->dhchap_skey
as NULL and req->sq->dhchap_skey_len as 0.  nvmet_auth_host_hash() and
nvmet_auth_ctrl_hash() then pass the empty session key to
nvme_auth_augmented_challenge(), and when ctrl->concat is enabled,
nvmet_auth_insert_psk() derives the TLS PSK with zero Diffie-Hellman
entropy.

[1] https://sashiko.dev/#/bug/linux-7531dbf0-44f0-49fe-9d48-917996e69355

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202034707.3844378-1-kanie@linux.alibaba.com?part=4


      reply	other threads:[~2026-12-02  4:02 UTC|newest]

Thread overview: 7+ 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  3:47 ` [PATCH 4/4] nvmet-auth: select the configured DH group from the host's list Guixin Liu
2026-12-02  4:01   ` 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-244823@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kanie@linux.alibaba.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